Code:
using System;
using System.Windows.Forms;
namespace prog
{
public class HandDrawnClass : Form
{
private System.Windows.Forms.Label lblOutput;
private System.Windows.Forms.Button btnCancel;
public HandDrawnClass( )
{
this.lblOutput = new System.Windows.Forms.Label ( );
this.btnCancel = new System.Windows.Forms.Button ( );
this.Text = "Hello World";
lblOutput.Location = new System.Drawing.Point (16, 24);
lblOutput.Text = "Hello World!";
lblOutput.Size = new System.Drawing.Size (216, 24);
btnCancel.Location = new System.Drawing.Point (150,200);
btnCancel.Size = new System.Drawing.Size (112, 32);
btnCancel.Text = "&Cancel";
btnCancel.Click += new System.EventHandler (this.btnCancel_Click);
this.AutoScaleBaseSize = new System.Drawing.Size (5, 13);
this.ClientSize = new System.Drawing.Size (300, 300);
this.Controls.Add (this.btnCancel);
this.Controls.Add (this.lblOutput);
}
protected void btnCancel_Click (object sender, System.EventArgs e)
{
Application.Exit();
}
public static void Main( )
{
Application.Run(new HandDrawnClass( ));
}
}
}
using System;
using System.Windows.Forms;
namespace prog
{
public class HandDrawnClass : Form
{
private System.Windows.Forms.Label lblOutput;
private System.Windows.Forms.Button btnCancel;
public HandDrawnClass( )
{
this.lblOutput = new System.Windows.Forms.Label ( );
this.btnCancel = new System.Windows.Forms.Button ( );
this.Text = "Hello World";
lblOutput.Location = new System.Drawing.Point (16, 24);
lblOutput.Text = "Hello World!";
lblOutput.Size = new System.Drawing.Size (216, 24);
btnCancel.Location = new System.Drawing.Point (150,200);
btnCancel.Size = new System.Drawing.Size (112, 32);
btnCancel.Text = "&Cancel";
btnCancel.Click += new System.EventHandler (this.btnCancel_Click);
this.AutoScaleBaseSize = new System.Drawing.Size (5, 13);
this.ClientSize = new System.Drawing.Size (300, 300);
this.Controls.Add (this.btnCancel);
this.Controls.Add (this.lblOutput);
}
protected void btnCancel_Click (object sender, System.EventArgs e)
{
Application.Exit();
}
public static void Main( )
{
Application.Run(new HandDrawnClass( ));
}
}
}
kada kompjliram sa:
mcs -r:System,System.Windows.Forms,System.Drawing winform.c
mono winform.exe
program se normalno starta, ali nakon sto kliknem na Cancel, forma se zatvori, ali program ostane visiti u konzoli ... zna li netko mozda u cemu je problem ?
konkretno nakon klika mi u konzoli ispise:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
i onda ga moram ubiti sa control-c