im doing a complex calculator in C#. the first textbox accepts the real part and the second accepts the immaginary part. i wanna be able to use the mouse to enter values also. so if i click button1 it will concat "1" to the value in the textbox on which the focus is on . i cant determine which textbox is focused. i tried the stuff some people posted, like using GotFocus for exemple, and non had worked..
private Control focusedControl;
private void TextBox_GotFocus(object sender, EventArgs e)
{
focusedControl = (Control)sender;
}
private void button1_Click(object sender, EventArgs e)
{
if (focusedControl != null)
{
focusedControl.Focus();
SendKeys.Send("1");
}
}
if ((txtBox as Control).Focused)
{
}
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