|
|
#1 |
|
Addicted Member
Join Date: Dec 01
Location: Boston
Posts: 232
![]() |
[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! |
|
|
|
|
|
#2 |
|
.NUT
Join Date: May 05
Location: Sydney, Australia
Posts: 54,913
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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:
__________________
![]() 2007, 2008, 2009, 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 | C# (ForumAccount has translated some of my VB submissions to C#) My Blog: Defining and Raising Custom Events | Manipulating GDI+ Drawings | Using Parameters in ADO.NET Last edited by jmcilhinney; May 30th, 2007 at 08:30 PM. |
|
|
|
|
|
#3 |
|
Addicted Member
Join Date: Dec 01
Location: Boston
Posts: 232
![]() |
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. |
|
|
|
|
|
#4 | |
|
.NUT
Join Date: May 05
Location: Sydney, Australia
Posts: 54,913
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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:
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, 2008, 2009, 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 | C# (ForumAccount has translated some of my VB submissions to C#) My Blog: Defining and Raising Custom Events | Manipulating GDI+ Drawings | Using Parameters in ADO.NET |
|
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|