Reputation: 1128
I want to change a textBox.text
only if it is not in focus. Example:
public void updateValue()
{
if (!this.valueTB.IsFocused)
this.valueTB.Text = updatedValue.ToString();
}
But the problem is that this.valueTB.IsFocused
property changes only when it's actually focused but not when it's focused out.
Upvotes: 1
Views: 7506
Reputation: 113345
Use only IsFocused
propery:
public void updateValue()
{
if((!tb.IsFocused) || (tb.IsFocused == false))
{
tb.Text = "The text was updated when I wasn't focused. Is't OK?";
}
}
Upvotes: 0
Reputation: 16
maybe you could take a bool value which tells you if the TB is focused or not:
bool TBIsFocused = false;
private void valueTB_Enter(object sender, EventArgs e)
{
TBIsFocused = true;
}
private void valueTB_Leave(object sender, EventArgs e)
{
TBIsFocused = false;
}
Upvotes: 0
Reputation: 180
the problem is that IsFocused
event gets fired only once when it gets the focus thats it and then it doesn't fire. I think you want it to fire this event continuous till Textbox
has the focus. For that you have to keep on checking whether it has the focus or not at specific interval.
Upvotes: 0