1. 命名空间引用方法
C# 通过 命名空间后跟"."来引用.
C++.NET 通过命名空间后跟"::"来引用
如: (c#)System.Data . (c++.net) System::Data
2.生成一个窗体的实例并显示出来
c++.net:
//通过指针操作
frmAbout* frm = new frmAbout();
frm->ShowDialog(this);
C#:
frmAbout frm = new frmAbout(); //生成对象的实例
frm.ShowDialog(this);
3.程序的入口点
c++.net
一个应用程序必须而且只能有一个CWinApp派生类的对象,并且只能由该对象来调
用WinMain()函数。这也对应着一个应用程序只有一个惟一的入口.
如:
[System::STAThreadAttribute]
void __stdcall WinMain()
{
Application::Run(new frmLogin());
}
WinMain函数在调用InitInstance进行初始化完毕后,就调用函数处理消息循环。
Run函数作为一个循环函数,主要进行消息的处理:Run函数不断地查询应用程序的消
息队列,一旦有消息出现就将其发回给Windows,并由Windows再来调用处理该消息的窗口
函数,而窗口则是隐藏在应用程序框架类内部的。当消息队列中没有消息时(大多数的时
候是这种情况),Run函数就会调用OnIdle函数,从而做一些应用程序框架类或用户在程序
空闲时所要做的工作。
如果既没有消息又没有空闲工作要做,那么应用程序就一直处于等待状态.
当应用程序关闭时,Run函数就会调用ExitInstance函数,做一些退出前的处理工作.
C#也如此
如:
// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new frmLogin());
}
4.设置(或获取)窗体和相关组件的属性
(下面的实例均基于相同的命名空间)
c++.net
this->BackColor =System::Drawing::Color::Gold ;
this->textBox1->Text =this->BackColor.ToString();
this->pictureBox1->BackColor =System::Drawing::Color::Red ;
C#
this.BackColor=System.Drawing.Color.Gold; //获取或设置本窗体的属性用 this.
this.textBox1.Text =this.BackColor.ToString();
Form2 frm2=new Form2();
frm2.BackColor=System.Drawing.Color.Gold; //获取或设置新实例窗体的属性用 新实例名.
frm2.ShowDialog(this) ;
frm2.Close();
this.pictureBox1.BackColor = System.Drawing.Color.Red ;