Click here to Skip to main content
15,906,947 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i recently started learning coding in c#. doing a project i want to perform a functionality when a user clicks on the textbox. That is i want to change the TextChanged event to Click Event.

What I have tried:

when i checked the net for a solution they suggested changing the event feature on properties. The thing is i dont have the event feature or the click feature on the properties of the text box.

pls can i be provided with a solution to this problem?
Posted
Updated 2-Jul-20 20:12pm

1 solution

You probably do, unless you are writing a website, and the textbox is hand coded to a Javascript event.
If so, you will have HTML code either like this:
HTML
<input type="text" id="fname" onchange="myFunction()">

Or like this
HTML
:<input type="text" id="fname">
<script>
document.getElementById("fname").onchange = function() {myFunction()};
...

That's pretty simple to deal with: change "onchange" to "onclick"

If it's a Windows app, then it's even simpler: highlight the TextBox in the VS designer, and look at the Properties Pane (not the Project "Properties" , it's a separate display pane you can open via the View menu if it isn't displayed already).
It looks something like this: https://i.stack.imgur.com/qWydN.png[^]
Click the "Lightning bolt" and it will change from the Properties to the Events:
https://docs.microsoft.com/en-us/visualstudio/ide/media/express_labelclick.png?view=vs-2019[^]
Double click the Click event and it will create a handler for you - you can now call the same code you executed from the TextChanged event (or cut'n'paste from your existing handler).
 
Share this answer
 

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