0
I’m doing a little pograma to memorialize photos consists of a label and a picturebox how can I record the label together with the picture box image to a single image? this is my code
Imports System.Diagnostics
Imports System.Drawing
Public Class Form1
Dim PPoint As Point
Dim image As Image
Dim graphics As Graphics
Dim fontx As Font
Dim point As PointF
Dim color
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
txtValueX.Text = e.x.tostring
txtValueY.Text = e.Y.ToString
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim OpenFileDialog1 As New OpenFileDialog
OpenFileDialog1.InitialDirectory = "C:\"
OpenFileDialog1.FileName = "Open A File..."
OpenFileDialog1.Multiselect = False
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim sName As String = OpenFileDialog1.SafeFileName
Dim img As String = OpenFileDialog1.FileName
PictureBox1.Image = System.Drawing.Bitmap.FromFile(img)
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
End If
' Load image
image = Drawing.Image.FromFile(OpenFileDialog1.FileName)
graphics = Drawing.Graphics.FromImage(image)
' Create font
fontx = New Font("Times New Roman", 42.0F)
' Create text position
point = New PointF(txtValueX.Text, txtValueY.Text)
' Draw text
graphics.DrawString(TextBox2.Text, fontx, Brushes.Red, point)
End Sub
Private Sub mouseMove_Capture(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles _
MyBase.MouseMove
Dim mousePos As Point = Control.MousePosition
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim OpenFileDialog1 As New OpenFileDialog
OpenFileDialog1.InitialDirectory = "C:\"
OpenFileDialog1.FileName = "Open A File..."
OpenFileDialog1.Multiselect = False
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim sName As String = OpenFileDialog1.SafeFileName
Dim img As String = OpenFileDialog1.FileName
PictureBox1.Image = System.Drawing.Bitmap.FromFile(img)
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
End If
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Label5.Parent = PictureBox1
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
'// Save The image in PictureBox in its Original size.
If Me.PictureBox1.Image IsNot Nothing Then
Me.PictureBox1.Image.Save(IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyPictures, "TestFile.jpg"))
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Process.Start("1.jpg")
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
End Sub
Private Sub PictureBox1_MouseClick(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseClick
PPoint = New Point(e.X, e.Y)
Label5.Location = New Point(e.X, e.Y)
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
Label5.Text = TextBox2.Text
Label5.TextAlign = ContentAlignment.MiddleLeft
Label5.Font = New Font("Comic Sans MS", 12, _
FontStyle.Bold Or FontStyle.Underline)
End Sub
Private Sub TrackBar1_Scroll(sender As Object, e As EventArgs) Handles TrackBar1.Scroll
Label5.Font = New Font("Comic Sans MS", TrackBar1.Value, _
FontStyle.Bold Or FontStyle.Underline)
End Sub
Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
FontDialog1.ShowDialog()
Label5.Font = FontDialog1.Font
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
ColorDialog1.ShowDialog()
Label5.ForeColor = ColorDialog1.Color
End Sub
End Class
i have one Question its Give me error on lab its not declared if i understand moldura its the panel but it s Give me an error on this line Dim lab As New Label With { . Text = text, . Font = New Font("Segoe UI", 14) ' you choose your font here }
– Helder Da Silveira Ventura
Hello, @Helderdasilveiraventura. Here on Stack Overflow, we Speak Brazil’s Portuguese language. Can you Tell more about your error?
– CypherPotato
well in Fact the problem is Wen i Try your example with a panel well i have Insert a panel call moldura http://imgur.com/wJYcGSr
– Helder Da Silveira Ventura
Strange.
lab
was declared some Lines above the code, Try to Reload the Solution.– CypherPotato
well in Fact i have Try and i Stay with same problem but i have Solved Temporary the problem with this Lines Dim mystring As String = Label5.Text Dim myFont As Font = New Font("Arial", 13, Fontstyle.Italic, Graphicsunit.Pixel) Dim gr As Graphics = Graphics.Fromimage(Picturebox1.Image) 'Drawing takes place here: gr.Drawstring(mystring, myFont, Brushes.White, txtValueX.Text, txtValueY.Text) 'force a repaint result so whe can see the Picturebox1.Invalidate()
– Helder Da Silveira Ventura