473,406 Members | 2,707 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,406 software developers and data experts.

How to "form1.line (x1,y2)-(x2,y2)" in VB.NET

Dear All,
I think you all knew my problem.

I don't know how to draw line @@ in VB.NET (2005 beta) , very sad.

Coudl you please help me?

Best regards,
Boki.
Nov 21 '05 #1
3 2883
Boki

http://communities.microsoft.com/new...idbey&slcid=us

Maybe a better place for this question?

Cor
Nov 21 '05 #2

"Boki" <bo******@ms21.hinet.net> wrote
I think you all knew my problem.

I don't know how to draw line @@ in VB.NET (2005 beta) , very sad.

Coudl you please help me?

Here is a simple scribble demo. Paste the code below into a new
form, under the Designer code (section). I've used white to draw
the lines on the form. But, if you want that picture to stay after
resizing, or after minimizing (ect.) then you need to keep a bitmap
in memory to redraw the image. I've used black to draw to that
so you can see when that takes effect....

Have fun!
LFS

Private Page As Bitmap
Private Mouse As Point
Private Drawing As Boolean
Private PageGrx As Graphics
Private FormGrx As Graphics
Private BlackInk As Pen = New Pen(Color.Black, 2)
Private WhiteInk As Pen = New Pen(Color.White, 2)
Private MyPen As Pen

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Page = New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height)
ResetGraphics()
End Sub

Private Sub ResetGraphics()
If Not PageGrx Is Nothing Then PageGrx.Dispose()
PageGrx = Graphics.FromImage(Page)
PageGrx.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
If Not FormGrx Is Nothing Then FormGrx.Dispose()
FormGrx = Me.CreateGraphics
FormGrx.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
End Sub

Private Sub Form1_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.SizeChanged
' Bail if minimized / downsizing
If Me.WindowState = FormWindowState.Minimized Then Exit Sub
If (Me.Width * Me.Height) < (Page.Width * Page.Height) Then Exit Sub

' Copy old image to new
Dim tmp As Bitmap = New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height)
Dim grx As Graphics = Graphics.FromImage(tmp)
grx.DrawImageUnscaled(Page, 0, 0)
grx.Dispose()
Page.Dispose()
' Start using new image
Page = tmp
ResetGraphics()

End Sub

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
If Not FormGrx Is Nothing Then
FormGrx.DrawImageUnscaled(Page, 0, 0)
End If
End Sub

Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
Mouse.X = e.X
Mouse.Y = e.Y
Drawing = True
If e.Button = MouseButtons.Left Then
MyPen = BlackInk
Else
MyPen = WhiteInk
End If

End Sub

Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If Drawing Then
' Use MyPen as both ink pens for normal use
FormGrx.DrawLine(WhiteInk, Mouse.X, Mouse.Y, e.X, e.Y)
PageGrx.DrawLine(BlackInk, Mouse.X, Mouse.Y, e.X, e.Y)
Mouse.X = e.X
Mouse.Y = e.Y
End If
End Sub

Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
Drawing = False
End Sub
Nov 21 '05 #3
"Cor Ligthert" <no************@planet.nl> wrote in message news:<#n**************@TK2MSFTNGP09.phx.gbl>...
Boki

http://communities.microsoft.com/new...idbey&slcid=us

Maybe a better place for this question?

Cor


Got it, thank you for information. : )

Best regards,
Boki.
Nov 21 '05 #4

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

Similar topics

19
by: les_ander | last post by:
Hi, suppose I am reading lines from a file or stdin. I want to just "peek" in to the next line, and if it starts with a special character I want to break out of a for loop, other wise I want to...
7
by: jamait | last post by:
Hi all, I m trying to read in a text file into a datatable... Not sure on how to split up the information though, regex or substrings...? sample: Col1 Col2 ...
6
by: mary | last post by:
When we use string line; while (getline(in,line)) { out.write(line.c_str(),line.size()); out.put('\n'); } in.close();
8
by: Peter A. Schott | last post by:
Per subject - I realize I can copy/paste a line at a time into an interactive session when I'm trying to debug, but was wondering if there is any tool out there that allows me to copy sections of...
65
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
22
by: DraguVaso | last post by:
Hi, For my application I need the following behavior: When I press F4 the cursor has to move to the next line in my multiline textbox which begins with "0". Finding lines starting with 0 isn't...
8
by: Frost | last post by:
Hi All, I am a newbie i have written a c program on unix for line by line comparison for two files now could some one help on how i could do word by word comparison in case both lines have the...
3
by: Double Echo | last post by:
Hi all, I'm using PHP 4.4.2, and use PHP on both the command-line and the web. I am running PHP on SuSE 10 Linux , in a VMware 5.5 workstation, using Apache 2.0.55 , on my Dell laptop. ...
9
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still...
6
by: magix | last post by:
Hi, when I read entries in file i.e text file, how can I determine the first line and the last line ? I know the first line of entry can be filtered using counter, but how about the last line...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.