How to check focused TextBox in vb.net winforms? -


i have multiple textbox in form. how know textbox cursor is? trying this:

if textbox2.focus() = true             messagebox.show("its in two")         elseif textbox3.focus = true             messagebox.show("its in three")         end if 

but think not working.

obviously, not work if calling code in button_click because when click button focus goes button have clicked.

you can 2 things:

make combined focus event textboxes , check sender object.

private sub textbox_focus(byval sender system.object, byval e system.eventargs) handles textbox2.enter, textbox3.enter     dim currtextbox textbox = sender      if currtextbox.equals(textbox2)         messagebox.show("it's in two")     elseif currtextbox.equals(textbox3)         messagebox.show("it's in three")     end if  end sub 

or

take global string variable, , set value @ each textbox_focus event, check string value in button click event.

 dim str string    private sub textbox2_focus(byval sender system.object, byval e system.eventargs)  handles textbox2.enter      str = "two"  end sub   private sub textbox3_focus(byval sender system.object, byval e system.eventargs)  handles textbox3.enter      str = "three"  end sub   private sub button1_click(byval sender system.object, byval e system.eventargs)  handles button1.click       messagebox.show("it's in " & str)  end sub 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -