gotfocus keeps firing

D

David

Hi,

I am not sure if this is a general framework question or specific to the
device.

I am using CF 1.

I have my own numeric input panel (larger buttons required...). When I enter
a textbox, I use its onfocus event to fire up the panel. (the panel is on
its own form).

When I finished with the panel, it will close and return to the main form
the value entered, however, when the main form re-appears, it re-fires the
gotfocus, restarting my numeric panel.

How can I get around this. (I have tried a toggle to stop it, I have tried
setting focus to something else)

Here is my code...

bool ValueInFocus = false;
NumericPad NumPad;

private void ActualValues_GotFocus(object sender, System.EventArgs e)
{

if (!ValueInFocus)
{
ValueInFocus = true;
NumPad = new NumericPad();

NumPad.Actual = Convert.ToDouble(dTable.Rows[RecordIndex]["Actual"]);
NumPad.Upper = Convert.ToDouble(dTable.Rows[RecordIndex]["Upper"]);
NumPad.Nominal = Convert.ToDouble(dTable.Rows[RecordIndex]["Nominal"]);
NumPad.Lower = Convert.ToDouble(dTable.Rows[RecordIndex]["Lower"]);

NumPad.Closing += new
System.ComponentModel.CancelEventHandler(this.numPad_Closing);
NumPad.Closed += new System.EventHandler(this.numPad_Close);

NumPad.ShowDialog();

NumPad.Dispose();
}
// Problem with number actualvalue retaining focus and causing number
panel to pop-up again.
//SaveButton.Focus();
}

private void numPad_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
dTable.Rows[RecordIndex]["Actual"] = NumPad.Actual;
ActualValues.Text = dTable.Rows[RecordIndex]["Actual"].ToString();
CalculateError();

SaveButton.Focus();
}

private void numPad_Close(object sender, EventArgs e)
{
ValueInFocus = false;
}


--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
J

Jin Chang

Hi,

I am not sure if this is a general framework question or specific to the
device.

I am using CF 1.

I have my own numeric input panel (larger buttons required...). When I enter
a textbox, I use its onfocus event to fire up the panel. (the panel is on
its own form).

When I finished with the panel, it will close and return to the main form
the value entered, however, when the main form re-appears, it re-fires the
gotfocus, restarting my numeric panel.

How can I get around this. (I have tried a toggle to stop it, I have tried
setting focus to something else)

Here is my code...

bool ValueInFocus = false;
NumericPad NumPad;

private void ActualValues_GotFocus(object sender, System.EventArgs e)
{

if (!ValueInFocus)
{
ValueInFocus = true;
NumPad = new NumericPad();

NumPad.Actual = Convert.ToDouble(dTable.Rows[RecordIndex]["Actual"]);
NumPad.Upper = Convert.ToDouble(dTable.Rows[RecordIndex]["Upper"]);
NumPad.Nominal = Convert.ToDouble(dTable.Rows[RecordIndex]["Nominal"]);
NumPad.Lower = Convert.ToDouble(dTable.Rows[RecordIndex]["Lower"]);

NumPad.Closing += new
System.ComponentModel.CancelEventHandler(this.numPad_Closing);
NumPad.Closed += new System.EventHandler(this.numPad_Close);

NumPad.ShowDialog();

NumPad.Dispose();
}
// Problem with number actualvalue retaining focus and causing number
panel to pop-up again.
//SaveButton.Focus();
}

private void numPad_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
dTable.Rows[RecordIndex]["Actual"] = NumPad.Actual;
ActualValues.Text = dTable.Rows[RecordIndex]["Actual"].ToString();
CalculateError();

SaveButton.Focus();
}

private void numPad_Close(object sender, EventArgs e)
{
ValueInFocus = false;
}

