|
-
Aug 18th, 2010, 01:15 PM
#1
Re: Drawing on Windowless Usercontrols
Welcome to the forums.
1. This is an excellent reference for usercontrols. Note that I'm having trouble accessing the site at the moment, but it's been up for years. Directly addresses VB5 but VB6 is not that different in this case.
2. Windowless controls can have their own DC or not (HasDC property).
a. Own DC: You draw on to the DC (same size as control) and VB transfers it to the form automatically
b. No DC: During the control's Paint event, VB passes you a clipped DC that you draw on directly. That DC is the control's parent's DC. Before the DC is sent to you, anything lower in the zOrder of your control that occupies the same space as your control is already drawn, including the background color as applicable.
3. Drawing text or anything on the control is done by drawing to the DC.
a. Has DC: use UserControl.hDC value. The Paint event is not called if AutoRedraw is True. If True, .Refresh control after drawing
b. No DC: use UserControl.hDC only in the control's Paint event. Accessing it outside of the event can/will produce an error since the control has no DC allocated. AutoRedraw cannot be set on DC-less controls.
Edited: The "No DC" option is how you can ensure transparency. Other methods include using the MaskPicture and MaskColor properties but are somewhat limited.
Regarding subclassing. Each usercontrol has a containerHwnd property.
Hope this clears up some issues.
Last edited by LaVolpe; Aug 18th, 2010 at 01:30 PM.
-
Aug 19th, 2010, 05:17 AM
#2
Thread Starter
New Member
Re: Drawing on Windowless Usercontrols
 Originally Posted by LaVolpe
Welcome to the forums.
b. No DC: use UserControl.hDC only in the control's Paint event. Accessing it outside of the event can/will produce an error since the control has no DC allocated. AutoRedraw cannot be set on DC-less controls.
Edited: The "No DC" option is how you can ensure transparency. Other methods include using the MaskPicture and MaskColor properties but are somewhat limited.
This solved the issue! It seems VB holds a buffer DC which is available in Paint event thus allowing you double-buffered rendering along with transparency! Really nice. I just call native Refresh method in my properties Set/Let handlers to request repainting.
That's what I've been missing, you're the man LaVolpe.
@petersen
Edit control would be an overkill, this is just a label . I was going for no permanent GDI handles and/or window handles.
@some1uk03
I've put LaVolpe's explanation to use and it worked great. All you have to do is draw inside the Paint event with BackgroundStyle set to Transparent! That way your DC will be laid out automatically by VB to the container surface. This eliminates the need for double buffering as well so you can just draw directly to the control's DC.
Thanks for help all!
-
Aug 19th, 2010, 08:09 AM
#3
Re: Drawing on Windowless Usercontrols
 Originally Posted by SassyCat
This solved the issue! It seems VB holds a buffer DC which is available in Paint event thus allowing you double-buffered rendering along with transparency! Really nice. I just call native Refresh method in my properties Set/Let handlers to request repainting.
That's what I've been missing, you're the man LaVolpe.
I've designed many windowless controls using dc-less options and it works quite well.
One word of advice. Depending on complexity of your drawing (i.e., time consuming), you may want to use an offscreen buffer, copy the passed DC to your offscreen, do the complex drawing and then copy the offscreen back to the passed DC. Also, should you be selecting anything into the passed DC, cache what you pulled out and put it back in else unexpected results can occur.
Last edited by LaVolpe; Aug 19th, 2010 at 11:37 AM.
Reason: typos
-
Mar 16th, 2015, 09:10 AM
#4
New Member
Re: Drawing on Windowless Usercontrols
 Originally Posted by LaVolpe
I've designed many windowless controls using dc-less options and it works quite well.
One word of advice. Depending on complexity of your drawing (i.e., time consuming), you may want to use an offscreen buffer, copy the passed DC to your offscreen, do the complex drawing and then copy the offscreen back to the passed DC. Also, should you be selecting anything into the passed DC, cache what you pulled out and put it back in else unexpected results can occur.
Thank you very much guys and especially LaVolpe, you just saved my day as I was writting a Image Button component to freshen an old application UI... this forum is just so great!
Have a nice day
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|