Draw Transparent Rectangle WITHOUT OnPaintBackground

I believe I may just be a dolt. This whole "flicker" thing has drained my will to program.
I just went and got the origional border drawing code and pasted it in...it works fine.
silly me.
:)

Thank you so very much for all your help Cags.
 
ah, the joy of all this crap is really getting to me.
:)

I have one last question (I hope).
still having a bit of trouble with drawing the border. The problem isnt that its not drawing the border...I think the problem is that the region isnt quite right. The border draws for the top and the left sides, and the bottom right corner shows up almost...but the right border and bottom border dont show.
this is what it should look like:
[Broken External Image]:http://www.livethislife.net/images/ForWork/should.png
and this is what it does:
[Broken External Image]:http://www.livethislife.net/images/ForWork/does.png

see the difference in the borders?
 
It depends on how you look at it as to whether the problem is the border or the region. The fact is you are using the same calculation to work out both, which means the border is drawn the same size as the region however it is drawn slightly further down and across. You need to essentially work out the path of the border and the path for the region seperately which is what the code I posted before did (It certainly wasnt perfect code, but it did make some alteration to the border). At this moment in time Im not entirely sure of the exact code that is required to make the border the correct size, but you definately have to work out the values seperately. Ill have a proper look at it tomorrow when Im completely sober. I might eventually post the code for the test control Ive been doing incase anybody else is trying to achieve the same effect.
 
For anybody interested in doing this here is an example control that allows the user to specify a custom border, gradient background and select which corners of a control are rounded.

Its the first time Ive made a control with designtime support so there may be a few bugs, so if you find one please let me know (for reference sake as im not actually using the control for anything).

The code is C# however Im trying to pickup the VB syntax so Im currently working on a conversion. If anyone is interested in that then just post here and let me know.
 

Attachments

Last edited by a moderator:
Cags, Ill check this out. Any VB syntax you need to know (and cant find) post up...Ill help in any way I can.

Cant thank you enough for all the help you provided man.
 
also, Cags...dont know if yours has this problem...but I noticed with mine that when you set the backcolor to Transparent in design time, it doesnt paint anything in the background and you end up with black or whatever is behind your app...its not a real problem for me...just thought Id point it out in case someone else does have a problem with it.
 
I have a vb version that works at runtime, however an error is encountered when using the control at designtime that prevents it from drawing. Basically instead of drawing correctly a nullreferenceexception is displayed, citing a line in the paint method. The variable it claims is null is Me.Region which seems very odd. What exactly causes this error I dont know but as this was only a learning task Im not too worried about it.
 
Solved the problem of endless flickering of transparent controls when the form first loads or is maximized. Couldnt find a solution anywhere on the NET after a strenuous search, so to give back for the countless times I have been helped by the online community, Im sharing it here:

It appears that sometimes when a transparent control paints itself, for some reason the display area of transparent controls in the lower z-order and the parent are invalidated, and an endless loop of WM_PAINT messages occurs. Override the WndProc function of the control. When the function receives the WM_PAINT message, call base.WndProc(ref m) and then call the ValidateRect Windows API as necessary, like so:

[Yeah, I know example is in C#. Started programming with VB6; I dont care where the solution comes from.]

[DllImport("user32", CharSet = CharSet.Auto, EntryPoint = "ValidateRect")]
public extern static Boolean ValidateRectangle(
IntPtr handle, // handle to window
IntPtr nullPointer); //type changed from ref RECT

private const Int32 WM_PAINT = 0x00f;

protected override void WndProc(ref Message m)
{

if(m.Msg == WM_PAINT)
{

base.WndProc(ref m);

ValidateRectangle(this.Parent.Handle, IntPtr.Zero);

foreach(Control control in this.Parent.Controls)
{


Int32 i3 = this.Parent.Controls.IndexOf(this);
Int32 i4 = this.Parent.Controls.IndexOf(control);

if(control is TransparentControlD)
{
if(i4 > i3)
{
continue;
}
}

ValidateRectangle(control.Handle, IntPtr.Zero);
}

}
else
{
base.WndProc(ref m);
}

}
 
Back
Top