Get the currently focused textbox in C#

前端 未结 2 395
孤城傲影
孤城傲影 2021-01-03 10:57

I have two textboxes, and a button. When I press the button, I want to know where my current caret is (either of the two boxes). I need this to know where to insert a certai

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-03 11:51

    There's a very simple way to do this. Your requirement is simple since you only have two textboxes.

    You can assign a class-wide string variable that holds when textbox1_GotFocus() is invoked as well as textbox2_GotFocus(). So if that textbox GotFocus() is called you assign a value. Then put a condition for the class-wide string variable in the button that if the class-wide variable has a value of thats kind, that textbox is populated whatever you want to put in the textbox.

    It worked for me so I believe it should work on you.

提交回复
热议问题