Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

When I set the backcolor property of my pictureBox to transparent, the backcolor of the underlying form shows through, but not squares etc drawn onto the surface of the form.

 

Is this how it is meant to work?

  • *Experts*
Posted
No. It simply takes the background image/color of the form and paints it on the picture box. You'll probably need to draw the contents of the picture box directly on the form manually usings its OnPaint event.
Posted

Thanks , you solved my problem.

 

Knowing what was meant to happen I had another look at my code. I actually don't have anything in the PictureBox, I just wanted its 3d border to provide a frame around something I am drawing onto the form.

 

In the form paint event I had (I'm new at this!):

 

Dim g As Graphics = Me.CreateGraphics

g.DrawRectangle(Pens.Blue, New Rectangle(50, 50, 100, 100))

 

The square dosen't show through. When I changed it to:

 

e. DrawRectangle(Pens.Blue, New Rectangle(50, 50, 100, 100))

 

The square shows through!

Posted

There is a PictureBox sitting over the area of the form where the square is drawn. The PictureBox backcolor is set to transparent . When I used :

 

Dim g As Graphics = Me.CreateGraphics

g.DrawRectangle(Pens.Blue, New Rectangle(50, 50, 100, 100))

 

in the form paint event, the square was not visable through the PictureBox. But when I used:

 

e. DrawRectangle(Pens.Blue, New Rectangle(50, 50, 100, 100))

 

in the form paint event the square is visable.

Posted

That is probably becuase this.CreateGraphics makes temporary graphics that aren't updated when the form is redrawn. Therefore, the picturebox was drawn and the that part of the form was Invalidated causing redraw.

 

When you draw in OnPaint directly, it is drawn every time Invalidate is called.

C#

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...