Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Anybody Tell Me.What is the (Focus) code in vb.net?i want to know about meaning of (Focus) Code in Vb.net.Please Help Me?
Posted
Comments
thatraja 26-Nov-13 10:54am    
(Focus) code? what?
Anupama Rhiyas 26-Nov-13 11:00am    
textbox1.focus()"what is this meaning"

1 solution

The word "Focus" means that a particular control (e.g. a textbox) is in focus or not. When a user clicks on/in a control like textbox then this control gets all the input (through the keyboard) from the user. When a user presses the TAB button on the keyboard like we do all the time filling up the forms on the internet or in a desktop application the FOCUS moves from one control to the next one. The textbox.focus methos simply does this programatically for us. Suppose you've created a desktop application in VB.NET in which the user can register itself, and when filling up the form he/she accidentally forgets to enter his/her email address and clicks on the submit button, what will you do to notify him/her about that. The following code will do...

VB
Private Sub btnSubmit_Click(object as sender, e as EventArgs) handles btnSubmit.clik
if txtEmail.text.trim.lenght=0 then
msgbox("Please enter your email address and try again.")
txtEmail.Focus()
exit sub
end if
'rest of the validation goes here
End Sub


now in the above code we've checked the lenght of the email address the user has provided and if the length is 0 the we've alerted the user via the MsgBox and the txtEmail.Focus will activate the txtEmail textbox for the user automatically.

Hope this will help.
 
Share this answer
 
Comments
Anupama Rhiyas 26-Nov-13 11:36am    
Hmm.thank you agian martene.i undustand to how to do it?
CHill60 26-Nov-13 18:14pm    
My 5. Succinct but clear explanation.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900