0

When I try to create a form from the mono C# REPL I cant get access to System.Windows.Forms classes

I can use other .net libraries from REPL with no problem.

Any thoughts?

ZEE
  • 2,931
  • 5
  • 35
  • 47

1 Answers1

1

You can use LoadAssembly and LoadPackage as needed inside of the REPL:

  • LoadAssembly (string): Loads the given assembly, equivalent to passing the -r:NAME to the compiler.
  • LoadPackage(string): Loads the given package, equivalent to passing the -pkg:NAME to the compiler.

Example:

csharp> LoadAssembly("System.Windows.Forms")
csharp> using System.Windows.Forms
csharp> LoadAssembly("System.Drawing")
csharp> using System.Drawing
csharp> class MyApp : System.Windows.Forms.Form
    {
        public MyApp()
        {
            Label label;

            ClientSize = new System.Drawing.Size(250, 250);

            label = new Label();
            label.Text = "A Mono CSharp REPL Window";
            label.Dock = DockStyle.Fill;
            label.TextAlign = ContentAlignment.MiddleCenter;
            this.Controls.Add(label);
            Text = "Hello, StackOverFlow";
        }

        public static void Main()
        {
            Application.Run(new MyApp());
        }
    }
MyApp.Main()

FYI: If you are trying to generate dynamic GUIs, I would look at gsharp (from mono-tools) since it has a GTK pane and you can add/remove widgets to that pane.

SushiHangover
  • 73,120
  • 10
  • 106
  • 165
  • You mention gsharp... Where can I download a Windows version (preference for binaries)... – ZEE Jul 11 '15 at 12:32
  • I do not know of bin installers for mono-tools. You can grab the official source: https://github.com/mono/mono-tools/tree/master/gsharp Note: On windows you need to have installed GTK# for .Net : http://www.mono-project.com/download/#download-win – SushiHangover Jul 11 '15 at 14:00
  • FYI, If you have problems, I can post the exe somewhere. – SushiHangover Jul 11 '15 at 14:20
  • thanx... I'd already try to compile GTK# inside Cygwin but ran into problems (in Linux everything runs OK)... http://stackoverflow.com/questions/31196554/compile-gtk-2-99-3-in-cygwin-unknown-types-uid-t-and-pid-t – ZEE Jul 11 '15 at 19:39
  • OK, so did you just use the GTK# 4 .net installer instead of compiling it? Running gsharp now? – SushiHangover Jul 11 '15 at 20:46
  • Yes, I installed GTK# 2.12.26 binaries (.msi) in windows and it works ok inside visual studio or command line... but i wanted to compile and run gtk# native inside cygwin,,, so I try to compile gtk# source inside cygwin.. same process I used to compile mono inside cygwin... but gtk# cant finalize compilation... it always stop with the errors I describe in here... http://stackoverflow.com/questions/31196554/compile-gtk-2-99-3-in-cygwin-unknown-types-uid-t-and-pid-t – ZEE Jul 13 '15 at 18:40