Ich bin neu hier und hoffe, Sie können mir helfen ... Ich habe eine Kopfzeile "Messagebox.h" für meine Fenster-Layout (ich benutze Visual Studio 2013) und ich möchte das Click-Event zu deklarieren in einer Klasse "Class.cpp" anstelle des Headers.Wie deklariere ich ein Button Event in einer Klasse?
das ist mein Messagebox.h
#pragma once
class Banana;
class Apple;
namespace Fruitsalat {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Zusammenfassung für Messagebox
/// </summary>
public ref class Messagebox : public System::Windows::Forms::Form
{
public:
Messagebox(void)
{
InitializeComponent();
//
//TODO: Konstruktorcode hier hinzufügen.
//
}
protected:
/// <summary>
/// Verwendete Ressourcen bereinigen.
/// </summary>
~Messagebox()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::TextBox^ textBox1;
protected:
private:
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
void InitializeComponent(void)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(197, 226);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 0;
this->button1->Text = L"quit";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Messagebox::button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(102, 226);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(75, 23);
this->button2->TabIndex = 1;
this->button2->Text = L"send";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &Messagebox::button2_Click);
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(12, 12);
this->textBox1->Multiline = true;
this->textBox1->ReadOnly = true;
this->textBox1->Name = L"textBox1";
this->textBox1->BackColor = Color::White;
this->textBox1->Size = System::Drawing::Size(260, 195);
this->textBox1->TabIndex = 2;
//
// Messagebox
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 261);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Name = L"Messagebox";
this->Text = L"Messagebox";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
this->Close();
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e){
//declare this in Apple.cpp or Banana.cpp
}
};
}
kann ich das und wie zu tun?
Dies ist nicht C++. – emlai
und warum nicht? Ich bin in C++ Programmierung O.o –
ah, okay, ich sehe! ^^ mein Fehler –