| C# | C++ |
|---|
using System;
using System.Runtime.InteropServices;
| #using <System.dll>
using namespace System;
using namespace System::Runtime::InteropServices;
|
class Program
{
[STAThread]
static void Main(string[] args)
{
}
| [STAThreadAttribute]
int main(array<System::String ^> ^args)
{
Application::Run(gcnew MyForm()); // message loop
return 0;
}
|
//add button to form
private System.Windows.Forms.Button button1; :
// init
this.button1.Font = new System.Drawing.Font("MS UI Gothic",
6F, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(128)));
this.button1.Location = new System.Drawing.Point(376, 32);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(32, 24);
this.button1.TabIndex = 3;
this.button1.Text = "・・・";
this.button1.Click +=
new System.EventHandler(this.button1_Click);
:
// add to form
this.Controls.Add(button1);
:
// handler
private void button1_Click(object sender, System.EventArgs e){
}
|
// variable
Button^ btn;
void btn_Click(Object ^sender, System::EventArgs^ e);
:
// init
btn=gcnew Button();
btn->Text="Test Button";
btn->Location=Point(5,90);
btn->Size=System::Drawing::Size(100,22);
btn->Click += gcnew EventHandler( this, &MyForm::btn_Click);
:
//add the button
this->Controls->Add(btn);
:
//the event handler for button click
void MyForm::btn_Click(Object ^sender, System::EventArgs ^e)
{
//we show the current date/time in the text box
DateTime dt=System::DateTime::Now;
txt1->Text=dt.ToString();
}
|
// Timer
// variable
private System.Windows.Forms.Timer timer1;
|
// variable
private:
System::Windows::Forms::Timer timer1;
void timer1_Tick(Object^ sender, System::EventArgs^ e);
|
// init
this.timer1.Tick +=
new System.EventHandler(this.timer1_Tick);
|
// init
this->timer1->Tick += gcnew System::EventHandler(this,&myApp::timer1_Tick);
|
// handler
private void timer1_Tick(object sender,
System.EventArgs e){}
|
// handler
void myApp::timer1_Tick(Object^ sender, System::EventArgs^ e){}
|
this.button.Location = new System.Drawing.Point(149, 86); this.button.Size = new System.Drawing.Size(147, 23);
|
this->button->Location = System::Drawing::Point(149, 86); this->button->Size
= System::Drawing::Size(147, 23);
|
|
ref Message m |
Message% m // 参照 |
|
Console::CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs
e)
|
this->button1->Click += gcnew System::EventHandler(this,&loop_sound::button
1_Click); |