Results 1 to 4 of 4

Thread: [RESOLVED] How to place fillrectangle over part of a label control

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2013
    Posts
    196

    Resolved [RESOLVED] How to place fillrectangle over part of a label control

    I need to place a fill rectangle over a portion of a label control. I have tried to use Label1.SendToBack() before drawing the fill rectangle, but it doesn't work, the control continues to be in the front of the rectangle. .

    Is there a way to implement that?
    Last edited by PickyBiker; Jan 10th, 2018 at 07:44 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: How to place fillrectangle over part of a label control

    How could SendToBack help? That only sends the Label behind it's other sibling controls. It can't send it behind its parent so, if it's the parent you're drawing on, that drawing can't possibly be seen over any of the child controls. Think about hanging several overlapping pictures on your wall. You can put whatever picture you like in front or behind the others but they are all in front of the wall, so painting the wall can never affect what you see in the picture frames.

    If you make the BackColor of the Label Transparent then the parent will show through, so you might try that. I'm not sure whether that applies to GDI+ drawing on the parent or not as I've never tried. It does apply to BackgroundImage and the like.

    The other option is to draw on the Label as well as it's parent. To learn how to do that, follow the CodeBank link in my signature below and check out my thread on drawing the same thing on multiple controls.

  3. #3
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: How to place fillrectangle over part of a label control

    Can you describe what you mean by "place a fill rectangle"?

    If you mean you're handling your control's Paint event, what is happening is expected. You draw on the form, THEN all the other controls get to draw. So the label can never be behind what you draw on the form. If you want to draw on the Label, you have to handle the Label's paint event. If you want something that partially overlaps the label, your best bet is to make a custom control, but honestly you could just use a Panel with a background color as a more-or-less rectangle control.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2013
    Posts
    196

    Re: How to place fillrectangle over part of a label control

    Thank you both for your replies.

    I was not handling the control's paint event. I had a form with a label on it and I was trying to cover up a portion of it at run-time by drawing a fillrectangle over it. As jmcilhinney pointed out to me, that doesn't wok.

    I solved the problem by changing the situation in a way that does not require me to overwrite a label control.

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