I want to draw a line in a picture box on an image from the point where I click the mouse to 100,100.
I have this code but don't know where to put the picColorKey_Paint sub so it draws when I click the image. currently it draws when the form is loaded.
TIA
DougP
< I Built one
I have this code but don't know where to put the picColorKey_Paint sub so it draws when I click the image. currently it draws when the form is loaded.
Code:
Public Class Form2
Dim XCoord, YCoord As Integer
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim img As Image = Image.FromFile("C:\FindFAST-old2\Office_Depot640x480.gif")
Dim TempImg As Image = New Bitmap(img.Width, img.Height)
Dim ImageDrawer As Graphics = Graphics.FromImage(TempImg)
Dim Fnt As New Font("Tahoma", 24, FontStyle.Bold)
'ImageDrawer.DrawString("X", Fnt, Brushes.Red, 300, 312)
PictureBox1.Image = img
End Sub
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
Dim img As Image = Image.FromFile("C:\FindFAST-old2\Office_Depot640x480.gif")
Dim TempImg As Image = New Bitmap(img.Width, img.Height)
Dim ImageDrawer As Graphics = Graphics.FromImage(TempImg)
XCoord = e.X
YCoord = e.Y
'MsgBox(e.X & " " & e.Y)
Me.txtXCoord.Text = XCoord.ToString
Me.txtYCoord.Text = YCoord.ToString
>>> Draw a line on picture box <<<<< when clicking here
End Sub
Private Sub picColorKey_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
>>>> ' this code draws a line at load and since XCoord and YCoord are 0 it goes from the upper left hand corner to 100, 100 <<<<
Dim objPen As Pen
Dim objPicGraphics As Graphics = e.Graphics
objPen = New Pen(Drawing.Color.Red, 3)
objPen.DashStyle = Drawing2D.DashStyle.Solid
objPicGraphics.DrawLine(objPen, XCoord, XCoord, 100, 100)
End Sub
End Class
TIA
DougP
< I Built one