[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-03-10
4
Medium Priority
?
522 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
ID: 35093585
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
ID: 35093619
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
ID: 35093786
You can also use the Old Way ;-)

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

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 35095183
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Loops Section Overview
Suggested Courses

872 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