VB.net Picturebox trouble

How to make a PB's backgound truly transparent.

Page 1 of 1

9 Replies - 4773 Views - Last Post: 25 February 2009 - 07:43 PM Rate Topic: -----

#1 Marzguitarz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 22-February 09

VB.net Picturebox trouble

Posted 22 February 2009 - 12:46 PM

Hi folks,
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+ too much and have never used WPF, so if the answer is to use either, please explain it with that in mind. I appreciate anyone taking the time to read this and apologize if you got lost in the explanation. I would greatly appreciate any and all help.

This post has been edited by Marzguitarz: 22 February 2009 - 01:26 PM


Is This A Good Question/Topic? 0
  • +

Replies To: VB.net Picturebox trouble

#2 programble  Icon User is offline

  • (cons :dic :head)

Reputation: 49
  • View blog
  • Posts: 1,315
  • Joined: 21-February 09

Re: VB.net Picturebox trouble

Posted 22 February 2009 - 03:53 PM

Use the line shape control included in the Visual Basic PowerPacks.
Was This Post Helpful? 1
  • +
  • -

#3 Marzguitarz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 22-February 09

Re: VB.net Picturebox trouble

Posted 22 February 2009 - 05:01 PM

I tried that last year and it did not work. The control didn't allow me to place the line on top of other controls. Thanks for the suggestion, I really appreciate it.
Was This Post Helpful? 0
  • +
  • -

#4 Marzguitarz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 22-February 09

Re: VB.net Picturebox trouble

Posted 24 February 2009 - 07:08 AM

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.
Does anyone else have any suggestions?
Was This Post Helpful? 0
  • +
  • -

#5 bflosabre91  Icon User is offline

  • go sabres

Reputation: 105
  • View blog
  • Posts: 1,439
  • Joined: 22-February 08

Re: VB.net Picturebox trouble

Posted 24 February 2009 - 07:25 AM

WPF. it sounds like it works similar to how you say you did it in vb6. ive never done anything in vb6 but in WPF you can draw lines whereever you want and they will overlay the controls that are in the same container if you build it this way. here is an example of my drawing a line in one of my apps

				Dim poly As New Polyline
				poly.Effect = dropshadow
				poly.Stroke = New SolidColorBrush(Colors.White)
				poly.StrokeThickness = 4
				Dim points As New PointCollection
				points.Add(New Point(0, 40))
				points.Add(New Point(700, 40))
				poly.Points = points
				Grid.SetColumn(poly, 0)
				Grid.SetColumnSpan(poly, 1)
				Grid.SetRow(poly, 1)


This post has been edited by bflosabre91: 24 February 2009 - 07:28 AM

Was This Post Helpful? 1
  • +
  • -

#6 Marzguitarz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 22-February 09

Re: VB.net Picturebox trouble

Posted 24 February 2009 - 05:11 PM

Yes, I guess I am going to have to make the leap. Any books you would recommend? Sites?

Thank you
Was This Post Helpful? 0
  • +
  • -

#7 bflosabre91  Icon User is offline

  • go sabres

Reputation: 105
  • View blog
  • Posts: 1,439
  • Joined: 22-February 08

Re: VB.net Picturebox trouble

Posted 24 February 2009 - 07:20 PM

http://www.learnwpf.com/

thats got a few good examples on there.
Was This Post Helpful? 1
  • +
  • -

#8 Marzguitarz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 22-February 09

Re: VB.net Picturebox trouble

Posted 24 February 2009 - 08:25 PM

I have started reading Sam's WPF is 24 hours. Do I have to fully code in XAML or is there a way I can program in VB.net? I am a bit confused.
WPF looks very exciting but it looks like it may have a steep learning curve.

"Future Microsoft software will be built on WPF, for example, the code editor in Visual Studio 2010 has been rebuilt on WPF" WIki

That speaks volumes for the importance learning and the power of WPF.

This post has been edited by Marzguitarz: 24 February 2009 - 08:31 PM

Was This Post Helpful? 0
  • +
  • -

#9 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: VB.net Picturebox trouble

Posted 24 February 2009 - 08:55 PM

Also a great resource on WPF and WinForms:
http://windowsclient.net/

There are some very good video tutorials regarding WPF drawing techniques, so that may be interesting for you.
Was This Post Helpful? 1
  • +
  • -

#10 Marzguitarz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 22-February 09

Re: VB.net Picturebox trouble

Posted 25 February 2009 - 07:43 PM

View PostCore, on 24 Feb, 2009 - 07:55 PM, said:

Also a great resource on WPF and WinForms:
http://windowsclient.net/

There are some very good video tutorials regarding WPF drawing techniques, so that may be interesting for you.


Yes that's excellent. Thanks :^:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1