RSS Forums RSS
Please support our VB.NET advertiser: Programming Forums
Views: 55017 | Replies: 4
Reply
Join Date: Apr 2005
Posts: 3
Reputation: gminhas is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
gminhas gminhas is offline Offline
Newbie Poster

How to draw a line in a VB.NET form?

  #1  
May 30th, 2005
hi guys!
can anyone tell me now to draw a line in VB.NET form?
I've been trying to do so , but nothings coming..
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2004
Posts: 27
Reputation: srikkanthan is on a distinguished road 
Rep Power: 5
Solved Threads: 0
srikkanthan srikkanthan is offline Offline
Light Poster

Re: How to draw a line in a VB.NET form?

  #2  
Jun 13th, 2005
There are lot more capabilities in VB.NET than in VB6 -

check out:
http://msdn.microsoft.com/library/de...LineOnForm.asp
Reply With Quote  
Join Date: May 2005
Posts: 494
Reputation: techniner is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 18
techniner techniner is offline Offline
Posting Pro in Training

Re: How to draw a line in a VB.NET form?

  #3  
Jun 13th, 2005
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
Did my post help?
Visit Little Jon's Web Portal


Generate Traffic with Maximum Traffic Software
Reply With Quote  
Join Date: Oct 2008
Posts: 4
Reputation: Tbusuk is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Tbusuk Tbusuk is offline Offline
Newbie Poster

Re: How to draw a line in a VB.NET form?

  #4  
Oct 22nd, 2008
what is the SaveSnapshot() method?????
Reply With Quote  
Join Date: Apr 2005
Location: Dundee, Scotland
Posts: 13,446
Reputation: jbennet is just really nice jbennet is just really nice jbennet is just really nice jbennet is just really nice 
Rep Power: 33
Solved Threads: 333
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: How to draw a line in a VB.NET form?

  #5  
Oct 22nd, 2008
there are two ways, the plain old line way, and the way using GDI and pens.
TRY MY SUGGESTIONS AT YOUR OWN RISK

Master of puppets Im pulling your strings, blinded by me, you cant see a thing. Master! Master!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 11:41 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC