Please support our VB.NET advertiser: Programming Forums
Views: 55017 | Replies: 4
![]() |
•
•
Join Date: May 2004
Posts: 27
Reputation:
Rep Power: 5
Solved Threads: 0
There are lot more capabilities in VB.NET than in VB6 -
check out:
http://msdn.microsoft.com/library/de...LineOnForm.asp
check out:
http://msdn.microsoft.com/library/de...LineOnForm.asp
•
•
Join Date: May 2005
Posts: 494
Reputation:
Rep Power: 4
Solved Threads: 18
Here is the old VB6 Way Private Sub DrawLine() Dim bit As Bitmap = New Bitmap(Me.Width, Me.Height) Dim g As Graphics = Graphics.FromImage(bit) Dim myPen As Pen = New Pen(Color.Blue, 3) Me.CreateGraphics.DrawLine(myPen, 0, 0, Me.Width, Me.Height) End Sub
Here is the C# .NET way
protected override void OnPaint(PaintEventArgs pe)
{
Graphics g = pe.Graphics ;
Pen pn = new Pen( Color.Blue );
// Rectangle rect = new Rectangle(50, 50, 200, 100);
Point pt1 = new Point( 30, 30);
Point pt2 = new Point( 110, 100);
g.DrawLine( pn, pt1, pt2 );
} Here is the VB .NET way
' True while we are drawing the new line.
Private m_Drawing As Boolean
' Buffer for erasing rubberband lines.
Private m_BufferBitmap As Bitmap
Private m_BufferGraphics As Graphics
' The mouse position.
Private m_X1 As Integer
Private m_Y1 As Integer
Private m_X2 As Integer
Private m_Y2 As Integer
' Start drawing a rubberband line.
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e _
As System.Windows.Forms.MouseEventArgs) Handles _
MyBase.MouseDown
' Do nothing if this isn'tthe left mouse button.
If e.Button <> MouseButtons.Left Then Exit Sub
m_Drawing = True
' Save a snapshot of the form.
SaveSnapshot()
' Save the current mouse position.
m_X1 = e.X
m_X2 = e.X
m_Y1 = e.Y
m_Y2 = e.Y
End Sub
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode