all groups > dotnet drawing api > january 2007 >
You're in the

dotnet drawing api

group:

Invalid parameter used


Invalid parameter used JayvardhanPune
1/30/2007 9:47:00 PM
dotnet drawing api:
I am using .Net 1.1
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.

----------------------------------------
Regards,
Re: Invalid parameter used Bob Powell [MVP]
1/31/2007 10:16:03 PM
Don't update the region in the OnPaint or in the constructor.

Make sure that you do it in the OnLoad method.

Happy programming.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





[quoted text, click to view]
AddThis Social Bookmark Button