Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Custom Windows Controls

Custom Windows Controls

Scheduled Pinned Locked Moved C#
graphicstutorialquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gktony
    wrote on last edited by
    #1

    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; } } }

    A E 2 Replies Last reply
    0
    • G Gktony

      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; } } }

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      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 !!! Thanks

      Best Regards ----------------- Abhijit Jana Check Out My Latest Article Java.NET : Integration of Java and .NET[^] "Success is Journey it's not a destination"

      G 1 Reply Last reply
      0
      • G Gktony

        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; } } }

        E Offline
        E Offline
        eggsovereasy
        wrote on last edited by
        #3

        Set the anchors for the text box.

        G 1 Reply Last reply
        0
        • A Abhijit Jana

          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 !!! Thanks

          Best Regards ----------------- Abhijit Jana Check Out My Latest Article Java.NET : Integration of Java and .NET[^] "Success is Journey it's not a destination"

          G Offline
          G Offline
          Gktony
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • E eggsovereasy

            Set the anchors for the text box.

            G Offline
            G Offline
            Gktony
            wrote on last edited by
            #5

            How do I set the anchors for the textbox? Sorry I am new to it Thanks Tony

            E 1 Reply Last reply
            0
            • G Gktony

              How do I set the anchors for the textbox? Sorry I am new to it Thanks Tony

              E Offline
              E Offline
              eggsovereasy
              wrote on last edited by
              #6

              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.

              G 1 Reply Last reply
              0
              • E eggsovereasy

                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.

                G Offline
                G Offline
                Gktony
                wrote on last edited by
                #7

                I am going to try it. But how can I make the label extensible as well? Thanks for your help Tony

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups