Query, raining the SIP on a form, C#

N

Neville Lang

Hi all,

I thought I had the SIP under control but now I get an exception whenever I
try to either raise it programmatically or set the Enabled property to True.
All I have done is to drop an Input Panel (named MySIP) onto my form in the
Designer then in the constructor of the form have "this.MySIP.Enabled =
true;". When this is run in the debugger, it throws the following
exception:

A managed Exception occurred at
MISC::HandleAr+0x5b

MISC::HandleAr+0x5b
InputPanel::set_Enabled+0x12
MyForm::InitializeComponent+0x3
e8
MyForm::.ctor+0xc
....
....
....
....


Does anyone know what might be causing this exception?

Regards,
Neville Lang
 
A

Alex Feinman [MVP]

You cannot raise sip in InitializeComponent as window is not created yet. Do
it in Load instead
 
N

Neville Lang

Eelco,

Thank you for reply. I do have a menu control on my form.

Regards,
Neville Lang
 
N

Neville Lang

Alex,

Programmatically, I was setting MySIP.Enable = true just after
InitializeComponent() in the Form's constructor - add got the Exception
error. Next, I deleted that code and simply set the Enabled property on the
InputPanel property in the Designer. In InitializeComponent, after the
Designer change, I can see the Enable property being set to true, and this
is the error message that I posted, though I got it in both cases. From what
you have said, it simply means that we cannot set the Enabled property of an
InputPanel in the Designer.

Can you tell me more about Load(). I have never used that before.

I am guessing therefore that you cannot raise the SIP in a form's
constructor either. So is Load() the only place to do it?

Regards,
Neville Lang
 
N

Neville Lang

Alex,

I should have read my books before jumping on here. I see that the examples
quoted suggest raising it on textBox1_GotFocus() and lowering it on
textBox1_LostFocus(). Together with your information, it now makes sense to
only raise it once the Form window has been drawn - and of course the
textBox1_GotFocus() is a good place to do this.

BTW, the book Microsoft .NET Compact Framework by Andy Wigley and Stephen
Wheelwright has given me some good information over the weeks I have had it,
together with this NG of course - super service from the respondents.

Regards,
Neville Lang
 
S

Shanti

GotFocus and LostFocus are the right places. But you will have to follow
with 'DoEvents()' after the sip.Enabled = true / false.

But including it in both GotFocus() and LostFocus() gives raise to a
problem. The sceneraio is:
1. Focus is in textbox1. SIP is enabled and shows up.
2. Move focus to textbox2 and try to type in. Nothing appears in textbox2.
3. Just re-focus textbox2 (by tapping just there, nowhere else). Now type
and chars appear.

I could resolve the problem only by not using it in LostFocus() but coding
only GotFocus(). That is when any control's GotFocus(), set sip.Enabled =
true if that control need sip. Otherwise set sip.Enabled = false. This
should be followed by DoEvents(). I think DoEvents() in LostFocus() of
previous control eats up the GotFocus() event of next control.

I don't know if there is any better solution. Any help?

ThanQ...
 
N

Neville Lang

Shanti,

Since I wanted to raise the SIP on the first TextBox, I did it on the
GotFocus() event for that control. I wanted to keep the SIP up for the
remainder of the TextBoxes so did not do anything else until either the OK
or Cancel buttons were tapped, where I lowered it at that point before going
on to another screen. This approach seems to work well for me.

Thank you for your reply.

Regards,
Neville Lang
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top