dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Dynamically change textbox width and name

  1. #1
    Join Date
    Jan 2010
    Posts
    2

    Unhappy Dynamically change textbox width and name

    I want to be able to move and resize my textboxes on my form...and the moving left\top works great, but I cant seem to change the width at all. I see the value change in debug, but the size on the screen doesnt seem to change at all...is there some trick to it?

    Code:
    private void propName_TextChanged(object sender, EventArgs e) {
                if (!String.IsNullOrEmpty(propName.Text)) {
                    foreach (Control c in panel1.Controls) {
                        if(c.Name == propName.Text){
                            c.Name = propName.Text;
                            if (!String.IsNullOrEmpty(propWidth.Text)) {
                                try {
                                    MyTextBox newTB = (MyTextBox)c;
                                    newTB.Name = (String.IsNullOrEmpty(propName.Text)) ? "" : propName.Text;
                                    newTB.Text = (String.IsNullOrEmpty(propName.Text)) ? "" : propName.Text;
                                    newTB.Left = (String.IsNullOrEmpty(propX.Text)) ? 0 : Convert.ToInt32(propX.Text);
                                    newTB.Top = (String.IsNullOrEmpty(propY.Text)) ? 0 : Convert.ToInt32(propY.Text);
                                    newTB.Width = (String.IsNullOrEmpty(propWidth.Text)) ? 0 : Convert.ToInt32(propWidth.Text);
                                    newTB.MaxLength = (String.IsNullOrEmpty(propMax.Text)) ? 0 : Convert.ToInt32(propMax.Text);
                                } catch (Exception ex) {
                                    Debug.WriteLine(ex.ToString());
                                }
                            }
                        }
                    }
                }
            }
    Any info would be AWESOME
    Last edited by HanneSThEGreaT; January 15th, 2010 at 08:04 AM.

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    210

    Re: Dynamically change textbox width and name

    What is "MyTextBox"?

    If this is not the TextBox in your form, you can change the values all night long w/o seeing any changes on the form, since it is NOT your controller.

  3. #3
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: Dynamically change textbox width and name

    Quote Originally Posted by stevescottwork View Post
    Any info would be AWESOME
    this is so true.

    can you post more code and inside code tags? then tell us what does not work and where.
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  4. #4
    Join Date
    Jan 2010
    Posts
    2

    Re: Dynamically change textbox width and name

    Quote Originally Posted by memeloo View Post
    this is so true.

    can you post more code and inside code tags? then tell us what does not work and where.
    MyTextBox inherited from TextBox to just allow me to set some common properties easier

    anywho, thats where the problem was

    Rectangle r = new Rectangle(this.ClientRectangle.X, this.ClientRectangle.Y+1, this.ClientRectangle.Width, this.ClientRectangle.Height - 2);
    this.Region = new Region(r);

    Thanks guys

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)