Link to home
Start Free TrialLog in
Avatar of Parth48
Parth48Flag for India

asked on

how can i search textbox control on the current form in C#.net windows application ??

i want to know that how can i search textbox control on the current form in C#.net windows application ??

without linq how can i do it ??
Avatar of Parth48
Parth48
Flag of India image

ASKER

please refer the below code ...

private TextBox GetTextBox()
        {
            TextBox txtPasskey = new TextBox();
            txtPasskey.Name = "txtPasskey";
            txtPasskey.MaxLength = 8;
            txtPasskey.PasswordChar = '*';
            txtPasskey.TextAlign = HorizontalAlignment.Left;
            txtPasskey.Location = new Point(200, 200);
            txtPasskey.TextChanged += new EventHandler(this.txtPasskey_TextChanged);
            txtPasskey.Validating += new CancelEventHandler(this.txtPasskey_Validating);
            return txtPasskey;
        }

Open in new window


now how can i find above textbox(txtPasskey) without linq ??
Avatar of Dirk Haest
Why wouldn't you use LINQ ? If you really not want to do that, you'll need to implement a loop over all your controls

Example without linq

foreach (Control con in mainForm.Controls)
    {
        if ( control is Textbox  && control.Name = ""YourTextBox")
                 // now you have your textbox
    }


See also: http://www.dotnetperls.com/query-windows-forms
You can also use the Old Way ;-)

TextBox MyTextBox = control.FindControl("YourTextBox") as TextBox;
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial