Invalid parameter used

Tech-Archive recommends: Fix windows errors by optimizing your registry



I am facing a problem with my GDI++ code in C# control.

Though i have tried many things from last 6 months, i am not able to
get completely rid of this bug.

Whenever the user is opening a window or closing a window, i'm getting
following exception.

This is a very rare exception but it causes the whole application
crash
and has become a nigtmare for me.

This problem is more frequent on Citrix client as compared to normal
desktop environment.

InnnerException: Invalid parameter used.

Stack Trace: at System.Drawing.Region.GetHrgn(Graphics g)
at System.Windows.Forms.Control.GetHRgn(Region region)
at System.Windows.Forms.Control.OnHandleCreated(EventArgs e)
at System.Windows.Forms.Control.WmCreate(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
Source: System.Drawing

I have done following coding in a control which is derived from
System.Windows.Forms.Button

protected override void OnPaint(PaintEventArgs e)
{
if(this != null)
{
if(!this.IsDisposed && !this.Disposing)
{
using(GraphicsPath path = new
GraphicsPath(FillMode.Alternate))
{
path.AddEllipse(0, 0, this.Width, this.Height);
using(Region rgn = new Region(path).Clone())
{
ctrl.Region=rgn.Clone();
}
}

}
}
}

I'll appriciate if you can provide some help.

.


Quantcast