public class MyTextBox : TextBox { public MyTextBox() { this.BackColor = Color.DarkGreen; } }When you drop this TextBox onto a Form, the BackColor will be explicitly set in code to Color.DarkGreen in the InitializeComponent() method of the Form. Consequently, if you later decide to change the color in your MyTextBox class, you have to revisit every single Form that you ever dropped that TextBox on to change it to the new default value. Not good!
public class MyTextBox : TextBox { public MyTextBox() { } [DefaultValue(typeof(System.Drawing.Color), "DarkGreen")] public override System.Drawing.Color BackColor { get {return base.BackColor;} set {base.BackColor = value;} } }>This doesn't work. Have you tried dragging that "Component TextBox" from the ToolBox onto a Form? Seems it disappears somewhere ... well, it's not visible anyway. Components are not meant to be used this way.
> public class MattsTextBox : OakLeaf.MM.Main.Windows.Forms.mmTextBox > { > public MattsTextBox() > { > this.BindingSourceMember = null; > this.ControlID = new System.Guid("00000000-0000-0000-0000-000000000000"); > this.Font = new System.Drawing.Font("Arial", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); > this.ForeColor = System.Drawing.Color.Red; > this.Location = new System.Drawing.Point(0, 0); > this.Name = "mmTextBox1"; > this.Size = new System.Drawing.Size(100, 22); > this.TabIndex = 0; > } > } >} >>
>>using System; >>using System.Collections.Generic; >>using System.ComponentModel; >>using System.Diagnostics; >>using System.Linq; >>using System.Text; >> >>namespace lmforms >>{ >> public partial class Component2 : Component >> { >> public Component2() >> { >> InitializeComponent(); >> } >> >> public Component2(IContainer container) >> { >> container.Add(this); >> >> InitializeComponent(); >> } >> } >>} >> >>>>
>>namespace lmforms >>{ >> partial class Component2 >> { >> /// <summary> >> /// Required designer variable. >> /// </summary> >> private System.ComponentModel.IContainer components = null; >> >> /// <summary> >> /// Clean up any resources being used. >> /// </summary> >> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> >> protected override void Dispose(bool disposing) >> { >> if (disposing && (components != null)) >> { >> components.Dispose(); >> } >> base.Dispose(disposing); >> } >> >> #region Component 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() >> { >> this.mmTextBox1 = new OakLeaf.MM.Main.Windows.Forms.mmTextBox(); >> // >> // mmTextBox1 >> // >> this.mmTextBox1.BindingSourceMember = null; >> this.mmTextBox1.ControlID = new System.Guid("00000000-0000-0000-0000-000000000000"); >> this.mmTextBox1.Font = new System.Drawing.Font("Arial", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); >> this.mmTextBox1.ForeColor = System.Drawing.Color.Red; >> this.mmTextBox1.Location = new System.Drawing.Point(0, 0); >> this.mmTextBox1.Name = "mmTextBox1"; >> this.mmTextBox1.Size = new System.Drawing.Size(100, 22); >> this.mmTextBox1.TabIndex = 0; >> >> } >> >> #endregion >> >> private OakLeaf.MM.Main.Windows.Forms.mmTextBox mmTextBox1; >> } >>} >>>>