Here's what finally worked.
using System;
using System.Diagnostics; // Trace and Debug.Assert
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms.Design;
namespace WS.Windows.Forms
{
public class ButtonExitControlDesigner :
System.Windows.Forms.Design.ControlDesigner
{
[Designer(typeof(WS.Windows.Forms.ButtonExitControl Designer))]
public class ButtonExit : Button
{
private ToolTip btn_ToolTip;
private System.ComponentModel.IContainer components;
public ButtonExit() : base()
{
this.components = new System.ComponentModel.Container();
this.btn_ToolTip = new ToolTip(this.components);
this.btn_ToolTip.SetToolTip(this, "Use this button to exit the
application.");
this.CausesValidation = false;
this.BackColor = Color.WhiteSmoke;
}
[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Visible)]
public override string Text
{
get { return base.Text; }
set
{
base.Text = value;
}
}
protected override void OnClick( EventArgs e )
{
if (MessageBox.Show("Do you really want to exit the application? \n
(Note: Unsaved data will not be saved)?", "Exit Warning",
MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.Yes)
{
base.OnClick( e ) ;
Form form = (Form)this.FindForm();
form.Close();
}
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
}
public override void OnSetComponentDefaults()
{
base.OnSetComponentDefaults();
Control.Text = "E&xit";
}
}
}
"Vern" wrote:
I'd like the default text to show up in designer, and allow it to be changed
to something else. I was able to change some of the other properties, but
for some reason I'm having trouble with the text. Here's the code from my
latest attempt. I initially tried just setting this.Text = "E&xit" but that
didn't work. Any ideas?
public class ButtonExit : Button
{
private ToolTip btn_ToolTip;
private System.ComponentModel.IContainer components;
public ButtonExit() : base()
{
this.components = new System.ComponentModel.Container();
this.btn_ToolTip = new ToolTip(this.components);
this.btn_ToolTip.SetToolTip(this, "Use this button to exit the
application.");
this.Enabled = true ;
this.CausesValidation = false;
base.Text = "E&xit";
}
[DefaultValue("E&xit"),
Category("Appearance"),
Description("Default Button Text")]
public override string Text
{
get { return base.Text; }
set
{
base.Text = value;
}
}
}