Public Class Form1
Private ptA As Point
Private ptB As Point
Private pen As Pen = Nothing
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Button1.PerformClick()
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.Paint
If Not (pen Is Nothing) Then
e.Graphics.DrawLine(pen, ptA, ptB)
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SetLine(New Point(0, 0), New Point(PictureBox1.Width, PictureBox1.Height), Color.Blue)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SetLine(New Point(PictureBox1.Width, 0), New Point(0, PictureBox1.Height), Color.Red)
End Sub
Private Sub SetLine(ByVal pt1 As Point, ByVal pt2 As Point, ByVal clr As Color)
ptA = pt1
ptB = pt2
If Not (pen Is Nothing) Then
pen.Dispose()
End If
pen = New Pen(clr)
PictureBox1.Refresh()
End Sub
End Class
Main Topics
Browse All Topics





by: iHadiPosted on 2007-06-28 at 16:53:46ID: 19385685
Hi cybermike3d
(); lor);
(); lor);
idth,0,0, pictureBox1.Height);
Place a pictureBox and two buttons on a form and paste the following code (don't forget to bind events with methods):
private void button1_Click(object sender, EventArgs e)
{
Graphics g = pictureBox1.CreateGraphics
Pen p = new Pen(Color.Red,1);
g.Clear(pictureBox1.BackCo
g.DrawLine(p, 0, 0, pictureBox1.Width, pictureBox1.Height);
}
private void button2_Click(object sender, EventArgs e)
{
Graphics g = pictureBox1.CreateGraphics
Pen p = new Pen(Color.Blue, 1);
g.Clear(pictureBox1.BackCo
g.DrawLine(p,pictureBox1.W
}