Results 1 to 8 of 8

Thread: Visual Basic 2017: how make usercontrol transparent?

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Visual Basic 2017: how make usercontrol transparent?

    we can change the usercontrol backcolor to Transparent, but when we add a button(another control) on back, we can't see it.
    so how we can make it transparent?
    the best and slow way is using Regions?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: Visual Basic 2017: how make usercontrol transparent?

    So you want a transparent usercontrol, but want the button visible?

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: Visual Basic 2017: how make usercontrol transparent?

    Quote Originally Posted by ident View Post
    So you want a transparent usercontrol, but want the button visible?
    yes, i need the transparent usercontrol(like a bitmap shaped control) and see the button
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Visual Basic 2017: how make usercontrol transparent?

    When you put a UserControl on a form, the form becomes the Parent of the UserControl. "Transparent" means "show my Parent's background". So if you set the UC's backcolor to Transparent, you can see the form's background, but not other controls through the transparent parts. That's how transparency works in Windows Forms.

    There are several ways to get round this, but it depends on what effect you are looking for. Some possibliities I can think of are:
    1. put the Button on the UC instead of on the Form.
    2. use Regions to punch holes in the UC so the form's controls will show through. It sounds like you know how to do this. I don't know why it must be slow, but it's always possible to code things badly enough.
    3. Do the same as in 2, but use the form's TransparencyKey to make the holes in the UC.
    4. use an Owned Form instead of a UserControl and set its BackColor and Opacity to whatever values you like. You can make a form an Owned Form by showing it with Show(Me).
    5. use a WPF Window (see "shaped form" in my signature).
    ... and possibly other things too.

    BB

  5. #5

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: Visual Basic 2017: how make usercontrol transparent?

    3 - on UC and Form too lol
    2 - maybe you have right, i'm opened to suggestions... tell me the best way for get a Region from a bitmap?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  6. #6
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Visual Basic 2017: how make usercontrol transparent?

    Quote Originally Posted by joaquim View Post
    3 - on UC and Form too lol
    You are right, I forgot that.

    Quote Originally Posted by joaquim View Post
    2 - maybe you have right, i'm opened to suggestions... tell me the best way for get a Region from a bitmap?
    I don't understand that question. What bitmap? What does that have to do with a button on the form? Do you mean some colours on a bitmap have to become transparent? Please don't assume I have read all your other threads. Perhaps you could post an image to show your bitmap and the effect you want to get. Or try to describe it better in words.

    BB

  7. #7

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,904

    Re: Visual Basic 2017: how make usercontrol transparent?

    i mean making regions from images
    VB6 2D Sprite control

    To live is difficult, but we do it.

  8. #8
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Visual Basic 2017: how make usercontrol transparent?

    If you can get an outline of the image as a sequence of points (i.e. a polygon) you can convert that to a GraphicsPath and then to the Region property of a control. To get the outline, you need the Marching Squares algorithm: see here for an example.

    BB

Posting Permissions

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



Click Here to Expand Forum to Full Width