Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2010 > BOOK: Visual Basic 2010 Programmer's Reference
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Visual Basic 2010 Programmer's Reference
This is the forum to discuss the Wrox book Visual Basic 2010 Programmer's Reference by Rod Stephens; ISBN: 9780470499832
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Visual Basic 2010 Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 3rd, 2011, 04:27 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2011
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Question Convert graphics VB6 to .net

I'm at last converting programs from VB6 to .NEt.

In VB6 I draw a graph on a picture box using methods like "line" to draw a line from one point to another. In VB.net a picture box does not appear to be a graphics object. I can't see how to get started. How do I draw a line from point x1,y1 to point x2,y2 on an object comparable to the picture box in VB6?
Reply With Quote
  #2 (permalink)  
Old September 4th, 2011, 10:36 AM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Graphics is the hardest thing to convert from VB 6 to VB .NET. For a lot of information about using graphics in .NET, see my Wrox Blox:
Visual Basic Graphics Programming
http://www.wrox.com/WileyCDA/WroxTit...470343486.html
It provides a good introduction for only $6.99.

The key ideas are:

There is a PictureBox control but it doesn't provide drawing methods. Instead it can either display an image or draw in its Paint event handler. (The Form can do the same).

The Paint event handler provides a Graphics object, and that object provides drawing methods such as DrawLine and FillRectangle. You can think of the Graphics object as the surface on which you draw.

You can also get a Graphics object by creating a Bitmap like this:

Code:
Dim bm As New Bitmap(100, 100)
Dim gr As Graphics = Graphics.FromImage(bm)
gr.DrawLine(Pens.Red, 0, 0, 100, 50)
You use Pen objects to determine how lines are drawn. For example, to set their color, thickness, dash styles, etc.

You use Brushes to determine how areas and text are filled. For example, to set their color and fill pattern.

That's the extremely quick overview. Search online for more examples. The VB Helper web site has lots of graphics examples. Try looking at:
http://www.vb-helper.com/index_graphics.html
Of look at that Wrox Blox I mentioned, or read the chapters about graphics in this forum's book Visual Basic 2010 Programmer's Reference.

Finally if you get stuck and need a hint, post a new question here or email me directly (RodStephens@vb-helper.com).

Good luck!
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
The Following User Says Thank You to Rod Stephens For This Useful Post:
PeterGans (September 4th, 2011)
  #3 (permalink)  
Old September 4th, 2011, 12:05 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2011
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Here's a follow up. When the line is used as a cursor I use picturebox.drawmode=7 (XOR). What's the equivalent in VB 8? I can't see anything relevant in pen or brush properties.
Reply With Quote
  #4 (permalink)  
Old September 5th, 2011, 11:42 AM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

One of the stranger omissions in GDI+ graphics is drawing modes like XOR. You just can't do it.

Instead what you normally do is make a copy of the Bitmap on which you are drawing, draw on the copy, and then display it. When you need to erase, you just make anotehr copy of the original.

To make a line contrast with whatever is is over (like XOR would provide), you can draw with a dashed line.

All this is less efficient than drawing in XOR mode but the GDI+ graphics used by .NET are around 20x faster than the graphics methods used by VB 6 so the end result is faster.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How convert projects vb6 to vba access gerry66 Access VBA 3 July 4th, 2011 01:01 AM
Convert Text to Graphics... gabri17bol Pro Visual Basic 2005 1 May 13th, 2007 04:24 PM
Consume VB6.0 WebService in ASP.NET using VB.NET pinkarc .NET Web Services 1 March 5th, 2007 08:19 AM
Re:COM and VB6 to .NET timlin All Other Wrox Books 2 May 4th, 2005 10:33 AM
How to use Visual Studio.NET for computer graphics chinadust VS.NET 2002/2003 1 November 6th, 2004 04:04 AM



All times are GMT -4. The time now is 04:22 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.