Detect when a form opens

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Hi All

I have an on-screen keyboard within a POS program I have written in VB.net
2005, for touch screen computers

I have it set to 'always on top' so the user can move the cursor to
different text boxes and type using the on-screen keyboard
The keyboard launches via the mouseclick event for any text box

If another form is launched, with the onscreen keyboard still visible, the
on-screen keyboard cannot be closed as the new form is opened modally and
will not release focus

Is there an event which captures when any form loads so I can close the
on-screen keyboard first?

Any other ideas other than putting code in every forms load event?

Regards
Steve
 
Hi Steve,

Based on my understanding, you have a WinForm application and want to get
notified when any form is going to be shown, so that you could close the
on-screen keyboard first. If I'm off base, please feel free to let me know.

I would say that there may no such an event which captures when any form
loads. A workaround to your question is to detect whether the on-screen
keyboard is visible or not when a new form is going to be shown modally. If
yes, close the on-screen keyboard first and then show this new form.

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Heya Steve,

I'm not sure if this will help at all - BUT you can Override the OnLoad
method in your forms to handle additional logic that needs to be done

<code>
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
'Call your method to hide the keyboard BEFORE MyBase is called
MyBase.OnLoad(e)
End Sub
</code>

Although depending on how you developed the system you could possibly create
an overload for the form constructors and ensure the on screen keyboard is
closed before continuing. Possibly pass a Boolean to the overload to signify
that the keyboard is still visible and handle the logic from there...

<code>
Public Sub New(ByVal keyboardVisible As Boolean)
InitializeComponent()
hideKeyboard(keyboardVisible)
End Sub

Private Sub hideKeyboard(ByVal keyboardVisible As Boolean)
If keyboardVisible Then
'Do your magic :)
End If
End Sub
</code>

HTH
Brendon
 
Hi Linda

Thanks for the reply

Further to this
Is there a way to have a modeless topmost form (on screen keyboard) still
accept input (or at least fire an event when clicked) when a modal form is
opened with the modeless form already open?

I am looking for a way to put the code, to close the topmost form, in the
topmost form rather than having to put code in every form load event to
check if the topmost form is open then close it, as I have many forms in my
application

If so this would solve my issue

Regards
Steve
 
Hi Linda

Further to this

I tested the on-screen keyboard that comes with windows XP and it is still
active when I open a modal form from another modal form within my program

Maybe it is because it is a seperate application

Would running my onscreen keyboard in a different thread give the same
behaviour, or do I need to to have my onscreen keyboard as a seperate
application?

Regards
Steve
 
Hi Steve,

Thank you for your prompt reply!
Is there a way to have a modeless topmost form (on screen keyboard) still
accept input (or at least fire an event when clicked) when a modal form is
opened with the modeless form already open?

As you have mentioned, you could show the screen keyboard form in a
seperate thread to get the above behavior. The following is a sample to do
this:
public partial class Form1 : Form
{
delegate void ShowKeyBoardDelegate();
private void Form1_Load(object sender, EventArgs e)
{
ShowKeyBoardDelegate dele = new
ShowKeyBoardDelegate(ShowKeyBoard);
// With the call to the BeginInvoke method of the delegate, the
ShowKeyBoard method will be execute in a seperate thread within the
application thread pool
dele.BeginInvoke(null, null);
}
private void ShowKeyBoard()
{
Form2 frm = new Form2();
frm.TopMost = true;
Application.Run(frm);
}
}

I don't suggest you to have the onscreen keyboard as a seperate
application, because this involves the intercommunicate between two
application, which will definitely add complication.
I am looking for a way to put the code, to close the topmost form, in the
topmost form rather than having to put code in every form load event to
check if the topmost form is open then close it, as I have many forms in my
application

You can create a base form in your application and in its Load event
handler, check if the onscreen keyboard form is open and if yes, close it.
You need to derive all other forms(except the onscreen keyboard form) in
your application from this base form. Thus, when each derived form is
loaded, it will check if the onscreen keyboard form is open and you needn't
add code to every form to check this.

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support
 
Back
Top