Question Drawing on top of controls

Marzguitarz

New member
Joined
Feb 22, 2009
Messages
3
Programming Experience
Beginner
Hello,
I am a novice hobby programmer using VB.net Express 2008. I have a problem that has haunted me for years and I have not been able to get a simple laymen’s answer to it as of yet. Perhaps there is not a simple answer.
Years ago I made a nice slot machine using VB6. I switched to VB.net in 2003 and tried to program an improved version and found I couldn’t even create my old game. The problem was drawing a line on top of other controls.
The slot machine consisted of 9 square picture boxes placed 3x3 to form a typical 9 box square slot interface. When 3 of the same images lined up in a straight row, a line would draw on top of all the winning picture boxes, just like a normal slot machine would, to let you know where the win is. In total there are 8 lines: 3 horizontal from left to right, 3 vertical from top to bottom and 2 diagonal one from top left to bottom right and one from bottom left to top right.
In VB6 drawing a line on top of other controls was simple as there was a basic shape control which allowed you to draw lines on any control anywhere on the form. In VB.net I have no idea how to draw lines on top of another control. Now I am sure there are many ways but they are probably above and beyond my current skill level.
One simple work-around I thought of would be to place a large picture box on top of the nine slot picture boxes. I would then use several line icons (gif, tiff with a no background) to create the illusion of the line being drawn on top of the winning picture boxes. My problem is that there does not seem to be a true transparent setting for the picturebox control. The picturebox always shows a component of background. Transparency just sets the back color to the same as the form’s.
I have not used GDI+ very much and have never worked with WPF, so if the answer requires me to use either, please explain with that in mind. I appreciate anyone taking the time to read this and apologize if you got lost in the explanation. I also tried using the line shape control included in the Visual Basic PowerPacks but it did not allow me to draw on top of other controls either. I would greatly appreciate any and all help.
 
Hello.

maybe a solution would be to use the PowerPacks and the Visible Property? Placing all lines in place and then just show/hide them?

Another solution could be to use the OnPaint Event of the controls, to draw directly onto the controls. However, some controls to not fire this event by default, you'd have to overwrite them and add this code into the contructor:
VB.NET:
Me.SetStyle(ControlStyles.UserPaint, True)
so that the event is fired.

Best Regards,
Bobby

P.s.: Some basics on the second topic
Introduction to VB.NET Controls
CodeProject: Starting with GDI+. Free source code and programming help
Working with GDI+ Brushes using VB.NET
 
The powerpack solution does not work as I have tried that. The last solution would work if I knew how to do it. I messed with that for a week about 6 months ago to no avail and I think you hit on the reason why. I am not very experienced at working with GDI+ so I'll reread some chapters on using it from my books and mull over a few tutorials. Thanks again.
I thought of a solution to make all of the vertical and horizontal lines. I just stretch a label out and it works just like a line. I simply change the color to whatever I want. The problem is the two diagonal lines. If I could add code to the label so I could rotate it diagonally then I would be set.
A custom line class, which allows one to paint lines on top of other controls, would be the best solution. If anyone ever sees one out there please let me know.

:)
 
The easiest is to use a single Picturebox and draw your boxes and images and lines, either to a Bitmap to be displayed or with the Paint event.
I can recommend you visit BobPowell.net to learn.
 
Back
Top