I am wondering if anyone can help me I am new to GTK# and MonoDevelop and I can not seem to figure out how to place a splash window in front of another window. When the splash window loads it is positioned to right hand side of the screen where the main window is positioned in the center and I want both of them to be center. I have used to use the GUI builder and have made sure that both have a position of center in the Designer->Properties
Main Window
public partial class MainWindow: Gtk.Window
{
public MainWindow () : base (Gtk.WindowType.Toplevel)
{
Build ();
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
}
Splash screen window
public partial class SplashScreenWindow : Gtk.Window
{
public SplashScreenWindow () :
base (Gtk.WindowType.Toplevel)
{
this.Build ();
}
}
Main To show and Hide the splash window
public static void Main (string[] args)
{
Application.Init ();
SplashScreenWindow s = new SplashScreenWindow ();
s.Title = @"I am a Splash Screen";
MainWindow win = new MainWindow ( );
System.Threading.Thread.Sleep (1000);
win.Title = @"I am a Menu";
win.Visible = false;
s.Show ();
s.Visible = false;
s.Dispose ();
win.Show ();
Application.Run ();
}
}
Get the size (width/height) of your primary screen via GdkWindow.Screen
and perform a Move
on the window adjusting the move by its half of its size.
MainWindow win = new MainWindow();
var screen = win.GdkWindow.Screen;
win.GdkWindow.GetSize(out var winWidth, out var winHeight);
win.Move((screen.Width / 2) - (winWidth / 2), (screen.Height / 2) - (winHeight / 2));
Application.Run();
win.Show();