调用抽绳时字体大小太小

时间:2015-04-21 02:19:08

标签: vb.net fonts picturebox font-size scaling

我正在加载并将图像放到图片框上并绘制som文本。 当我拖动文本时,它看起来很大,但是当我将它拖动或将其锁定到位时它会变得太小。图片框sizemode设置为Zoom。如此巨大的图像变小了。如何在picturebox中设置正确的字体大小和预览?

Sub btnLock负责将Text“锁定”到图像 和 sub Picturebox1_Paint预览

如何进行预览缩小字体大小或使btnLock scaleup fontSIze

 Dim Loc As Point
    Dim Pxy As Point

    Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
        txtButton.Text = MouseButtons.Left
        If e.Button = MouseButtons.Left Then
            Loc = e.Location
            Me.PictureBox1.Invalidate()
        End If
    End Sub

    Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
        Dim myFontSize As Integer
        Integer.TryParse(ComboBox1.Text, myFontSize)
        Dim myFont As New Font("Arial", myFontSize, FontStyle.Bold Or FontStyle.Italic)
        Dim pt As Point = PictureBox1.PointToClient(Control.MousePosition)
        e.Graphics.DrawString(txtA.Text, myFont, Brushes.Black, pt.X, pt.Y)
    End Sub

    Private Sub btnLock_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLock.Click
        Dim myFontSize As Integer
        Integer.TryParse(ComboBox1.Text, myFontSize)
        Dim myFont As New Font("Arial", myFontSize, FontStyle.Bold Or FontStyle.Italic)
        Dim g As Graphics = Graphics.FromImage(Me.PictureBox1.Image)
        ' g.DrawString(txtA.Text, myFont, Brushes.Black, Loc.X, Loc.Y)
        g.DrawString(txtA.Text, myFont, Brushes.Black, Pxy.X, Pxy.Y)
        ' Me.PictureBox1.Invalidate()
    End Sub

感谢您的帮助!-DB35M

1 个答案:

答案 0 :(得分:0)

我认为你会得到这种行为,因为两个Graphics对象有不同的大小。您的对象g正在从图片框的图像中获取其边界(不进行缩放),并且PictureBox1期间的图形对象正从图片框容器中获取它即可。这意味着它们的大小不同,因此myFontSize看起来会有不同的大小。

努力缩小规模"根据图像缩小的字体大小真的很难实现。相反,请通过将SizeMode更改为Normal并调整容器大小以适合图像来解决问题:

PictureBox1.SizeMode = PictureBoxSizeMode.Normal