vb.net - mousedoubleclick doesnt work for dynamically created button -


in button events mousedoubleclick included when add form when programmatically add buttons form mousedoubleclick doesn't exist in ide suggestion events if write myself program execute without error doesn't on mousedoubleclick event

here code:

dim pb new button pb.text = "hello" pb.size = new size(150, 110) frmaddimage.flpanel.controls.add(pb)  addhandler pb.mousedoubleclick, addressof pbbutton_mousedoubleclick  private sub pbbutton_mousedoubleclick(byval sender object, byval e system.windows.forms.mouseeventargs)     'do end sub 

what boils down following: buttons don't use double-click event. button class inherits control provides double-click event. there it's not fired class.

you can use .clicks property of mouseeventargs variable in mousedown event though:

private sub button3_click(sender object, e eventargs) handles button3.click     dim pb new button     pb.text = "hello"     pb.size = new size(150, 110)     frmaddimage.flpanel.controls.add(pb)     addhandler pb.mousedown, addressof pbbutton_mousedown end sub  private sub pbbutton_mousedown(byval sender object, byval e system.windows.forms.mouseeventargs)     if e.clicks = 2         messagebox.show("the button double-clicked.")     end if end sub 

taken from: http://social.msdn.microsoft.com/forums/en-us/83ac6fbd-af42-4b9c-897e-142abb0a8199/can-not-use-event-double-click-on-button


a workaround enable standardclick , standarddoubleclick controlstyles button. need create own button class , set flags true in constructor. can handle doubleclick (not mousedoubleclick) event.

public class mybutton     inherits button     public sub new()         mybase.new()         setstyle(controlstyles.standarddoubleclick, true)         setstyle(controlstyles.standardclick, true)     end sub end class 

wire event in other class before, create mybutton , not button.

private sub button3_click(sender object, e eventargs) handles button3.click     dim pb new mybutton     pb.text = "hello"     pb.size = new size(150, 110)     me.controls.add(pb)     addhandler pb.doubleclick, addressof pbbutton_doubleclick end sub  private sub pbbutton_doubleclick(byval sender object, byval e system.windows.forms.mouseeventargs)     messagebox.show("the button double-clicked.") end sub 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -