[Mono-winforms-list] Some basic questions on Winforms.

Wei Weng wweng@kencast.com
Wed, 13 Apr 2005 12:02:12 -0400

This is a multi-part message in MIME format.
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Jordi Mas wrote:
>>2: How do I bind a shortcut key to an action/function without using the
>>setting the shortcut key in MainMenu/ContextMenu? (Can not set menu in my 
>>current mono setup either. Always complains about set_Menu method, throwing 
>>a NullReferenceException)
> Hello Wei,
> Can you provide a small sample that reproduces this problem?
> Thanks!

I have attached the small sample to this email. The environment is mono 
1.1.6, OSX 10.3. I could mono the same program on fedora 2, however, the 
menu never really showed.

The error message I got is:

[wweng@NEWTON TestMono]$ mono Test.exe
Mono System.Windows.Forms Assembly [Revision: 41731; built: 2005/2/15 5:56:12]
Keyboard: United States keyboard layout (phantom key version)

Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object
in <0x0007c> System.Windows.Forms.Form:set_Menu (System.Windows.Forms.MainMenu)
in <0x00084> (wrapper remoting-invoke-with-check) System.Windows.Forms.Form:set_
Menu (System.Windows.Forms.MainMenu)
in <0x000d8> Form1:InitializeComponent ()
in <0x0006c> (wrapper remoting-invoke-with-check) Form1:InitializeComponent ()
in <0x00024> Form1:.ctor ()
in <0x00048> (wrapper remoting-invoke-with-check) Form1:.ctor ()
in <0x0002c> Form1:Main ()

Content-Type: text/plain;
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

public class Form1 : System.Windows.Forms.Form
	private System.ComponentModel.Container components = null;

	public Form1()

	protected override void Dispose( bool disposing )
		if( disposing )
			if (components != null) 
		base.Dispose( disposing );

	private void InitializeComponent()
		MainMenu mBar = new MainMenu();

		MenuItem item1 = new MenuItem();

		item1.Text = "File";


		this.Menu = mBar;
		// Form1
		this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
		this.ClientSize = new System.Drawing.Size(316, 214);
		this.Name = "Form1";
		this.Text = "Form1";


	static void Main() 
		Application.Run(new Form1());