dcsimg
Results 1 to 5 of 5

Thread: Rectangular shape substitute

  1. #1

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    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.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,802

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Rectangular shape substitute

    Quote Originally Posted by jmcilhinney View Post
    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?
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,802

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    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.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width