Example Invokation with System.Windows.Form on GTK Window as Win32Windows?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

Example Invokation with System.Windows.Form on GTK Window as Win32Windows?

This post has NOT been accepted by the mailing list yet.
Hello i am new here thanks for welcome.

I am really happy because I don't need to worry with Build() from generated Build.cs.
I am using with Visual Studio 2017 Community and I have no problem yet.
I really want understand how does Application.Invoke work if unsupported sub-framework example
Main core is GTK Sharp and sub-framework is System.Windows.Forms. You know about macOS users don't like GTKFileChooseDialog and they want use "native" NSOpenPanel or NSSavePanel. It is very easy to invoke with GTK.Application.Invoke(delegate { ... });

That is really nice. I know how does it work with WinForms version like it.
And I really want show you for example with GTKSharp  framework under Visual Studio 2017 Community. I don't need to install Xamarin or MonoDevelop. You know same reference by Unity3D and it works same to Visual Studio 2017 Community. That is why it works like same crossplatform :)
It is Visual Studio 2017 and GTKSharp
How do you know create project without Winforms. Just create easy ConsoleApplication project than you can change proprety "ConsoleApplication" to "WindowApplication" and add references from Mono/lib/<XXX>/<xxx>.dll to reference's project. and I don't need to write "Build():" Because It is nothing because Build class was generated by MonoDevelop or Xamarin. Just I don't need it.

I have written in C#:
Program.cs for example:
using System;
using Gtk;

namespace MyGtk
    class Program
        static MainWindow win;

        static void Main(string[] args)
            win = new MainWindow();

            VBox myV01 = new VBox(false, 3);
            HBox myH01 = new HBox(false, 3);
            myV01.PackStart(myH01, false, true, 10);
            Button myBtn01 = new Button();
            myBtn01.Label = "Show native messagebox!";
            myH01.PackStart(myBtn01, false, true, 10);
            myBtn01.Clicked += new EventHandler(myBtn01Handler);

            Button myBtn02 = new Button();
            myBtn02.Label = "Show MessageBox from GTK#!";
            myH01.PackStart(myBtn02, false, true, 10);
            myBtn02.Clicked += new EventHandler(myBtn02Handler);

        protected static void myBtn01Handler(object sender, EventArgs e)
            Application.Invoke(delegate {
                System.Windows.Forms.MessageBox.Show("Hello It is native MessageBox from WinForm invoking to GtkSharp Application.", "Winfo0rm Messagebox");

        protected static void myBtn02Handler(object sender, EventArgs e)
            MessageDialog md = new MessageDialog(win, DialogFlags.Modal, MessageType.Other, ButtonsType.Ok, "Hello it is gtksharp messagedialog");
            md.Title = "GTKsharp MessageDialog";

And MainWindow.cs:
using System;
using Gtk;

namespace MyGtk
    public partial class MainWindow : Window
        public MainWindow() : base(WindowType.Toplevel)
            SetDefaultSize(400, 300);
            DeleteEvent += delegate { Application.Quit(); };
            Title = "Hello Gtk by Visual Studio 2017";

Why I ask that. I wish System.Windows.Forms.MessageBox(win.ownerhandle, "Message", "Title");
If System.Windows.Forms should catch to GTK Window's instance / parent.
If you see MessageDialog of GTKSharp was openned and posits to center of GTKSharp applicatioon.
And MessageBox doesn't catch from GTKSharp window and it just opens outside of GTKSharp application.

How do I fix? Thanks. Win32Window is hard to understand for GTKSharp.