[wxruby-users] use bitmapButton with mouseEvent?

Alex Fenton alex at pressure.to
Sat Apr 19 09:33:06 EDT 2008


Pat Kiatchaipipat wrote:
> hi. I want to make button that can change picture when mouse is entering
> and can click to use function. and this is my code.
>
>
>     @button2 = BitmapButton.new(@window, -1, @picturebox1_bmp,
> Point.new(248,89),       Size.new(53, 53))
>     @button2.evt_mouse_events{ |event| evtmouse2(event) }
>     evt_button(@button2.get_id()) { |event| evtbtn2()}
>
>
>     def evtmouse2(event)
>       if event.entering == true
>         @button2.set_bitmap_label(@picturebox2_bmp)
>       end
>       if event.leaving == true
>         @button2.set_bitmap_label(@picturebox1_bmp)
>       end
>   
Add 'event.skip' here
>     end
>
>
>     def evtbtn2()
>       #mycode
>     end
>
> It work normally when I use mouse enter the button it can change
> picture. but when I click on it. it can't use evtbtn2. what I doing
> wrong?? I try to use event.left_down to capture when mouse was clicked.
> It work but the button show was not pushed.
>   
This is a common gotcha with event handling. The explanation is here:
http://wxruby.rubyforge.org/doc/event.html#Event_skip

a




More information about the wxruby-users mailing list