1
我正在將圖像加載到圖片框和繪製som文本。 當我拖動它看起來很大的文字,但當我拉它或鎖定它的地方它變得太小。圖片框sizemode設置爲縮放。所以巨大的圖像變得很小。如何在picturebox中設置正確的字體大小和預覽?當抽取字符串時字體大小過小
子btnLock負責「鎖定」文本到影像 和 子Picturebox1_Paint預覽
我怎麼可以讓預覽縮小字體大小或使btnLock比例放大字號
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
你爲什麼不爲** ** myFontSize整數定義的值? – MacKentoch
@MacKentoch我正在使用Combobox1來更改字體大小 – db35m
好吧,我會調試並添加斷點以檢查發生了什麼。我想你已經做到了。 – MacKentoch