using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace ManualFormClass
{
static class Program
{
//应用程序的主入口点
[STAThread]
static void Main ()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MyClass());
}
}
class MyClass : Form
{
//构造函数
public MyClass()
{
Text = "MyClass";
Height = 320;
Width = 480;
Cursor = Cursors.Cross;
BackColor = Color.Blue;
MouseClick += new MouseEventHandler(MyClass_MouseClick);
}
//按键判断
void MyClass_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Text = "左键" + e.Location;
}
else if (e.Button == MouseButtons.Right)
{
Text = "右键" + e.Location;
}
else
{
Text = "其他按键" + e.Location;
}
}
}
}
1:把上面代码保存在F盘MyNet文件夹下,保存成*.cs格式如MouseClick.cs。
2:打开SDK命令提示如下图,用cd命令切换到程序所保存的路径下。
3:用csc命令编译文件,如csc MouseClick.cs回车,编译成功在F盘MyNet文件夹下生成一个MouseClick.exe执行文件。
4:运行执行文件MouseClick.exe,直接输入执行文件的名称,如下图所示:F:/MyNet> MouseClick.exe回车。