Messagebox result???
-
Ich arbeite jetzt mit der ganz neuen VS 2010 Ultimate edition und hab ne ziemlich simple frage:
MessageBox::Show("Aktivierung wiklich abbrechen?","Achtung:",MessageBoxButtons::YesNo);
so aber wie frage ich jetzt ab ob er ja oder nein geklickt hat...
ich hab das hier probiertif (MessageBoxResult == Yes) { this->Close(); }
lg
-
if (MessageBox::Show("Aktivierung wiklich abbrechen?","Achtung:",MessageBoxButtons::YesNo) == MessageBoxResult::Yes)
-
Oh Danke
-
verdammt:
if (MessageBox::Show("Aktivierung wiklich abbrechen?","Achtung:",MessageBoxButtons::YesNo) == MessageBoxResult::Yes) { this->Close(); }
geht nicht...
Fehlermeldung:
1>c:\users\besitzer\documents\visual studio 2010\projects\serial\serial\Form1.h(235): error C2653: 'MessageBoxResult': Keine Klasse oder Namespace
1>c:\users\besitzer\documents\visual studio 2010\projects\serial\serial\Form1.h(235): error C2065: 'Yes': nichtdeklarierter Bezeichner
-
Das ist ja letztlich genau das, was ich dir auch gesagt habe (http://c-plusplus.net/forum/viewtopic-var-t-is-256998-and-highlight-is--and-sid-is-6d9ac1b847de8813ad1d1bf3cfbc8dc2.html).
Sind das denn die einzigen Fehlermeldungen, die du bekommst (wird die Show-Methode nicht angemeckert?)? Kann es sein, dass dir Header fehlen bzw. du vielleicht sogar einen falschen Projekttypen gewählt hast? Nur so 'ne Vermutung...
-
Das war aus dem Kopf zitiert... wenn Du Dir die Mühe machen würdest und einenkurzen Blick in die Hilfe werden würdest, würdest Du das richtige Beispiel finde:
http://msdn.microsoft.com/de-de/library/system.windows.forms.messageboxif (MessageBox::Show("Aktivierung wiklich abbrechen?","Achtung:",MessageBoxButtons::YesNo) == DialogResult::Yes)
-
Hä bin ich doof...
kann mir jemand meinen quelltext ändern so dass es funzt#pragma once namespace Serial { 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 Form1 /// </summary> public ref class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); // //TODO: Konstruktorcode hier hinzufügen. // } protected: /// <summary> /// Verwendete Ressourcen bereinigen. /// </summary> ~Form1() { if (components) { delete components; } } private: System::Windows::Forms::Button^ button1; protected: private: System::Windows::Forms::Button^ button2; private: System::Windows::Forms::ProgressBar^ progressBar1; private: System::Windows::Forms::TextBox^ textBox1; private: System::Windows::Forms::TextBox^ textBox2; private: System::Windows::Forms::TextBox^ textBox3; private: System::Windows::Forms::TextBox^ textBox4; private: System::Windows::Forms::TextBox^ textBox5; private: System::Windows::Forms::Label^ label1; private: System::Windows::Forms::Label^ label2; private: System::Windows::Forms::Label^ label3; private: System::Windows::Forms::Label^ label4; 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) { System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid)); this->button1 = (gcnew System::Windows::Forms::Button()); this->button2 = (gcnew System::Windows::Forms::Button()); this->progressBar1 = (gcnew System::Windows::Forms::ProgressBar()); this->textBox1 = (gcnew System::Windows::Forms::TextBox()); this->textBox2 = (gcnew System::Windows::Forms::TextBox()); this->textBox3 = (gcnew System::Windows::Forms::TextBox()); this->textBox4 = (gcnew System::Windows::Forms::TextBox()); this->textBox5 = (gcnew System::Windows::Forms::TextBox()); this->label1 = (gcnew System::Windows::Forms::Label()); this->label2 = (gcnew System::Windows::Forms::Label()); this->label3 = (gcnew System::Windows::Forms::Label()); this->label4 = (gcnew System::Windows::Forms::Label()); this->SuspendLayout(); // // button1 // this->button1->Location = System::Drawing::Point(543, 284); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(75, 23); this->button1->TabIndex = 2; this->button1->Text = L"Activate"; this->button1->UseVisualStyleBackColor = true; // // button2 // this->button2->Location = System::Drawing::Point(560, 12); this->button2->Name = L"button2"; this->button2->Size = System::Drawing::Size(58, 23); this->button2->TabIndex = 0; this->button2->Text = L"Close"; this->button2->UseVisualStyleBackColor = true; this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click); // // progressBar1 // this->progressBar1->Location = System::Drawing::Point(12, 313); this->progressBar1->Name = L"progressBar1"; this->progressBar1->Size = System::Drawing::Size(606, 23); this->progressBar1->TabIndex = 8; // // textBox1 // this->textBox1->Location = System::Drawing::Point(15, 287); this->textBox1->Margin = System::Windows::Forms::Padding(6, 3, 6, 3); this->textBox1->MaxLength = 4; this->textBox1->Name = L"textBox1"; this->textBox1->Size = System::Drawing::Size(66, 20); this->textBox1->TabIndex = 3; // // textBox2 // this->textBox2->Location = System::Drawing::Point(249, 287); this->textBox2->Margin = System::Windows::Forms::Padding(6, 3, 6, 3); this->textBox2->MaxLength = 4; this->textBox2->Name = L"textBox2"; this->textBox2->Size = System::Drawing::Size(66, 20); this->textBox2->TabIndex = 6; // // textBox3 // this->textBox3->Location = System::Drawing::Point(93, 287); this->textBox3->Margin = System::Windows::Forms::Padding(6, 3, 6, 3); this->textBox3->MaxLength = 4; this->textBox3->Name = L"textBox3"; this->textBox3->Size = System::Drawing::Size(66, 20); this->textBox3->TabIndex = 4; // // textBox4 // this->textBox4->Location = System::Drawing::Point(171, 287); this->textBox4->Margin = System::Windows::Forms::Padding(6, 3, 6, 3); this->textBox4->MaxLength = 4; this->textBox4->Name = L"textBox4"; this->textBox4->Size = System::Drawing::Size(66, 20); this->textBox4->TabIndex = 5; // // textBox5 // this->textBox5->Location = System::Drawing::Point(327, 287); this->textBox5->Margin = System::Windows::Forms::Padding(6, 3, 6, 3); this->textBox5->MaxLength = 4; this->textBox5->Name = L"textBox5"; this->textBox5->Size = System::Drawing::Size(66, 20); this->textBox5->TabIndex = 7; // // label1 // this->label1->AutoSize = true; this->label1->ForeColor = System::Drawing::Color::White; this->label1->Location = System::Drawing::Point(82, 290); this->label1->Margin = System::Windows::Forms::Padding(0); this->label1->Name = L"label1"; this->label1->Size = System::Drawing::Size(10, 13); this->label1->TabIndex = 8; this->label1->Text = L"-"; // // label2 // this->label2->AutoSize = true; this->label2->ForeColor = System::Drawing::Color::White; this->label2->Location = System::Drawing::Point(160, 290); this->label2->Margin = System::Windows::Forms::Padding(0); this->label2->Name = L"label2"; this->label2->Size = System::Drawing::Size(10, 13); this->label2->TabIndex = 9; this->label2->Text = L"-"; // // label3 // this->label3->AutoSize = true; this->label3->ForeColor = System::Drawing::Color::White; this->label3->Location = System::Drawing::Point(238, 290); this->label3->Margin = System::Windows::Forms::Padding(0); this->label3->Name = L"label3"; this->label3->Size = System::Drawing::Size(10, 13); this->label3->TabIndex = 10; this->label3->Text = L"-"; // // label4 // this->label4->AutoSize = true; this->label4->ForeColor = System::Drawing::Color::White; this->label4->Location = System::Drawing::Point(316, 290); this->label4->Margin = System::Windows::Forms::Padding(0); this->label4->Name = L"label4"; this->label4->Size = System::Drawing::Size(10, 13); this->label4->TabIndex = 11; this->label4->Text = L"-"; // // Form1 // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->BackColor = System::Drawing::Color::Black; this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"$this.BackgroundImage"))); this->ClientSize = System::Drawing::Size(630, 348); this->ControlBox = false; this->Controls->Add(this->label4); this->Controls->Add(this->label3); this->Controls->Add(this->label2); this->Controls->Add(this->label1); this->Controls->Add(this->textBox5); this->Controls->Add(this->textBox4); this->Controls->Add(this->textBox3); this->Controls->Add(this->textBox2); this->Controls->Add(this->textBox1); this->Controls->Add(this->progressBar1); this->Controls->Add(this->button2); this->Controls->Add(this->button1); this->DoubleBuffered = true; this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::None; this->ImeMode = System::Windows::Forms::ImeMode::KatakanaHalf; this->KeyPreview = true; this->Name = L"Form1"; this->ShowIcon = false; this->ShowInTaskbar = false; this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen; this->Text = L"Form1"; this->TopMost = true; this->ResumeLayout(false); this->PerformLayout(); } #pragma endregion private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { MessageBox::Show("Aktivierung wiklich abbrechen?","Achtung:",MessageBoxButtons::YesNo) if (MessageBox::Show("Aktivierung wiklich abbrechen?","Achtung:",MessageBoxButtons::YesNo) == Yes) { this->Close(); } } }; }
-
Registriere mich bald schrieb:
kann mir jemand meinen quelltext ändern so dass es funzt
Nö, ehrlich gesagt fänd ich das nicht gut. Du hast quasi von Jochen die Lösung präsentiert bekommen. Einbauen solltest du sie schon selbst. Tipp: du willst nicht 2 MessageBoxen aufrufen!
-
_matze schrieb:
Tipp: du willst nicht 2 MessageBoxen aufrufen!
erschlag ihn doch nicht gleich mit der Lösung
-
Les doch noch mal oben und vergleiche
btw: im header ? Ist das nicht ziemlich unschön die Prozedur da aufzulösen ? (Gilt nicht dem Thread starter, dann ist der völlig verwirrt
)
-
#pragma endregion private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { if (MessageBox::Show("Aktivierung wiklich abbrechen?","Achtung:",MessageBoxButtons::YesNo) == DialogResult::Yes) { this->Close(); } } }; }
das funzt nich:
1>c:\users\besitzer\documents\visual studio 2010\projects\serial\serial\Form1.h(235): error C2039: 'Yes': Ist kein Element von 'System::Windows::Forms::Form::DialogResult'
1> c:\users\besitzer\documents\visual studio 2010\projects\serial\serial\Form1.h(16): Siehe Deklaration von 'System::Windows::Forms::Form::DialogResult'
1>c:\users\besitzer\documents\visual studio 2010\projects\serial\serial\Form1.h(235): error C2065: 'Yes': nichtdeklarierter Bezeichner
-
#pragma endregion private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) { String^ message = "Aktivierung wiklich abbrechen?"; String^ caption = "Achtung:"; MessageBoxButtons buttons = MessageBoxButtons::YesNo; System::Windows::Forms::DialogResult result; result = MessageBox::Show( this, message, caption, buttons ); if ( result == DialogResult::Yes ) { this->Close(); } } }; }
und auch funktioniert nicht...
1>c:\users\besitzer\documents\visual studio 2010\projects\serial\serial\Form1.h(239): error C2039: 'Yes': Ist kein Element von 'System::Windows::Forms::Form::DialogResult'
1> c:\users\besitzer\documents\visual studio 2010\projects\serial\serial\Form1.h(16): Siehe Deklaration von 'System::Windows::Forms::Form::DialogResult'
1>c:\users\besitzer\documents\visual studio 2010\projects\serial\serial\Form1.h(239): error C2065: 'Yes': nichtdeklarierter Bezeichner
-
Leute was ist los mit euch? Ihre seid derbe damit beschäftigt, euch über
Poster lustig zumachen und überseht das dieser Code gar nicht
funktionieren kann. Auch die Version von Jochen nicht, sorry Jochen...DialogResult gehört zum Namespace System::Windows::Forms.
Es gibt zwei Möglichkeiten diesen Code Lauffähig zu bekommen.
Die erste, ich vereinbare o.g. Namespace Global...
#pragma once using namespace System::Windows::Forms; namespace tstBsp { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Data; using namespace System::Drawing;
if(MessageBox::Show("Aktivierung wiklich abbrechen?","Achtung:",MessageBoxButtons::YesNo,MessageBoxIcon::Question,MessageBoxDefaultButton::Button2) == ::DialogResult::Yes) { this->Close(); }
Oder ich lasse ihn Lokal und stelle den Namespace vorran...
if(MessageBox::Show("Aktivierung wiklich abbrechen?","Achtung:",MessageBoxButtons::YesNo,MessageBoxIcon::Question,MessageBoxDefaultButton::Button2) == ::System::Windows::Forms::DialogResult::Yes) { this->Close(); }
Gruß,
Doug_HH
Oder Irre ich mich? :xmas2:
-
Danke Doug_HH
dein zweiter code
[quote=Doug_HH]if(MessageBox::Show("Aktivierung wiklich abbrechen?","Achtung:",MessageBoxButtons::YesNo,MessageBoxIcon::Question,MessageBoxDefaultButton::Button2) == ::System::Windows::Forms::DialogResult::Yes) { this->Close(); }
[/quote]
funktioniert...
Und danke auch an alle die mitgeholfen haben das problem zu lösen...lg
-
Ja, das Problem ist, dass ein "Form" ein Property mit dem Namen "DialogResult" hat... und der Compiler wohl zu "blöd" ist, dies korrekt aufzulösen... deshalb muss man ein Namespace qualifier angeben...