# Wxruby messagedialog box

**URL:** <https://www.ruby-forum.com/t/wxruby-messagedialog-box/192249>\
**Category:** wxRuby\
**Created:** [July 27, 2010, 12:27am UTC](https://www.ruby-forum.com/t/wxruby-messagedialog-box/192249 "2010-07-27T00:27:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bruce\_Loving](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/74df32/32.png) [@Bruce\_Loving](https://www.ruby-forum.com/u/Bruce_Loving)\
**Post date:** [July 27, 2010, 12:27am UTC](https://www.ruby-forum.com/t/wxruby-messagedialog-box/192249/1 "2010-07-27T00:27:38Z")

</div>

any way to keep a dialog box inside its parent, instead of centered on  
the  
screen?  
require ‘rubygems’  
require ‘wx’  
include Wx

class MyFrame \< Frame  
def initialize()  
super(nil,-1,‘Wristband Manager’,:size =\> [400,600])  
@my\_panel = Panel.new(self)  
@mybutton = Button.new(self,-1,‘click’)  
evt\_button(@mybutton) {onclick}  
show

end

def onclick  
diagYesno = MessageDialog.new(self,‘are you sure’,‘Process  
Request’,YES\_NO)  
case diagYesno.show\_modal  
when Wx::ID\_YES  
yesno = ‘Yes’  
when Wx::ID\_NO  
yesno = ‘No’  
end  
puts yesno  
end

end

class MyApp \< App  
def on\_init  
frame1 = MyFrame.new

```
end

```

end

### Main Logic

MyApp.new.main\_loop()

---

<div class="post-metadata">

**Author:** ![Bruce\_Loving](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/74df32/32.png) [@Bruce\_Loving](https://www.ruby-forum.com/u/Bruce_Loving)\
**Post date:** [July 27, 2010, 12:39am UTC](https://www.ruby-forum.com/t/wxruby-messagedialog-box/192249/2 "2010-07-27T00:39:56Z")

</div>

hi

On 26/07/2010 23:07, Bruce Loving wrote:

> any way to keep a dialog box inside its parent, instead of centered on  
> the screen?

Try calling centre\_on\_parent() - or center\_on\_parent(), if you’re that  
way inclined

Dialog inherits this method from Wx::Window

cheers  
alex

---

<div class="post-metadata">

**Author:** ![Bruce\_Loving](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/74df32/32.png) [@Bruce\_Loving](https://www.ruby-forum.com/u/Bruce_Loving)\
**Post date:** [July 27, 2010, 1:31pm UTC](https://www.ruby-forum.com/t/wxruby-messagedialog-box/192249/3 "2010-07-27T13:31:58Z")

</div>

You will need to do this, before you call show\_modal, as show\_modal will  
open the dialog, and wait for a User Response, before returning control  
back  
to your program, so just after the creation of your Dialog Object, you  
would  
call #centre\_on\_parent() or #center\_on\_parent().

---

<div class="post-metadata">

**Author:** ![Bruce\_Loving](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/74df32/32.png) [@Bruce\_Loving](https://www.ruby-forum.com/u/Bruce_Loving)\
**Post date:** [July 27, 2010, 4:11pm UTC](https://www.ruby-forum.com/t/wxruby-messagedialog-box/192249/4 "2010-07-27T16:11:47Z")

</div>

hm, ok, read the docs, but it still doesnt center on parent  
also, how come button fills whole frame?

require ‘rubygems’  
require ‘wx’  
include Wx

class MyFrame \< Frame  
def initialize()  
super(nil,-1,‘The Rabbit Hole’,:size =\> [300,300])  
@diagYesno = MessageDialog.new(self,‘are you sure’,‘White Rabbit  
asks’,YES\_NO)  
@diagYesno.center\_on\_parent(BOTH)  
#@my\_panel = Panel.new(self)  
@mybutton = Button.new(self,-1,‘Drink Me’,:pos =\>[2,2],:size =\>  
[30,20])  
evt\_button(@mybutton) {onclick}  
show  
end

def onclick

case @diagYesno.show\_modal  
when Wx::ID\_YES  
yesno = ‘Yes’  
when Wx::ID\_NO  
yesno = ‘No’  
end  
puts yesno  
end

end

class MyApp \< App  
def on\_init  
frame1 = MyFrame.new

```
end

```

end

### Main Logic

MyApp.new.main\_loop()