Seems like the TextBox control is getting the focus again once
returning from your numeric input panel, thus triggering the event
again.
One way to avoid this is to have a global boolean variable that keeps
track of your numeric input panel status.
Set it to false initially, check it to see if it's false in your focus
event handler before invoking the panel, set it to true within the
panel, set it to false within your focus event handler if it's true
(and don't invoke the panel) so that later focus will behave
correctly.

If the cause was due to something else, like multiple focus behavior
for some odd reason, then this approach won't work.

- Jin
 
D

David

Hi,

I am not sure if this is a general framework question or specific to the
device.

I am using CF 1.

I have my own numeric input panel (larger buttons required...). When I
enter
a textbox, I use its onfocus event to fire up the panel. (the panel is on
its own form).

When I finished with the panel, it will close and return to the main form
the value entered, however, when the main form re-appears, it re-fires
the
gotfocus, restarting my numeric panel.

How can I get around this. (I have tried a toggle to stop it, I have
tried
setting focus to something else)

Here is my code...

bool ValueInFocus = false;
NumericPad NumPad;

private void ActualValues_GotFocus(object sender, System.EventArgs e)
{

if (!ValueInFocus)
{
ValueInFocus = true;
NumPad = new NumericPad();

NumPad.Actual = Convert.ToDouble(dTable.Rows[RecordIndex]["Actual"]);
NumPad.Upper = Convert.ToDouble(dTable.Rows[RecordIndex]["Upper"]);
NumPad.Nominal =
Convert.ToDouble(dTable.Rows[RecordIndex]["Nominal"]);
NumPad.Lower = Convert.ToDouble(dTable.Rows[RecordIndex]["Lower"]);

NumPad.Closing += new
System.ComponentModel.CancelEventHandler(this.numPad_Closing);
NumPad.Closed += new System.EventHandler(this.numPad_Close);

NumPad.ShowDialog();

NumPad.Dispose();
}
// Problem with number actualvalue retaining focus and causing number
panel to pop-up again.
//SaveButton.Focus();
}

private void numPad_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
dTable.Rows[RecordIndex]["Actual"] = NumPad.Actual;
ActualValues.Text = dTable.Rows[RecordIndex]["Actual"].ToString();
CalculateError();

SaveButton.Focus();
}

private void numPad_Close(object sender, EventArgs e)
{
ValueInFocus = false;
}

