Open domeneo opened 7 years ago
Is it a bug, in c# on FormLoad when using "Form1 : MetroFramework.Forms.MetroForm" my textbox wont recieve input but switching to Form1 :Form now it is working and I can type text in the textbox.
How to make a textbox recieve focus and reade for input when the MetroForm is loaded?
I have tried a lot of googlinge samples. Here is the code not working (tabindex is 0): public partial class Form1 : MetroFramework.Forms.MetroForm { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.ActiveControl = textBox1; textBox1.Focus(); } }
There seems to be something wrong with MetroForm class related to form activation.
Commenting out the entire 'private void OnTargetFormActivated(object sender, EventArgs e)' method contents will fix several focus issues for me.
Even the demo program has problems activating the main form. If you deactivate window (select another program) and try to select any tab inside the demo app you have to click three times on a single location, or two times if you click on separate locations.
This seems to go away by commenting out theOnTargetFormActivated method.
Didn't have time to investigate that further :)
I know this is kind of old now but I just ran into the same exact problem @mvehkala ran into and was able to find a fix. Seems like the shadow that shows by default with a MetroForm is what causes the interruption in reactivating the form. On the MetroForm properties set ShadowType to None. In the Designer.cs file it shows as:
this.ShadowType = MetroFramework.Forms.MetroFormShadowType.None;
Hope this helps someone out there :)
I know this is kind of old now but I just ran into the same exact problem @mvehkala ran into and was able to find a fix. Seems like the shadow that shows by default with a MetroForm is what causes the interruption in reactivating the form. On the MetroForm properties set ShadowType to None. In the Designer.cs file it shows as:
this.ShadowType = MetroFramework.Forms.MetroFormShadowType.None;
Hope this helps someone out there :)
You have no idea how long I've been searching for this issue. Thanks a ton bro.
when i focus another program than come to running metro form it doesn't focus it automatically until metro form is not clicked its annoying when user has to copy/paste data from other program to metro form. even when meto form is loaded it is not in focus to accept key press, same when after metro message box disappears the metro form doesn't accept key press.
If disable shadows it'll be fixed
You do not need to disable shadow to solve this, the issue is with how the shadow control is receiving focus when the user intends on focusing the window.
In MetroFramework\Forms\MetroForm.cs you'll find the following code in MetroShadowBase class:
private void OnTargetFormActivated(object sender, EventArgs e) {
if (Visible) Update();
if (isBringingToFront) {
Visible = true;
isBringingToFront = false;
return;
}
BringToFront();
}
Removing BringToFront(); fixes the issue.
I know this is kind of old now but me too ran into same problem. Recently I had to develop a Windows Application. ShadowType is the real problem. Setting ShadowType to None will make things work perfectly. You can still set the ShadowType to anything you want. I found another way to make it work. Please remember this is not the correct way but for immediate solution this can be used. this will simply force the form to get focus.
private void frmMain_Activated(object sender, EventArgs e) {
txtId.Focus();
this.WindowState = FormWindowState.Minimized;
this.WindowState = FormWindowState.Normal;
}
I would suggest rebuilding the framework with the change I mentioned above instead. Hacky solutions to refocus the form by changing its state will not be ideal if you have events listening on those state changes.
when i use this code
Dim pgb As New ProgressFrm pgb.PGB.Maximum = 3 pgb.Show() . . pgb.close() txtcode.Focus() txtcode.Focus()
I solve by Double Focus. And When open Program must Double Click to Focus in textbox.