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? -- Posted via http://www.ruby-forum.com/.
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
thank you it work! :D -- Posted via http://www.ruby-forum.com/.
Hello Pat, On Sat, Apr 19, 2008 at 12:36 AM, Pat Kiatchaipipat <lists at ruby-forum.com> 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 > 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? > --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. ;-) -- Mario Steele http://www.trilake.net http://www.ruby-im.net http://rubyforge.org/projects/wxruby/ http://rubyforge.org/projects/wxride/ http://rubyforge.org/projects/vwmc/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/wxruby-users/attachments/20080419/1a78b126/attachment.html
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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/wxruby-users/attachments/20080419/e85834b9/attachment-0001.html