Re: How to programmatically invoke Click event of the Button ?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Fri, 24 Mar 2006 09:57:54 +0500, Oleg Subachev wrote:

You can use the PerformClick() function.

And what if I need to invoke another event ?
Or if I need to invoke an event of Label class ?

That of course won't work then. But your question was "How to
programmatically invoke Click event of the Button ?". I'm sorry but I don't
have yet the ability to read into usenet's users mind (but i'm working on
it).

As for your new question, wrapping the OnEvent() methods may be a solution
of course but it sounds like you are mixing a bit to much the UI code with
the application logic which ultimately tends to make the code difficult to
read and maintain. Much better in my opinion would be to clearly separate
those 2 layers. E.g., if you have a button "Take Order", then this button's
click event handler should call the TakeOrder() method. If you need to take
an order programmatically, you can call TakeOrder() instead of calling the
button's event handler. If the event handler of the button changes, this
shouldn't affect the rest of the application logic. Your code should be
able to determine what function to call at any time rather than blindly
calling the button's event handler hoping that it's gonna do the right
thing.

I think the best way is to put corresponding protected
On<Event> method into the public wrapper.
[...]
I can't do this because Button's click event may contain different handlers
during execution of my application.

What would happen if later you decided to modify your UI and use 2 separate
buttons instead a single button with changing event handlers? If your code
was just calling your button's OnClick() method to do what the button was
supposed to do, you would have to go through all your code and try to find
out for each OnClick() call what you really wanted to do by calling
OnClick(). Plus i don't want to think of how difficult to read your code
would be to another programmer with OnClick() calls of a button which click
event handlers keep changing during the execution of the program.
.



Relevant Pages

  • Re: Async callback vs events vs ?
    ... This seems to make life complicated and dangerous since there is still a lot I need to do with the information returned including updating the GUI, calling more methods, ... ... The only thing you probably need to really fix is the lack of a call to Control.Invokein your event handler. ... just pass your delegate instance as the state object to the call to BeginInvoke, and then retrieve that from the IAsyncResult.AsyncState property. ... The call to Control.Invoke() does the exact same check, and will simply invoke the delegate directly if InvokeRequired is false. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Trouble with DeselectAll()
    ... DoCmdbehaves exactly like calling DeselectAll(), ... Calling DoCmdtwice also works. ... from an event handler seems to be what is broken. ...
    (microsoft.public.visio.developer)
  • Re: Button click - form update?
    ... Use Google Groups and search this newsgroup for BackgroundWorker and/or Invoke or read the MSDN documentation. ... Within the DoWork event handler, you can either just use the built-in progress reporting and let the event handler for that update the form controls, no Invoke() required, or you can call Invokefrom the DoWork event handler itself and update the form controls that way. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Spanning thread in WS Async Call
    ... I am calling a web service asynchronously as follows ... I want to span thread here to do some operation on the the result data and ... Why don't you do your processing within the event handler? ... John Saunders | MVP – Windows Server System – Connected System Developer ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: Serialport question
    ... OpenNETCF's won't help as the event handler also runs in a worker thread. ... You'll still have to use Invoke. ... SerialDataReceivedEventArgs) Handles prt.DataReceived ... Private Sub Button1_Click(ByVal sender As System.Object, ...
    (microsoft.public.dotnet.framework.compactframework)