Results 1 to 14 of 14
Like Tree1Likes
  • 1 Post By Swoop

Thread: Create Semi-Transparent rectangle over a checkbox? (Highlighter)

  1. #1
    Swoop is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2011
    Posts
    14
    Reputation
    20

    Create Semi-Transparent rectangle over a checkbox? (Highlighter)

    Does anyone know how to create a semi-transparent rectangle over a checkbox? Something that can be used in a mousehover event to highlight the checkbox and when the mouse is not over the checkbox it looks normal again. It would act like a menuitem that has the mouse over it.

    Any advice would be appreciated and thanks!
    Rael Tulus likes this.

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,345
    Reputation
    1543
    Do you really need this semi-transparent rectangle? Can you not just change the appearance of the CheckBox control itself?

    Also, do you really mean MouseHover, which occurs when the mouse pointer stops over the control, or do you actually mean MouseEnter and MouseLeave?

  3. #3
    Swoop is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2011
    Posts
    14
    Reputation
    20
    The mouse enter and mouse leave events would be great. I think the thrust is to discover what I need to do in order to make it happen. Should I be looking at altering the checkbox or leaving the checkbox as is and painting something on top of it that is translucent? What is the suggested methodology to create a highlighting rectangle that is larger than the content bounds of the checkbox?

  4. #4
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,345
    Reputation
    1543
    It really depends exactly what you want. The bounds of the CheckBox control extend well beyond the actual box that you check and uncheck. Do you want this highlight to extend beyond that? Do you want the change to occur within a range of the box or the whole control?

  5. #5
    Swoop is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2011
    Posts
    14
    Reputation
    20
    Yeah, I think it would be useful to be able to draw a selection rectangle that acts like a highlighter. A rectangle that overlays a control and is a translucent color so you're looking at the control through the selection rectangle.

    It would behave exactly like a MenuStrip item. If you have a menustrip close, take a look at the selection highlighting that occurs when over a menu item. Before you click on the menustrip item and simply hover over it, it highlights the item you're over with a translucent blue rectangle. That rectangle is much larger then the item.

    How would you go about doing something like that?

  6. #6
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,345
    Reputation
    1543
    I'm not sure that you understand exactly what the item or the control actually is. Try adding a CheckBox to a form and changing its BackColor to something unusual. That will show what is the CheckBox control.

  7. #7
    Swoop is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2011
    Posts
    14
    Reputation
    20
    JM, I have no idea why you're giving me that response. In fact, that response is so terrible you're got me laughing and smiling at the same time.

    What I'm hoping for is answer based in GDI+ somewhere. Maybe creating a bitmap from the checkbox and then creating an alpha channel transparency from it. Something along those lines. Changing the background color of a checkbox???...I mean really...can't you do any better then that? I'd like some help here if you would be kind enough to provide it.

  8. #8
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,345
    Reputation
    1543
    I didn't suggest that as a solution. I suggested it as a way for you to see what actually constitutes a CheckBox control. You said:
    It would behave exactly like a MenuStrip item. If you have a menustrip close, take a look at the selection highlighting that occurs when over a menu item. Before you click on the menustrip item and simply hover over it, it highlights the item you're over with a translucent blue rectangle. That rectangle is much larger then the item.
    The highlighted sentence is completely false. The highlighted portion is exactly the size of the item because it is the item. The highlight is bigger than the text on the item, but the text is not the item. Likewise, the actual box on a CheckBox control and the text on a CheckBox control are not the CheckBox control. You obviously don't understand how items on a MenuStrip work so there's every likelihood that you don't understand how a CheckBox works too. I was kind enough to try to provide some help in your gaining that understanding but your attitude has brought that kindness to an end.

  9. #9
    Swoop is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2011
    Posts
    14
    Reputation
    20
    Listen, I think we're getting off on the wrong foot here. The original question stands and I don't believe that we've broached an answer of any kind. The menu item was simply an example of what I'm looking to do as it's easy to see...a simple example.

    The question still is how to duplicate a selection rectangle (sort-of-kind-of) like a menu item in a menu strip. How would you go about doing so? What's the procedure...


    Edit:
    One more thing...I just realized by your responses that you might not know how to do something like this. So don't feel bad if that's the case. Just say so and maybe someone else wouldn't mind chiming in. It would nice....
    Last edited by Swoop; 05-15-2012 at 4:28 AM.

  10. #10
    Swoop is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2011
    Posts
    14
    Reputation
    20
    Just in case anyone is interested...I found an example of something close that might actually do the trick....

    Windows Forms Controls: VB.NET Translucent Control using GDI+ - CodeProject®

  11. #11
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,200
    Reputation
    2369
    How would you go about doing something like that?
    Handle the controls Paint event, or if you are creating a derived CheckBox class override the OnPaint method.
    Along with MouseEnter and MouseLeave event you can detect state and Refresh the control for it to paint accordingly.
    Filling a rectangle is done with Graphics.FillRectangle method. You can use any kind of Brush object, for example a SolidBrush with a custom transparent color.
    Color structure provides transparency through the alpha channel, check for example out the FromARGB method.

  12. #12
    Swoop is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2011
    Posts
    14
    Reputation
    20
    Well Paszt, it's nice to see you supporting you co-moderator but to be honest, changing the backcolor won't accomplish a selection style rectangle over a control. So the reality is that the suggestion by JM was not what I was looking to do right out of the box (or rectangle . In fact, that response was so non-conversational that it simply took me by surprise.

    John's response was much better and it was actually close to what I ended up doing. So one out of two isn't bad, it was just a little late. That's the way the cookie crumbles sometimes!

    Mark

  13. #13
    Swoop is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2011
    Posts
    14
    Reputation
    20
    While changing the backcolor can get me part of the way there, it certainly doesn't address drawing a border around the control in the OnPaint event of an inherited checkbox or the form it's currently on. It doesn't speak about lowering the opacity of the brush or color that I'm using.

    Now this is becoming the conversation that could have happened but didn't. But I suppose that we can agree to disagree as people would say in a situation like this. Tell you what though, my feeling on this is just as important as yours and I still say that the original conversation did not broach the subject of GDi+, custom controls, sub overrrides, argb colors...nothing.

    It was simply change the backcolor of a checkbox. But all things being equal, who cares?

  14. #14
    BanditSteve is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Oct 2008
    Posts
    28
    Reputation
    59
    Can't you simply put the checkbox in a small panel and change the panel's backcolor on mouse enter and leave?

Bookmarks

Posting Permissions

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