I put that code on a button_click event in a UserControl that I made.
It is supposed to work as a boolean. eg if the value is 1 then it should change it to 0
else if the value is 0 it should change it to 1.
The click event is not going to work for this. Click is fired after the button is pushed AND released.
Similar code has to be called by the MouseDown, MouseUp, KeyDown and KeyUp handlers. The xDown events fire when the button is pushed down and the mouse or key is still being held down. The xUp events fire when the mouse or key is released.
before selecting another event to let your code,
make a breakpoint after bottun_click() line,run your control in dubug mode check if
break point stop your program,therefore event has no problem,then check your condition state.
If you mean the Button1 handler should modify the Button1 text, then I see no problem, that works just fine. Mind you, you will see the results only after the Click handler has finished (unless you add a call to Refresh). So changing the text initially, performing a long operation, then changing the text back to its original, all in the one Click handler, will not show any change at all. But then, you shouldn't be doing long operations inside a handler on the GUI thread to begin with... Threads (and BackgroundWorkers) were invented to decouple long operations from the GUI thread.
Then you are doing something wrong. Maybe you have more than one Button1 in your project, and you're talking to the wrong one (it helps to use meaningful names). Maybe its initial text isn't neither "0" nor "1". Maybe ...
You will need to provide a more comprehensive description of what you have if you want to get more effective help around here.
Sorry, I am not going to download, unpack, and investigate a bunch of code, and neither would anyone else around here. If you want effective help, put some effort in describing the problem properly and provide the relevant pieces of code (inside your message, and using PRE tags), not just all of it.
I have no idea what you're doing wrong because this works fine. I wiped up this little example in about a minute:
Private Sub TestButton_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles TestButton.MouseDown
Private Sub TestButton_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles TestButton.MouseUp
Private Sub ChangeButtonText(ByRef target As Button)
If target.Text = "0" Then
target.Text = "1"
target.Text = "0"
If you want the button to change text like a toggle, just remove the MouseUp handler.
Truthfully, I'd be creating my own button control to wrap this functionality and overriding the OnMouseDown and OnMouseUp methods to do this. I wouldn't be doing it using event handlers.
But, since this method is easier to understand, here you go...
Dear ammar ahmad
there was no user control name usercontrol1 in your solution.
I saw your coding,you are more expert than me.
I didnt run your program at all.
Would you please tell me what this code is for?
if your using that button thing in a sub/background thread then add the above sub and try calling it after the button event is done. be aware that this isn't good code and will enforce a full refresh of your screen, its a nice way to test tough.