S
steve bull
When adding a new user control to a panel I get the following call stack. Having put debugs everywhere I can think of I
cannot get the program to break anywhere near where it is having this problem.
System.ArgumentException: Invalid parameter used
at System.Drawing.Graphics.EndContainer(GraphicsContainer container)
at System.Windows.Forms.DibGraphicsBufferManager.ReleaseBuffer(GraphicsBuffer buffer)
at System.Windows.Forms.GraphicsBuffer.Dispose()
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Design.DesignerWindowTarget.DefWndProc(Message& m)
at System.Windows.Forms.Design.ControlDesigner.DefWndProc(Message& m)
at System.Windows.Forms.Design.ControlDesigner.WndProc(Message& m)
at System.Windows.Forms.Design.DesignerWindowTarget.OnMessage(Message& m)
Does anyone have any idea? I have included a stripped down version of the original control.
The problem appears to be with the dispose in the OnPaint method. If I leave it out the control runs fine but I thought
all graphics objects should be disposed of when no longer needed.
Thanks,
Steve
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using Graphics2D;
namespace NewControls
{
[ToolboxItem(true)]
[ToolboxBitmap(typeof(resfinder),"ColorPictureBox.bmp")]
/// <summary>
/// Summary description for ColorPictureBox.
/// </summary>
public class ColorPictureBox : System.Windows.Forms.PictureBox
{
private Color m_selectedColor = Color.Black;
private System.ComponentModel.Container components = null;
public ColorPictureBox()
{
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} /* End of Dispose(bool) */
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
Graphics g = e.Graphics;
ControlPaint.DrawBorder3D(g, new Rectangle(1, 1, Width - 20, Height - 20));
g.Dispose();
} /* End of OnPaint(PaintEventArgs) */
} /* End of public class ColorPictureBox */
} /* End of namespace NewControls */
cannot get the program to break anywhere near where it is having this problem.
System.ArgumentException: Invalid parameter used
at System.Drawing.Graphics.EndContainer(GraphicsContainer container)
at System.Windows.Forms.DibGraphicsBufferManager.ReleaseBuffer(GraphicsBuffer buffer)
at System.Windows.Forms.GraphicsBuffer.Dispose()
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Design.DesignerWindowTarget.DefWndProc(Message& m)
at System.Windows.Forms.Design.ControlDesigner.DefWndProc(Message& m)
at System.Windows.Forms.Design.ControlDesigner.WndProc(Message& m)
at System.Windows.Forms.Design.DesignerWindowTarget.OnMessage(Message& m)
Does anyone have any idea? I have included a stripped down version of the original control.
The problem appears to be with the dispose in the OnPaint method. If I leave it out the control runs fine but I thought
all graphics objects should be disposed of when no longer needed.
Thanks,
Steve
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using Graphics2D;
namespace NewControls
{
[ToolboxItem(true)]
[ToolboxBitmap(typeof(resfinder),"ColorPictureBox.bmp")]
/// <summary>
/// Summary description for ColorPictureBox.
/// </summary>
public class ColorPictureBox : System.Windows.Forms.PictureBox
{
private Color m_selectedColor = Color.Black;
private System.ComponentModel.Container components = null;
public ColorPictureBox()
{
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} /* End of Dispose(bool) */
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
Graphics g = e.Graphics;
ControlPaint.DrawBorder3D(g, new Rectangle(1, 1, Width - 20, Height - 20));
g.Dispose();
} /* End of OnPaint(PaintEventArgs) */
} /* End of public class ColorPictureBox */
} /* End of namespace NewControls */