J
John
I am working on writing a simple base form that will provide a colored
"Info Header" across the top of the form. I am no expert at winforms but
I can't understand what I am doing that would cause this to crash out
the IDE. Not an exception.. a hard crash where VS.NET has to restart.
To replicate the problem, add the attached CS to a class lib and build,
then create a winform project and add an inherited form using the DLL
that was built from the class lib. When the form loads you should see a
gray gradient pane going across the top of the form.
In the properties under section "Info Header" there are three items,
start, end, and height. Change the start color.. works fine.. change it
a second time.. and bye bye VS.NET =(
If anyone has the time to take a look at the code, and provide a little
direction I would appreciate it. Regards
John Parrish
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace BaseForms
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class BaseForm : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Drawing.Rectangle rect;
private Color mStartColor;
private Color mEndColor;
private int mHeight;
[Category("Info Header")]
public Color StartColor
{
get
{
return this.mStartColor;
}
set
{
this.mStartColor = value;
this.Invalidate();
}
}
[Category("Info Header")]
public Color EndColor
{
get
{
return this.mEndColor;
}
set
{
this.mEndColor = value;
this.Invalidate();
}
}
[Category("Info Header")]
public int PaneHeight
{
get
{
return this.mHeight;
}
set
{
this.mHeight = value;
this.rect.Height = value;
this.Invalidate();
}
}
public BaseForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//enable XP visual styles
Application.EnableVisualStyles();
//turn on double buffering
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer,true);
//set the initial start and end colors and height
this.mStartColor = Color.Silver;
this.mEndColor = Color.Gray;
this.mHeight = 100;
//get our initial rectangle
this.rect = new Rectangle(new Point(0,0),new Size(this.Width,this.mHeight));
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
//create our rectangle
LinearGradientBrush myBrush = new LinearGradientBrush(rect, this.mStartColor, this.mEndColor, System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal);
e.Graphics.FillRectangle(myBrush,rect);
e.Graphics.DrawLine(Pens.Black,0,this.mHeight,this.Width,this.mHeight);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// BaseForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(832, 478);
this.Name = "BaseForm";
this.Text = "BaseForm";
this.Resize += new System.EventHandler(this.BaseForm_Resize);
}
#endregion
private void BaseForm_Resize(object sender, System.EventArgs e)
{
this.rect = new Rectangle(new Point(0,0),new Size(this.Width,this.mHeight));
this.Invalidate(this.rect,true);
}
public bool Authorize(string context)
{
return false;
}
}
}
"Info Header" across the top of the form. I am no expert at winforms but
I can't understand what I am doing that would cause this to crash out
the IDE. Not an exception.. a hard crash where VS.NET has to restart.
To replicate the problem, add the attached CS to a class lib and build,
then create a winform project and add an inherited form using the DLL
that was built from the class lib. When the form loads you should see a
gray gradient pane going across the top of the form.
In the properties under section "Info Header" there are three items,
start, end, and height. Change the start color.. works fine.. change it
a second time.. and bye bye VS.NET =(
If anyone has the time to take a look at the code, and provide a little
direction I would appreciate it. Regards
John Parrish
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace BaseForms
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class BaseForm : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Drawing.Rectangle rect;
private Color mStartColor;
private Color mEndColor;
private int mHeight;
[Category("Info Header")]
public Color StartColor
{
get
{
return this.mStartColor;
}
set
{
this.mStartColor = value;
this.Invalidate();
}
}
[Category("Info Header")]
public Color EndColor
{
get
{
return this.mEndColor;
}
set
{
this.mEndColor = value;
this.Invalidate();
}
}
[Category("Info Header")]
public int PaneHeight
{
get
{
return this.mHeight;
}
set
{
this.mHeight = value;
this.rect.Height = value;
this.Invalidate();
}
}
public BaseForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//enable XP visual styles
Application.EnableVisualStyles();
//turn on double buffering
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer,true);
//set the initial start and end colors and height
this.mStartColor = Color.Silver;
this.mEndColor = Color.Gray;
this.mHeight = 100;
//get our initial rectangle
this.rect = new Rectangle(new Point(0,0),new Size(this.Width,this.mHeight));
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
//create our rectangle
LinearGradientBrush myBrush = new LinearGradientBrush(rect, this.mStartColor, this.mEndColor, System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal);
e.Graphics.FillRectangle(myBrush,rect);
e.Graphics.DrawLine(Pens.Black,0,this.mHeight,this.Width,this.mHeight);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// BaseForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(832, 478);
this.Name = "BaseForm";
this.Text = "BaseForm";
this.Resize += new System.EventHandler(this.BaseForm_Resize);
}
#endregion
private void BaseForm_Resize(object sender, System.EventArgs e)
{
this.rect = new Rectangle(new Point(0,0),new Size(this.Width,this.mHeight));
this.Invalidate(this.rect,true);
}
public bool Authorize(string context)
{
return false;
}
}
}