473,320 Members | 1,744 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

VB.NET lines

Is it possible to write code to draw lines on a form? if so...how?
thanks in advance for any help with this
Capuchin
Nov 20 '05 #1
5 1555
Add the following code to a functino inside a form:
Dim g As Graphics = Graphics.FromHwnd(Me.Handle)

g.DrawLine(Pens.Black, 0, 0, 100, 100)

g.Dispose()

If your code is inside the Paint event, the graphics object is already
available and you don't have to create it.

-Rob Teixeira [MVP]

"Capuchin" <i.**@spam.free> wrote in message
news:K9****************@wards.force9.net...
Is it possible to write code to draw lines on a form? if so...how?
thanks in advance for any help with this
Capuchin

Nov 20 '05 #2
Rob,
Rather then:
Dim g As Graphics = Graphics.FromHwnd(Me.Handle)
I would recommend:
Dim g As Graphics = Me.CreateGraphics()
As its "cleaner".

However as you stated, putting the code in the Paint event is generally
better, and the Graphics object is supplied.

Just a thought
Jay
"Rob Teixeira [MVP]" <RobTeixeira@@msn.com> wrote in message
news:%2******************@tk2msftngp13.phx.gbl... Add the following code to a functino inside a form:
Dim g As Graphics = Graphics.FromHwnd(Me.Handle)

g.DrawLine(Pens.Black, 0, 0, 100, 100)

g.Dispose()

If your code is inside the Paint event, the graphics object is already
available and you don't have to create it.

-Rob Teixeira [MVP]

"Capuchin" <i.**@spam.free> wrote in message
news:K9****************@wards.force9.net...
Is it possible to write code to draw lines on a form? if so...how?
thanks in advance for any help with this
Capuchin


Nov 20 '05 #3
Ha! That's what I was thinking of :-)

Been wading waste-deep in security code for so long, i'm losing the "fun"
stuff.

-Rob Teixeira [MVP]

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:eK**************@TK2MSFTNGP09.phx.gbl...
Rob,
Rather then:
Dim g As Graphics = Graphics.FromHwnd(Me.Handle)


I would recommend:
Dim g As Graphics = Me.CreateGraphics()


As its "cleaner".

However as you stated, putting the code in the Paint event is generally
better, and the Graphics object is supplied.

Just a thought
Jay
"Rob Teixeira [MVP]" <RobTeixeira@@msn.com> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
Add the following code to a functino inside a form:
Dim g As Graphics = Graphics.FromHwnd(Me.Handle)

g.DrawLine(Pens.Black, 0, 0, 100, 100)

g.Dispose()

If your code is inside the Paint event, the graphics object is already
available and you don't have to create it.

-Rob Teixeira [MVP]

"Capuchin" <i.**@spam.free> wrote in message
news:K9****************@wards.force9.net...
Is it possible to write code to draw lines on a form? if so...how?
thanks in advance for any help with this
Capuchin



Nov 20 '05 #4
* "Capuchin" <i.**@spam.free> scripsit:
Is it possible to write code to draw lines on a form? if so...how?
thanks in advance for any help with this


\\\
Private m_ptStartPosition As Point
Private m_ptPosition As Point
Private m_blnMoving As Boolean

Private Sub Form1_MouseDown( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs _
) Handles MyBase.MouseDown
m_blnMoving = True
m_ptStartPosition = New Point(e.X, e.Y)
End Sub

Private Sub Form1_MouseUp( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs _
) Handles MyBase.MouseUp
m_blnMoving = False
End Sub

Private Sub Form1_MouseMove( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs _
) Handles MyBase.MouseMove
m_ptPosition = New Point(e.X, e.Y)
Me.Invalidate()
End Sub

Private Sub Form1_Paint( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs _
) Handles MyBase.Paint
e.Graphics.DrawLine(Pens.Blue, m_ptStartPosition, m_ptPosition)
End Sub
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5
On Sat, 13 Dec 2003 16:02:20 -0600, Jay B. Harlow [MVP - Outlook] wrote:

g.Dispose()

If your code is inside the Paint event, the graphics object is already
available and you don't have to create it.


I feel it should also be stated that if you use the graphics object
provided in the paint event, then do NOT dispose of it yourself.

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jesse Noller | last post by:
I am a relative newbie to python and I am having issues trying to iterate over the lines of a file. I have a text file - foo.bar inside of this file are lines of text: x-3411342 y-1324123...
5
by: Brian | last post by:
Hello all.. Am working on an Air Hockey game... have an table loaded into a picture box. The borders of the table are slightly slanted. Am using hit testing lines with GDI+ to manipulate the...
2
by: m00nm0nkey | last post by:
Ok well i thought i'd try a different approach, so what I'm now trying is appending 50,000 lines from the collection to a stringbuilder, and then writing that entire stringbuilder to a file. ...
11
by: lovecreatesbeauty | last post by:
For example, line L1 and line L2 are two lines in two-dimensional space, the start-points and end-points can be described with following the `point_t' type. The start-points and end-points are:...
82
by: Edward Elliott | last post by:
This is just anecdotal, but I still find it interesting. Take it for what it's worth. I'm interested in hearing others' perspectives, just please don't turn this into a pissing contest. I'm in...
24
by: rudranee | last post by:
hi there, can anyone tell me how to lines from a file which are odd numbered i.e. 1st,3rd,5th...lines. i tried incrementing file pointer by 2 (fp=fp+2) but it does'nt work Can someone give me...
11
by: Girish Sahani | last post by:
I wrote the following code to concatenate every 2 keys of a dictionary and their corresponding values. e.g if i have tiDict1 = tiDict1 = {'a':,'b':} i should get tiDict2={'ab':} and similarly for...
7
by: peraklo | last post by:
Hello, there is another problem i am facing. i have a text file which is about 15000 lines big. i have to cut the last 27 lines from that file and create a new text file that contans those 27...
19
by: Pavan | last post by:
Hi, I want to know if there is any software for measuring lines of code of my c++ application. I found out a tool, sloccount, but it gives only physical lines of code. I found out one more...
7
by: Gustaf | last post by:
Hi all, Just for fun, I'm working on a script to count the number of lines in source files. Some lines are auto-generated (by the IDE) and shouldn't be counted. The auto-generated part of files...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.