dennismagno / metroframework-modern-ui

My humble attempt to bring the new Modern UI alias Metro UI of Windows 8 to .NET Windows Forms applications.
http://dennismagno.github.io/metroframework-modern-ui
Other
861 stars 1.08k forks source link

Textbox can't set focus #23

Closed ricoris closed 7 years ago

ricoris commented 7 years ago

When using the the "Form1 : MetroFramework.Forms.MetroForm" I cant have a metroTextBox1 "active" Tab Index is 0. I want to start typing in the textbox. Before I can input I must click on the textbox. When I remove MetroFramework.Forms.MetroForm and use standard winform "Form1 : Form" I can start typing in the textbox.

Is this an Error? Compleate "Form1.cs code" public partial class Form1 : Form

{
    public Form1()
    {
        InitializeComponent();
    }

    private void metroUserControl1_Load(object sender, EventArgs e)
    {

    }

    private void Form1_Load(object sender, EventArgs e)
    {
        metroTextBox1.Focus();
    }
}
dennismagno commented 7 years ago

Hi, even on the regular TextBox your code is also not working. You can use the Shown event to set focus on the control that you want to focus on when loaded.

ricoris commented 7 years ago

Truethe regular isn't working eihter when using " : MetroFramework.Forms.MetroForm" , changing to standard winform ": Form" it is working. The showen event after Initialize(); can't set focus either. Can it be MetroForm which is messing with the .Focus()

dennismagno commented 7 years ago

I also tested in regular form it is actually the same.

ricoris commented 7 years ago

Strange, I think I found a work around, when the form is loaded event I'm setting this.BringToFront(); then I can enter the textbox right away. Thanks for your time.

PasanBhanu commented 6 years ago

I had the same issue. I found this solution.

Senerio : I call form2 from form1. When form2 unloads I want to focus to text box in form1. I also has to pass some data to a text box in form1. I used a setter function to pass that data.

I added this codes when second form unloads.

form1.BringToFront() form1.txtMy.Select() form1.Select()

This work fine but I have triggered keypress event on txtMy for Enter Key. Due to the above code that event runs. I think form1.select send Enter Key Code.