To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



Go Back   VBForums > Visual Basic > Visual Basic .NET

Reply Post New Thread
 
Thread Tools Display Modes
Old May 30th, 2007, 07:12 PM   #1
neef
Addicted Member
 
neef's Avatar
 
Join Date: Dec 01
Location: Boston
Posts: 241
neef is on a distinguished road (10+)
[2005] Best Way to Draw On Top Of a Large Image

I have an image of a football field. It has been placed in a picturebox which is in a panel; the field is huge and needs the vertical scrollbar that the panel provides. It works great as I can move the scroll bar around to view any portion of the field - but I think I've set up a poor foundation for what I wish to accomplish next, which is to place images of players on the field, move them around, and draw patterns for their movements (a play designer, in effect). In short, I'm enterring GDI+ territory.

Is it true that drawing on top of my image with this setup is a bad idea? I've read that pictureboxes should only display images not have events drawing circles/lines/other images in addition to this.

If the above is true then what is the best way to set up my field image with a scrollbar on just a form with no panels or pictureboxes? The autoscroll property doesn't kick in for anything that isn't a control (hence I added a large picturebox which signals there is a need for a scrollbar), Can the size of an image signal a form to produce the neccessary space I need for my image?

Finally, since I'm entering into GDI+ territory I'd like to know how much of a pain in the ass mouse coordinates are in VB.NET. I remember when I learned some Visual C++ years ago many conversions being neccessary for different instances. For example, today (in VB.NET) I tried a hit test on an image control that I overlayed on my huge field image-in-picture-box and the hit fired WAY off of the actual picturebox.

To sum up I'd like to know how I should move forward with this project without setting myself up for problems down the road.

Thanks!
neef is offline   Reply With Quote
Old May 30th, 2007, 07:26 PM   #2
jmcilhinney
.NUT
 
jmcilhinney's Avatar
 
Join Date: May 05
Location: Sydney, Australia
Posts: 61,542
jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)
Re: [2005] Best Way to Draw On Top Of a Large Image

In my opinion the PictureBox is the right choice for what you want to do.

Mouse coordinates are very easy to use. Some events, like MouseDown, provide you with X and Y coordinates directly. You can also get mouse coordinates at any time from the Windows.Forms.Cursor.Position property. Just note that the screen has its own coordinate system with the origin at the top, left corner, as does every individual control. Every control has PointToScreen and PointToClient methods to allow you to convert between them. For instance, if you have a point in a PictureBox and you want to know where that point is on the form you can do this:
vb.net Code:
  1. Dim pt As Point = Me.PointToClient(Me.PictureBox1.PointToScreen(somePoint))
That's probably what you were lacking in your test: you were using the wrong coordinate system.
__________________

2007-2010

Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs
MSDN "How Do I?" Videos: VB | C#
VBForums Database Development FAQ
My CodeBank Submissions: VB (Nullable Data Extensions *NEW*) (Serial Code TextBox *NEW*) | C# (ForumAccount has translated some of my VB submissions to C#)
My Blog: Defining and Raising Custom Events | Using Parameters in ADO.NET | Keyboard Events *NEW*

Last edited by jmcilhinney; May 30th, 2007 at 07:30 PM.
jmcilhinney is online now   Reply With Quote
Old May 30th, 2007, 07:58 PM   #3
neef
Addicted Member
 
neef's Avatar
 
Join Date: Dec 01
Location: Boston
Posts: 241
neef is on a distinguished road (10+)
Re: [2005] Best Way to Draw On Top Of a Large Image

I was using Control.MousePosition; that must return the mouse coordinates for the form, not any other control, eh?

I'd probably want to have my mouse coordinates returned exclusively in the picturebox as I would have no need to draw, test, or move anything outside the picturebox.

A followup question: I eventually want player images moving around and even overlapping - should they be controlled and manipulated in the form of picturebox controls? Or should I draw them with GDI+ functions? Controls are great because they store data for hit tests and such; if I went GDI I'd have to write my own code for such things. Controls also stay on the screen whereas a circle is pretty much forgotten about after it's drawn in GDI.

But GDI would be better when players crash into each other I would think, eh? And I'm already annoyed that my triangle drawn in Photoshop with the transparent background is displayed as white on my form when I place it inside a picturebox - even when I set that picturebox's background to transparent. It just doesn't seem like the intended use of the picturebox control to be flying all over the screen.
neef is offline   Reply With Quote
Old May 30th, 2007, 08:16 PM   #4
jmcilhinney
.NUT
 
jmcilhinney's Avatar
 
Join Date: May 05
Location: Sydney, Australia
Posts: 61,542
jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)jmcilhinney has a reputation beyond repute (3000+)
Re: [2005] Best Way to Draw On Top Of a Large Image

Have I ever mentioned that you should always read the documentation, especially when things don't work the way you expect. This is from the help topic for the Control.MousePosition property:
Quote:
A Point that contains the coordinates of the mouse cursor relative to the upper-left corner of the screen.
That same help topic also includes a code example that uses the PointToClient method to convert to client coordinates from screen coordinates.

I don't think PictureBoxes can have a transparent background so your players would have to be rectangular.

How do you think controls are drawn on screen? With GDI+. Why do you think they stay on screen? Because they are redrawn on every Paint event. How do you get your GDI+ drawing to stay on screen? You redraw it on every Paint event. You ALWAYS do your GDI+ drawing on the Paint event of the control you're drawing on, thus each time the control is repainted so your drawing is repeated. To move or change your drawing you simply change the variables that control it and force a repaint.
__________________

2007-2010

Why is my data not saved to my database? | Communicating between multiple forms | MSDN Data Walkthroughs
MSDN "How Do I?" Videos: VB | C#
VBForums Database Development FAQ
My CodeBank Submissions: VB (Nullable Data Extensions *NEW*) (Serial Code TextBox *NEW*) | C# (ForumAccount has translated some of my VB submissions to C#)
My Blog: Defining and Raising Custom Events | Using Parameters in ADO.NET | Keyboard Events *NEW*
jmcilhinney is online now   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic .NET


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:22 AM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.