c# - Position Gtk# Dialog in the center of a Gtk window -


im trying position gtk# dialog in center of window,also make parent window non editable when dialog appears. tried setting parent property , of dialog , set it's position center on parent.(the parent windows position centered,the parent appers centered portion of below taskbar)

what im doing wrong?

update:

i tried setting transcientfor property.

        mywin d = new mywin();         d.parent = this;         d.windowposition = windowposition.centeronparent;          d.transientfor = this;          d.widthrequest = 360;         d.heightrequest =260;         d.resizable = false;          d.show ();  

also error in application output when

(myapp:5844): gtk-warning **: can't set parent on toplevel widget  (myapp:5844): gdk-critical **: inner_clipboard_window_procedure: assertion 'success' failed 

update: calling dialog parent

protected void onbutton7clicked (object sender, eventargs e)     {             var mydiag = new mydiag( );              if ( ( (gtk.responsetype) mydiag.run() ) == gtk.responsetype.ok ) {                 // whatever here...             }      } 

dialog code

using system;  namespace myproj {     public partial class mydiag : gtk.dialog     {         public mydiag (gtk.window parent)         {             this.build ();             this.title = parent.title + " more info";             this.icon = parent.icon;             this.parent = parent;             this.transientfor = parent;             this.setposition( gtk.windowposition.centeronparent );             this.showall();         }     } } 

the problem being reported here:

(myapp:5844): gtk-warning **: can't set parent on toplevel widget 

your mywin class not gtk.dialog, gtk.window. should create main window way:

namespace whatever {     public class mainwindow: gtk.window {         public mainwindow()             : base( gtk.windowtype.toplevel )         {             this.title = "gtk# app";             this.build();         }          private void build() {             // create widgets         }          // more things... } 

suppose need open dialog function in app.

namespace whatever {     public class mainwindow: gtk.window {         // ...more things         private void onwhatever() {             var dlg = new dlgmoreinfo( );              if ( ( (gtk.responsetype) dlg.run() ) == gtk.responsetype.ok ) {                 // whatever here...             }              dlg.destroy();         }     } } 

finally, need create dialog dlgmoreinfo centered, etc.

namespace whatever {     public class dlgmoreinfo : gtk.dialog {         public dlgmoreinfo(gtk.window parent) {             this.build();              this.title = parent.title + " more info";             this.icon = parent.icon;             this.transientfor = parent;             this.setposition( gtk.windowposition.centeronparent );             this.showall();         }          private void build() {             // create widgets here...             // buttons             this.addbutton( gtk.stock.cancel, gtk.responsetype.cancel );             this.addbutton( gtk.stock.ok, gtk.responsetype.ok );             this.defaultresponse = gtk.responsetype.ok;         }     } } 

you can create dialogs childs of top level window; never window can child of one.

note code not use designer of xamarin studio. if use designer, call hideall() before showall(), if need use widgets, or move call build() after call setposition().

hope helps.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -