Solved

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

Posted on 2011-03-10
4
510 Views
Last Modified: 2012-05-11
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 ??
0
Comment
Question by:Parth48
4 Comments
 

Author Comment

by:Parth48
Comment Utility
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 ??
0
 
LVL 53

Expert Comment

by:Dhaest
Comment Utility
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
0
 
LVL 10

Expert Comment

by:John Claes
Comment Utility
You can also use the Old Way ;-)

TextBox MyTextBox = control.FindControl("YourTextBox") as TextBox;
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
For WinForms, it would be similar:
string CtlName = "txtPasskey";
            Control[] matches = this.Controls.Find(CtlName, true);
            if (matches.Length > 0)
            {
                // ... do something with matches[0] ...
                if (matches[0] is TextBox)
                {
                    TextBox tb = (TextBox)matches[0];
                    tb.Text = "You found me!";
                }
            }

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now