您的位置:首页 > 编程语言 > C语言/C++

Visual C++ 2005 系列课程学习笔记-5

2008-09-04 03:30 531 查看
Visual C++ 2005与Visual C#的对比(Visual C++2005中的组件成员)

Visual C++ 2005:

Ref class MyClass

{

private:

int x;

public:

property int X //组件成员:属性

{

int get()

{

return x;

}

void set(int value)

{

x = value;

}

}

};

public delegate void EventHandler(Object^ sender,EventArgs^ e) //委托

ref class button

{

public:

event EventHandler^ Click; //组件成员:事件

}

public ref class Form1

{

Button^ Button1;

void Button1_Click(Object^ sender,EventArgs^ e)

{

////////////////

}

public:

Form1()

{

Button1 = gcnew Button;

Button1->Click += gcnew EventHandler(this,&Button1_Click); //组件成员:使用事件

}

}

Visual C#:

class MyClass

{

private int x;

public int X // 属性

{

get

{

return x;

}

set

{

x = value;

}

}

};

public delegate void EventHandler(Object sender,EventArgs e) //委托

class button

{

public event EventHandler Click; //事件

}

public class Form1

{

Button Button1;

void Button1_Click(Object sender,EventArgs e)

{

////////////////

}

Form1()

{

Button1 = new Button();

Button1.Click += new EventHandler(Button1_Click); //使用事件

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: