Use bitmapButton with mouseEvent?

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
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. how can I solve it?

Pat K. wrote:

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

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

thank you it work! :smiley:

Minor change
http://wxruby.rubyforge.org/doc/bitmapbutton.html#BitmapButton_setbitmapselected

BitmapButton#set_bitmap_disable()http://wxruby.rubyforge.org/doc/bitmapbutton.html#BitmapButton_setbitmapdisable

Should be:

BitmapButton#set_bitmap_disabled()http://wxruby.rubyforge.org/doc/bitmapbutton.html#BitmapButton_setbitmapdisabled

My mistake.

L8ers

Hello Pat,

On Sat, Apr 19, 2008 at 12:36 AM, Pat K.
[email protected]
wrote:

def evtmouse2(event)
#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. how can I solve it?

Another, easier way to implement this type of functionality, is to use
the
following given methods:

BitmapButton#set_bitmap_focus()http://wxruby.rubyforge.org/doc/bitmapbutton.html#BitmapButton_setbitmapfocus
BitmapButton#set_bitmap_hover()http://wxruby.rubyforge.org/doc/bitmapbutton.html#BitmapButton_setbitmaphover
BitmapButton#set_bitmap_selected()http://wxruby.rubyforge.org/doc/bitmapbutton.html#BitmapButton_setbitmapselected
BitmapButton#set_bitmap_disable()http://wxruby.rubyforge.org/doc/bitmapbutton.html#BitmapButton_setbitmapdisable

Though, the way you have now, gives you an idea of how to do things,
this
sort of thing is already implemented, just so ya know. :wink:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs