EDN Admin
Well-known member
Hi, Im using the Drawline method by capturing coordinates entered into 4 textboxes and then printing the image onto a picturebox. However, I cant get the previous line to be redrawn along with the new line that needs to be drawn. I understand that it refreshes
when using the picturebox.refresh() function.
The code is:
Public Class Form1<br/>
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br/>
PictureBox1.Refresh()<br/>
End Sub<br/>
<br/>
Private Sub PictureBox1_Paint1(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint<br/>
Create pen.<br/>
Dim blackPen As New Pen(Color.Black, 3)<br/>
<br/>
Create coordinates of points that define line.<br/>
Dim x1 As Integer<br/>
Dim y1 As Integer<br/>
Dim x2 As Integer<br/>
Dim y2 As Integer<br/>
<br/>
x1 = Val(TextBox1.Text)<br/>
y1 = Val(TextBox2.Text)<br/>
x2 = Val(TextBox3.Text)<br/>
y2 = Val(TextBox4.Text)<br/>
<br/>
Draw line to screen.<br/>
e.Graphics.DrawLine(blackPen, x1, y1, x2, y2)<br/>
End Sub<br/>
End Class
View the full article
when using the picturebox.refresh() function.
The code is:
Public Class Form1<br/>
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br/>
PictureBox1.Refresh()<br/>
End Sub<br/>
<br/>
Private Sub PictureBox1_Paint1(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint<br/>
Create pen.<br/>
Dim blackPen As New Pen(Color.Black, 3)<br/>
<br/>
Create coordinates of points that define line.<br/>
Dim x1 As Integer<br/>
Dim y1 As Integer<br/>
Dim x2 As Integer<br/>
Dim y2 As Integer<br/>
<br/>
x1 = Val(TextBox1.Text)<br/>
y1 = Val(TextBox2.Text)<br/>
x2 = Val(TextBox3.Text)<br/>
y2 = Val(TextBox4.Text)<br/>
<br/>
Draw line to screen.<br/>
e.Graphics.DrawLine(blackPen, x1, y1, x2, y2)<br/>
End Sub<br/>
End Class
View the full article