# Wxruby dialog box, not centering on parent

**URL:** <https://www.ruby-forum.com/t/wxruby-dialog-box-not-centering-on-parent/192405>\
**Category:** Ruby\
**Created:** [July 29, 2010, 5:30pm UTC](https://www.ruby-forum.com/t/wxruby-dialog-box-not-centering-on-parent/192405 "2010-07-29T17:30:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bxling](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/edb3f5/32.png) [@bxling](https://www.ruby-forum.com/u/bxling)\
**Post date:** [July 29, 2010, 5:30pm UTC](https://www.ruby-forum.com/t/wxruby-dialog-box-not-centering-on-parent/192405/1 "2010-07-29T17:30:32Z")

</div>

## Trying to center a messagebox on the parent instead of on whole screen. Read the docs, they say to use #center\_on\_parent before calling \_modal. Doesnt seem to work, any ideas?

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()
