.net - How to set focus to an object(textbox) in main form from another form (C#) -
Whatever problem I know, I should have trouble trying that my textbox is in a group box. I have a mainframe from which I go to any other form. When I come back to the mainfrom, I want to focus a particular object. How is this done? My main form is my code.
Private Zero Button 1_Click (Object Sender, EventEurge E) {Form 1 FM = New Form 1 (); Frm.ShowDialog (); } Now that I come back from Form 1 on my main form.
Private Zero Button 3_Click (Object Sender, EventArgs e) {this.DialogResult = DialogResult.OK; } I have textbox1 in the microform, except for Form1 and how to focus on TextBox 1 while entering the mainframe. I have textBox1.Focus (); and tried this. ActctControl = this.textBox1; Under load , show , active and enter the event still did not work Tried to make a public law and called it under the exit button of Form 1. like this. In the main form,
public zero text Box1Focus () {textBox1.Focus (); } and then in Form 1,
Private Zero Button 3_Click (Object Sender, EventArgs e) {this.DialogResult = DialogResult.OK; Main frame = new masterform (); Frm.textBox1Focus (); } who still do not work. Why can this be in my textbox 1 groupbox?
Thank you.
I do not understand how the code you show is also compiled. > TextBox1 is calling Focus () inside a method that is defined in the Form1 class, which is the best I can understand, in this for textBox1Focus Definition does not include . That method is defined only in the main format category. No more, it is difficult to say that there is something else wrong in your code to prevent it from receiving a text box focus placed in a group box; I think I'm looking at Sunset from Venice's blind, instead of a big picture window.
Anyway, I suspect that this is a simple solution. Just set the focus on the text box control at the end of the button1_Click method, the ShowDialog method is a blocked call, which means that the execution will not continue until the user returns another form Will not stop. When this happens, the execution will continue with the next line of code, which will focus on the text box control. Try changing your code to:
Private Zero Button 1_Click (Object Sender, EventEurge E) {Form 1 FM = New Form 1 (); Frm.ShowDialog (); This.textBox1.Select (); }
Comments
Post a Comment