Seems like the TextBox control is getting the focus again once
returning from your numeric input panel, thus triggering the event
again.
One way to avoid this is to have a global boolean variable that keeps
track of your numeric input panel status.
Set it to false initially, check it to see if it's false in your focus
event handler before invoking the panel, set it to true within the
panel, set it to false within your focus event handler if it's true
(and don't invoke the panel) so that later focus will behave
correctly.

If the cause was due to something else, like multiple focus behavior
for some odd reason, then this approach won't work.

- Jin


Yes, the textbox is regaining focus hence causing the refiring...

I am already doing this...

ValueInFocus is my boolean and is set to false.

In the gotfocus handler, I check if false, if it is, I allow the numeric
panel to show. Inside the gotfocus event handler, I then set the value to
true.

Now, I have to set the value back to false at some stage so that I can
pop-up the numeric panel later... I have tried doing this after returning
from the panel, but it seems that doesn't stop it. I have tried setting it
to false in the onClosing event and the Closed event. Again, these fire
prior to the end of the gotfocus handler, so when the panel finally
disappears, the cursor is back in the textbox causing the focus event to run
again.


What is odd is that this does not happen on the emulator (WM5 I guess),
though it is happening on my device, WM6.

I may have to rethink... perhaps using a click handler rather than onfocus.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
J

Jin Chang

Hi,
I am not sure if this is a general framework question or specific to the
device.
I am using CF 1.
I have my own numeric input panel (larger buttons required...). When I
enter
a textbox, I use its onfocus event to fire up the panel. (the panel is on
its own form).
When I finished with the panel, it will close and return to the main form
the value entered, however, when the main form re-appears, it re-fires
the
gotfocus, restarting my numeric panel.
How can I get around this. (I have tried a toggle to stop it, I have
tried
setting focus to something else)
Here is my code...
bool ValueInFocus = false;
NumericPad NumPad;
private void ActualValues_GotFocus(object sender, System.EventArgs e)
{
if (!ValueInFocus)
{
ValueInFocus = true;
NumPad = new NumericPad();
NumPad.Actual = Convert.ToDouble(dTable.Rows[RecordIndex]["Actual"]);
NumPad.Upper = Convert.ToDouble(dTable.Rows[RecordIndex]["Upper"]);
NumPad.Nominal =
Convert.ToDouble(dTable.Rows[RecordIndex]["Nominal"]);
NumPad.Lower = Convert.ToDouble(dTable.Rows[RecordIndex]["Lower"]);
NumPad.Closing += new
System.ComponentModel.CancelEventHandler(this.numPad_Closing);
NumPad.Closed += new System.EventHandler(this.numPad_Close);
NumPad.ShowDialog();
NumPad.Dispose();
}
// Problem with number actualvalue retaining focus and causing number
panel to pop-up again.
//SaveButton.Focus();
}
private void numPad_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
dTable.Rows[RecordIndex]["Actual"] = NumPad.Actual;
ActualValues.Text = dTable.Rows[RecordIndex]["Actual"].ToString();
CalculateError();
SaveButton.Focus();
}
private void numPad_Close(object sender, EventArgs e)
{
ValueInFocus = false;
}
Seems like the TextBox control is getting the focus again once
returning from your numeric input panel, thus triggering the event
again.
One way to avoid this is to have a global boolean variable that keeps
track of your numeric input panel status.
Set it to false initially, check it to see if it's false in your focus
event handler before invoking the panel, set it to true within the
panel, set it to false within your focus event handler if it's true
(and don't invoke the panel) so that later focus will behave
correctly.
If the cause was due to something else, like multiple focus behavior
for some odd reason, then this approach won't work.

Yes, the textbox is regaining focus hence causing the refiring...

I am already doing this...

ValueInFocus is my boolean and is set to false.

In the gotfocus handler, I check if false, if it is, I allow the numeric
panel to show. Inside the gotfocus event handler, I then set the value to
true.

Now, I have to set the value back to false at some stage so that I can
pop-up the numeric panel later... I have tried doing this after returning
from the panel, but it seems that doesn't stop it. I have tried setting it
to false in the onClosing event and the Closed event. Again, these fire
prior to the end of the gotfocus handler, so when the panel finally
disappears, the cursor is back in the textbox causing the focus event to run
again.

What is odd is that this does not happen on the emulator (WM5 I guess),
though it is happening on my device, WM6.

I may have to rethink... perhaps using a click handler rather than onfocus.

It's odd that the behaviors are different between the emulator and the
device. I suppose there could be differences between WM5 and WM6, but
for something as straight forward as this, I doubt it.

Just to be clear, what I had in mind was slightly different from what
you seem to be describing. Here are the steps I had in mind again:

1. Set the ValueInFocus to false initially.
2. When TextBox gains focus, you do one of two things:
(a) If ValueInFocus is False, invoke the Dialog.
(b) If ValueInFocus is True, do not invoke the Dialog, but set
the ValueInFocus to False once again.
3. Withing the Dialog, set the ValueInFocus to True (you can do this
on the Close event).

I think these steps are slightly different from what you described.
This logic will either work or tell you that the Focus event for the
TextBox is being generated at times you're not expecting. That should
at least give you a clue to debug on.

- Jin
 
D

David

Jin Chang said:
I am not sure if this is a general framework question or specific to
the
device.
I am using CF 1.
I have my own numeric input panel (larger buttons required...). When I
enter
a textbox, I use its onfocus event to fire up the panel. (the panel is
on
its own form).
When I finished with the panel, it will close and return to the main
form
the value entered, however, when the main form re-appears, it re-fires
the
gotfocus, restarting my numeric panel.
How can I get around this. (I have tried a toggle to stop it, I have
tried
setting focus to something else)
Here is my code...
bool ValueInFocus = false;
NumericPad NumPad;
private void ActualValues_GotFocus(object sender, System.EventArgs
e)
{
if (!ValueInFocus)
{
ValueInFocus = true;
NumPad = new NumericPad();
NumPad.Actual =
Convert.ToDouble(dTable.Rows[RecordIndex]["Actual"]);
NumPad.Upper =
Convert.ToDouble(dTable.Rows[RecordIndex]["Upper"]);
NumPad.Nominal =
Convert.ToDouble(dTable.Rows[RecordIndex]["Nominal"]);
NumPad.Lower =
Convert.ToDouble(dTable.Rows[RecordIndex]["Lower"]);
NumPad.Closing += new
System.ComponentModel.CancelEventHandler(this.numPad_Closing);
NumPad.Closed += new System.EventHandler(this.numPad_Close);

NumPad.Dispose();
}
// Problem with number actualvalue retaining focus and causing
number
panel to pop-up again.
//SaveButton.Focus();
}
private void numPad_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
dTable.Rows[RecordIndex]["Actual"] = NumPad.Actual;
ActualValues.Text = dTable.Rows[RecordIndex]["Actual"].ToString();
CalculateError();
SaveButton.Focus();
}

