Rectangular shape substitute
I'm upgrading an old application from vb6 to vb.net and I need a replacement for a rectangular shape control. This shape lay on top of a picturebox and worked like Photoshop's rectangle on the navigation window: the part of the image inside the rectangle was magnified by copying it to a larger picturebox.
I've tried to use a panel control but it's not transparent.
Re: Rectangular shape substitute
You can set the BackColor of a control to Transparent and its parent will "show through". That means that your Panel can be used if you make the PictureBox its parent instead of the form. That has to be done code, but it's a simple matter of setting a single property or calling a single method.
The alternative would be to use GDI+ to simply draw a rectangle onto the PictureBox, which would mean handling its Paint event and calling DrawRectangle.
Re: Rectangular shape substitute
Quote:
Originally Posted by
jmcilhinney
You can set the BackColor of a control to Transparent and its parent will "show through". That means that your Panel can be used if you make the PictureBox its parent instead of the form. That has to be done code, but it's a simple matter of setting a single property or calling a single method.
The alternative would be to use GDI+ to simply draw a rectangle onto the PictureBox, which would mean handling its Paint event and calling DrawRectangle.
Thanks but it still won't work, the panel is not shown as if it were in a layer behind the image.
Initially the picturebox is empty and has the panel on it that I've added at design time.
Then at run time an image is drawn on the picturebox by means of the DrawImage method.
Thereafter comes this code:
Code:
PanelNav.Parent = PicBox1
PanelNav.BackColor = Color.Transparent
Dim wNav As Integer = 0.5 * Math.Min(PicBox1.ClientSize.Width, PicBox1.ClientSize.Height)
Dim hNav As Integer = wNav
PanelNav.Location = New Point(0, 0)
PanelNav.Size = New Size(wNav, hNav)
What's wrong with it?
Re: Rectangular shape substitute
I didn't realise the Image was drawn on the PictureBox as opposed to being assigned to its Image property. In that case, you'd have to draw the Image on the Panel too. If you want to see an example of common drawing on multiple controls then follow the CodeBank link in my signature below and check out my thread on the subject.
That said, I think that I'd just draw a rectangle on the PictureBox too, after drawing the Image.
Re: Rectangular shape substitute
I see.
Well, I've found an alternative possibility which allows to even control the degree of opacity:
https://www.codeguru.com/csharp/.net...ent-panel.html
Drawing a rectangle works too, but I have the feeling it might get more complicated to handle as I have to add code to pull on the border to change its size, and drag it about the picturebox.