I found a few topics about this but none of these could help me with my problem, i want to set the focus on a new created winform window after it started.
I'm starting the form in a own new thread with:
application.Run(new InvisibleForm());
and the form appears, but the focus is still set on the last selected window from windows. this form has no titlebar and is not in the taskpanel to see, it also has a TransparencyKey set:
this.AutoScaleDimensions = new SizeF(6F, 13F);
this.AutoScaleMode = AutoScaleMode.Font;
this.BackColor = SystemColors.AppWorkspace;
this.ClientSize = new Size(992, 992);
this.ControlBox = false;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "InvisibleForm";
this.Opacity = 0.5;
this.ShowInTaskbar = false;
this.TransparencyKey = SystemColors.AppWorkspace;
this.Load += new EventHandler(this.InvisibleForm_Load);
now i tried a few methods but none of these got me focus on the form or could set the form on the foreground / of top of all other windows:
this.TopMost = true;
this.Focus();
this.BringToFront();
this.Activate();
is there a way to fire programmly a click / focus event to the form so that it sets himself with this event on focus ?
The Focus method returns true if the control successfully received input focus. The control can have the input focus while not displaying any visual cues of having the focus. This behavior is primarily observed by the nonselectable controls listed below, or any controls derived from them.
The focus() method is used to give focus to a text field. Tip: Use the blur() method to remove focus from a text field.
When showing a form that contains a TextBox, it's common courtesy to focus the TextBox so that the user can begin typing immediately. To focus a TextBox when a Windows Form first loads, simply set the TabIndex for the TextBox to zero (or the lowest TabIndex for any Control on the Form).
Its important to use the Activate()
method in the "shown" state of the form, so create a listener for the shown event and use your focus / front methods there
you can trying this code
this.ShowDialog();
the code above same as MessageBox with attention. So the last form appear must close and can access the other form again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With