在MFC中集成RAD .NET框架

豆豆网   技术应用频道   2007年06月21日  【字号: 收藏本文

内容摘要:关于是MFC还是.NET的讨论时隐时现,不绝于耳。CLR是个充满魅力的世界,这种魅力,使得C#、VB.NET等变得光彩夺目。然而,MFC并没有衰老,如果你深入的了解MFC,你会发现,MFC完全可以与C#、VB.NET争奇斗艳……

#pragma once
...
namespace test
{
  public __gc class testControl :
    public System::Windows::Forms::UserControl
  {
  public:
    testControl(void)
    {
      InitializeComponent();
    }
  protected:
    void Dispose(Boolean disposing)
    {
      if(disposing && components)
        components->Dispose();
      __super::Dispose(disposing);
    }
  private:
    System::Windows::Forms::Label *label1;
    System::ComponentModel::Container
      *components;
    void InitializeComponent(void)
    {
      this->label1 = new
        System::Windows::Forms::Label();
      this->SuspendLayout();
      this->label1->Location =
        System::Drawing::Point(16, 24);
      this->label1->Name = S"label1";
      this->label1->Size =
        System::Drawing::Size(208, 16);
      this->label1->TabIndex = 0;
      this->label1->Text =
        S"Welcome to TZ MFC.NET!";
      this->Controls->Add(this->label1);
      this->Name = S"testControl";
      this->Size =
        System::Drawing::Size(240, 160);
      this->ResumeLayout(false);
    }
  };
}

  注意,testControl类继承自UserControl类,用户控件是开发者创建的任何控件,您可以将多个.NET控件组织在一起,添加功能代码,然后把它作为一个更综合一些的控件来使用,使用每一个用户控件和使用其他的.NET标准控件的步骤都是没有区别的。在上面的代码中,我们自定义的用户控件仅包含了一个.NET Label控件。

来源:microsoft    作者:孙辉    责编:豆豆技术应用

正在加载评论...