Custom Windows Controls
-
Hi all, I am developing some custom windows controls and I want every control to be resized when used on the windows form. For example if there is a text box the user can extend the length by just extendeing the legnth of the control. I cannot do this succesfully at then moment I have tried to set AutoSize to true and the AutoSizeMode to GrowAndShrink but it doesn't work. Do you have any examples? Thanks in Advance Tony Here is my code for the control using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; namespace UserControls.UIControls { public partial class LabelledText : UserControl { public delegate void EventHandler(Object sender, EventArgs e); public event EventHandler onGetFocus; public event EventHandler onLostFocus; public LabelledText() { InitializeComponent(); } public string LabelText { get { return lbl.Text; } set { lbl.Text = value; } } public ContentAlignment LabelAlign { get { return lbl.TextAlign; } set { lbl.TextAlign = value; } } public string TextBoxText { get { return txt.Text; } set { txt.Text = value; } } public HorizontalAlignment TextBoxAlign { get { return txt.TextAlign; } set { txt.TextAlign = value; } } private void LabelledText_Load(object sender, EventArgs e) { txt.BackColor = System.Drawing.SystemColors.Control; } private void txt_Leave(object sender, EventArgs e) { txt.BackColor = System.Drawing.SystemColors.Control; } private void txt_Enter(object sender, EventArgs e) { txt.BackColor = System.Drawing.Color.White; } } }
-
Hi all, I am developing some custom windows controls and I want every control to be resized when used on the windows form. For example if there is a text box the user can extend the length by just extendeing the legnth of the control. I cannot do this succesfully at then moment I have tried to set AutoSize to true and the AutoSizeMode to GrowAndShrink but it doesn't work. Do you have any examples? Thanks in Advance Tony Here is my code for the control using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; namespace UserControls.UIControls { public partial class LabelledText : UserControl { public delegate void EventHandler(Object sender, EventArgs e); public event EventHandler onGetFocus; public event EventHandler onLostFocus; public LabelledText() { InitializeComponent(); } public string LabelText { get { return lbl.Text; } set { lbl.Text = value; } } public ContentAlignment LabelAlign { get { return lbl.TextAlign; } set { lbl.TextAlign = value; } } public string TextBoxText { get { return txt.Text; } set { txt.Text = value; } } public HorizontalAlignment TextBoxAlign { get { return txt.TextAlign; } set { txt.TextAlign = value; } } private void LabelledText_Load(object sender, EventArgs e) { txt.BackColor = System.Drawing.SystemColors.Control; } private void txt_Leave(object sender, EventArgs e) { txt.BackColor = System.Drawing.SystemColors.Control; } private void txt_Enter(object sender, EventArgs e) { txt.BackColor = System.Drawing.Color.White; } } }
Hi Tony, Just Use Following Code in you Control.
private void UserControl1_Load(object sender, EventArgs e) { textBox1.Width = this.Width; } private void UserControl1_Resize(object sender, EventArgs e) { textBox1.Width = this.Width; }
Note : Change Control Name According to your control Let me know when done !!! ThanksBest Regards ----------------- Abhijit Jana Check Out My Latest Article Java.NET : Integration of Java and .NET[^] "Success is Journey it's not a destination"
-
Hi all, I am developing some custom windows controls and I want every control to be resized when used on the windows form. For example if there is a text box the user can extend the length by just extendeing the legnth of the control. I cannot do this succesfully at then moment I have tried to set AutoSize to true and the AutoSizeMode to GrowAndShrink but it doesn't work. Do you have any examples? Thanks in Advance Tony Here is my code for the control using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; namespace UserControls.UIControls { public partial class LabelledText : UserControl { public delegate void EventHandler(Object sender, EventArgs e); public event EventHandler onGetFocus; public event EventHandler onLostFocus; public LabelledText() { InitializeComponent(); } public string LabelText { get { return lbl.Text; } set { lbl.Text = value; } } public ContentAlignment LabelAlign { get { return lbl.TextAlign; } set { lbl.TextAlign = value; } } public string TextBoxText { get { return txt.Text; } set { txt.Text = value; } } public HorizontalAlignment TextBoxAlign { get { return txt.TextAlign; } set { txt.TextAlign = value; } } private void LabelledText_Load(object sender, EventArgs e) { txt.BackColor = System.Drawing.SystemColors.Control; } private void txt_Leave(object sender, EventArgs e) { txt.BackColor = System.Drawing.SystemColors.Control; } private void txt_Enter(object sender, EventArgs e) { txt.BackColor = System.Drawing.Color.White; } } }
Set the anchors for the text box.
-
Hi Tony, Just Use Following Code in you Control.
private void UserControl1_Load(object sender, EventArgs e) { textBox1.Width = this.Width; } private void UserControl1_Resize(object sender, EventArgs e) { textBox1.Width = this.Width; }
Note : Change Control Name According to your control Let me know when done !!! ThanksBest Regards ----------------- Abhijit Jana Check Out My Latest Article Java.NET : Integration of Java and .NET[^] "Success is Journey it's not a destination"
Thanks Abhijit that works fine. However I have a label on the left of the textbox which I want the user to extend it. Also I want the label to get extended automatically when typing long text into it. For example if the text on the label is long like 'International Accounts:' the label should be extended to the size of the text in order to display the whole text. Thanks in advance Tony
-
Set the anchors for the text box.
-
In the designer if you select the text box and look in the properties grid there is one called Anchor in the Layout section. You can set which sides to anchor and when the form is resized the control will try to stay the same distance from the edge. However, I don't think a TextBox will stretch up and down unless you have Multiline set to true.
-
In the designer if you select the text box and look in the properties grid there is one called Anchor in the Layout section. You can set which sides to anchor and when the form is resized the control will try to stay the same distance from the edge. However, I don't think a TextBox will stretch up and down unless you have Multiline set to true.