private void numPad_Close(object sender, EventArgs e)
{
ValueInFocus = false;
}
Seems like the TextBox control is getting the focus again once
returning from your numeric input panel, thus triggering the event
again.
One way to avoid this is to have a global boolean variable that keeps
track of your numeric input panel status.
Set it to false initially, check it to see if it's false in your focus
event handler before invoking the panel, set it to true within the
panel, set it to false within your focus event handler if it's true
(and don't invoke the panel) so that later focus will behave
correctly.
If the cause was due to something else, like multiple focus behavior
for some odd reason, then this approach won't work.

Yes, the textbox is regaining focus hence causing the refiring...

I am already doing this...

ValueInFocus is my boolean and is set to false.

In the gotfocus handler, I check if false, if it is, I allow the numeric
panel to show. Inside the gotfocus event handler, I then set the value to
true.

Now, I have to set the value back to false at some stage so that I can
pop-up the numeric panel later... I have tried doing this after returning
from the panel, but it seems that doesn't stop it. I have tried setting
it
to false in the onClosing event and the Closed event. Again, these fire
prior to the end of the gotfocus handler, so when the panel finally
disappears, the cursor is back in the textbox causing the focus event to
run
again.

What is odd is that this does not happen on the emulator (WM5 I guess),
though it is happening on my device, WM6.

I may have to rethink... perhaps using a click handler rather than
onfocus.

It's odd that the behaviors are different between the emulator and the
device. I suppose there could be differences between WM5 and WM6, but
for something as straight forward as this, I doubt it.

Just to be clear, what I had in mind was slightly different from what
you seem to be describing. Here are the steps I had in mind again:

1. Set the ValueInFocus to false initially.
2. When TextBox gains focus, you do one of two things:
(a) If ValueInFocus is False, invoke the Dialog.
(b) If ValueInFocus is True, do not invoke the Dialog, but set
the ValueInFocus to False once again.
3. Withing the Dialog, set the ValueInFocus to True (you can do this
on the Close event).

I think these steps are slightly different from what you described.
This logic will either work or tell you that the Focus event for the
TextBox is being generated at times you're not expecting. That should
at least give you a clue to debug on.

- Jin


Hi Jin,

I think that is what I was doing, but as I am initialising the numeric panel
within the gotfocus, I can only initialise the closing event there as well,
so, basically, at the end of the event, the value is set back to false
before the end of the gotfocus event.

Anyhow, it is now academic as I have now got it working. Basically, I
re-adjusted the code, ultimately, before the end of the gotfocus, I am
moving the focus to a button (though I did try that before and it didn't
work).

This now works and I am happy, though I am waiting for feedback from WM5
devices.



--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
Top