שאלה ב c++ visual studio gui

nadavru

New member
שאלה ב c++ visual studio gui

שלום לכולם!!!

יש לי gui שבניתי :
#pragma once

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "iomanip"
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <fstream>

namespace anicegame {

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>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{

public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//



////////////// my code is here

int c;
int billy[9];
int danny[9];
for (int i=0; i<9; i++)
billy = i;
for (int j=0; j<9; j++) {
int d;
c = rand() % (9-j) + 1;
danny[j] = billy[c];
d = billy[8-j];
billy[8-j] = billy[c];
billy[c] = d;
}
/////////////////////

label1->Text = L"1";
label2->Text = L"2";
label3->Text = L"3";
label4->Text = L"4";
label5->Text = L"5";
label6->Text = L"6";
label7->Text = L"7";
label8->Text = L"8";
label9->Text = L"9";

}

protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Label^ label1;
protected:
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::Label^ label4;
private: System::Windows::Forms::Label^ label5;
private: System::Windows::Forms::Label^ label6;
private: System::Windows::Forms::Label^ label7;
private: System::Windows::Forms::Label^ label8;
private: System::Windows::Forms::Label^ label9;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::Button^ button3;
private: System::Windows::Forms::Button^ button4;
private: System::Windows::Forms::Button^ button5;
private: System::Windows::Forms::Button^ button6;
private: System::Windows::Forms::Button^ button7;
private: System::Windows::Forms::Button^ button8;
private: System::Windows::Forms::Button^ button9;
private: System::Windows::Forms::Button^ button10;
private: System::Windows::Forms::Button^ button11;
private: System::Windows::Forms::Button^ button12;
private: System::Windows::Forms::Button^ button13;

private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
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->label5 = (gcnew System::Windows::Forms::Label());
this->label6 = (gcnew System::Windows::Forms::Label());
this->label7 = (gcnew System::Windows::Forms::Label());
this->label8 = (gcnew System::Windows::Forms::Label());
this->label9 = (gcnew System::Windows::Forms::Label());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->button3 = (gcnew System::Windows::Forms::Button());
this->button4 = (gcnew System::Windows::Forms::Button());
this->button5 = (gcnew System::Windows::Forms::Button());
this->button6 = (gcnew System::Windows::Forms::Button());
this->button7 = (gcnew System::Windows::Forms::Button());
this->button8 = (gcnew System::Windows::Forms::Button());
this->button9 = (gcnew System::Windows::Forms::Button());
this->button10 = (gcnew System::Windows::Forms::Button());
this->button11 = (gcnew System::Windows::Forms::Button());
this->button12 = (gcnew System::Windows::Forms::Button());
this->button13 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::point(93, 77);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(35, 13);
this->label1->TabIndex = 0;
this->label1->Text = L"label1";
this->label1->Click += gcnew System::EventHandler(this, &Form1::label1_Click);
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::point(134, 77);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(35, 13);
this->label2->TabIndex = 1;
this->label2->Text = L"label2";
this->label2->Click += gcnew System::EventHandler(this, &Form1::label2_Click);
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::point(175, 77);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(35, 13);
this->label3->TabIndex = 2;
this->label3->Text = L"label3";
this->label3->Click += gcnew System::EventHandler(this, &Form1::label3_Click);
//
// label4
//
this->label4->AutoSize = true;
this->label4->Location = System::Drawing::point(93, 99);
this->label4->Name = L"label4";
this->label4->Size = System::Drawing::Size(35, 13);
this->label4->TabIndex = 3;
this->label4->Text = L"label4";
this->label4->Click += gcnew System::EventHandler(this, &Form1::label4_Click);
//
// label5
//
this->label5->AutoSize = true;
this->label5->Location = System::Drawing::point(134, 99);
this->label5->Name = L"label5";
this->label5->Size = System::Drawing::Size(35, 13);
this->label5->TabIndex = 4;
this->label5->Text = L"label5";
this->label5->Click += gcnew System::EventHandler(this, &Form1::label5_Click);
//
// label6
//
this->label6->AutoSize = true;
this->label6->Location = System::Drawing::point(175, 99);
this->label6->Name = L"label6";
this->label6->Size = System::Drawing::Size(35, 13);
 

nadavru

New member
המשך

this->label7->TabIndex = 6;
this->label7->Text = L"label7";
this->label7->Click += gcnew System::EventHandler(this, &Form1::label7_Click);
//
// label8
//
this->label8->AutoSize = true;
this->label8->Location = System::Drawing::point(134, 121);
this->label8->Name = L"label8";
this->label8->Size = System::Drawing::Size(35, 13);
this->label8->TabIndex = 7;
this->label8->Text = L"label8";
this->label8->Click += gcnew System::EventHandler(this, &Form1::label8_Click);
//
// label9
//
this->label9->AutoSize = true;
this->label9->Location = System::Drawing::point(175, 121);
this->label9->Name = L"label9";
this->label9->Size = System::Drawing::Size(35, 13);
this->label9->TabIndex = 8;
this->label9->Text = L"label9";
this->label9->Click += gcnew System::EventHandler(this, &Form1::label9_Click);
//
// button1
//
this->button1->Location = System::Drawing::point(40, 80);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(45, 10);
this->button1->TabIndex = 9;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
//
// button2
//
this->button2->Location = System::Drawing::point(40, 101);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(46, 11);
this->button2->TabIndex = 10;
this->button2->Text = L"button2";
this->button2->UseVisualStyleBackColor = true;
//
// button3
//
this->button3->Location = System::Drawing::point(40, 124);
this->button3->Name = L"button3";
this->button3->Size = System::Drawing::Size(45, 10);
this->button3->TabIndex = 11;
this->button3->Text = L"button3";
this->button3->UseVisualStyleBackColor = true;
//
// button4
//
this->button4->Location = System::Drawing::point(93, 142);
this->button4->Name = L"button4";
this->button4->Size = System::Drawing::Size(35, 17);
this->button4->TabIndex = 12;
this->button4->Text = L"button4";
this->button4->UseVisualStyleBackColor = true;
//
// button5
//
this->button5->Location = System::Drawing::point(137, 142);
this->button5->Name = L"button5";
this->button5->Size = System::Drawing::Size(29, 17);
this->button5->TabIndex = 13;
this->button5->Text = L"button5";
this->button5->UseVisualStyleBackColor = true;
//
// button6
//
this->button6->Location = System::Drawing::point(178, 145);
this->button6->Name = L"button6";
this->button6->Size = System::Drawing::Size(28, 13);
this->button6->TabIndex = 14;
this->button6->Text = L"button6";
this->button6->UseVisualStyleBackColor = true;
//
// button7
//
this->button7->Location = System::Drawing::point(223, 123);
this->button7->Name = L"button7";
this->button7->Size = System::Drawing::Size(43, 10);
this->button7->TabIndex = 15;
this->button7->Text = L"button7";
this->button7->UseVisualStyleBackColor = true;
//
// button8
//
this->button8->Location = System::Drawing::point(223, 101);
this->button8->Name = L"button8";
this->button8->Size = System::Drawing::Size(42, 10);
this->button8->TabIndex = 16;
this->button8->Text = L"button8";
this->button8->UseVisualStyleBackColor = true;
//
// button9
//
this->button9->Location = System::Drawing::point(225, 78);
this->button9->Name = L"button9";
this->button9->Size = System::Drawing::Size(39, 11);
this->button9->TabIndex = 17;
this->button9->Text = L"button9";
this->button9->UseVisualStyleBackColor = true;
//
// button10
//
this->button10->Location = System::Drawing::point(178, 56);
this->button10->Name = L"button10";
this->button10->Size = System::Drawing::Size(26, 12);
this->button10->TabIndex = 18;
this->button10->Text = L"button10";
this->button10->UseVisualStyleBackColor = true;
//
// button11
//
this->button11->Location = System::Drawing::point(137, 55);
this->button11->Name = L"button11";
this->button11->Size = System::Drawing::Size(27, 12);
this->button11->TabIndex = 19;
this->button11->Text = L"button11";
this->button11->UseVisualStyleBackColor = true;
//
// button12
//
this->button12->Location = System::Drawing::point(93, 55);
this->button12->Name = L"button12";
this->button12->Size = System::Drawing::Size(31, 12);
this->button12->TabIndex = 20;
this->button12->Text = L"button12";
this->button12->UseVisualStyleBackColor = true;
//
// button13
//
this->button13->Location = System::Drawing::point(50, 198);
this->button13->Name = L"button13";
this->button13->Size = System::Drawing::Size(140, 36);
this->button13->TabIndex = 21;
this->button13->Text = L"button13";
this->button13->UseVisualStyleBackColor = true;
this->button13->Click += gcnew System::EventHandler(this, &Form1::button13_Click);
//
// Form1
//
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->button13);
this->Controls->Add(this->button12);
this->Controls->Add(this->button11);
this->Controls->Add(this->button10);
this->Controls->Add(this->button9);
this->Controls->Add(this->button8);
this->Controls->Add(this->button7);
this->Controls->Add(this->button6);
this->Controls->Add(this->button5);
this->Controls->Add(this->button4);
this->Controls->Add(this->button3);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->label9);
this->Controls->Add(this->label8);
this->Controls->Add(this->label7);
this->Controls->Add(this->label6);
this->Controls->Add(this->label5);
this->Controls->Add(this->label4);
this->Controls->Add(this->label3);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Na
 

nadavru

New member
המשך

this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion


private: System::Void label1_Click(System::Object^ sender, System::EventArgs^ e) {

}
private: System::Void label2_Click(System::Object^ sender, System::EventArgs^ e) {

}
private: System::Void label3_Click(System::Object^ sender, System::EventArgs^ e) {

}
private: System::Void label4_Click(System::Object^ sender, System::EventArgs^ e) {

}
private: System::Void label5_Click(System::Object^ sender, System::EventArgs^ e) {

}
private: System::Void label6_Click(System::Object^ sender, System::EventArgs^ e) {

}
private: System::Void label7_Click(System::Object^ sender, System::EventArgs^ e) {

}
private: System::Void label8_Click(System::Object^ sender, System::EventArgs^ e) {

}
private: System::Void label9_Click(System::Object^ sender, System::EventArgs^ e) {

}
private: System::Void button13_Click(System::Object^ sender, System::EventArgs^ e) {
c = 5;
}

};
}
 

nadavru

New member
המשך לשאלה

והשאלה שלי היא,

כאשר הגדרתי בקוד שלי למעלה ב public לדוגמא את int c;
ואני רוצה להשתמש ב c ב privata של הכפתור 13 בלחיצה, בסוף הקוד, איך אני מצהיר עליו? מה אני אמור לרשום?

תודה רבה לכל העוזרים !!!!!! :)
 

BravoMan

Active member
במבט חטוף ביותר:

עשית בקוד בדיוק מה שרצית לעשות...

יש לך מחלקה (גדולה ומכוערת, אבל בסה"כ מחלקה).
c הוא איבר שלה. אתה ניגש עליו מתוך פונקציה של מחלקה, בצורה רגילה, בדיוק כמו שכתבת. c = 5

אם אתה רוצה להיות בטוח שאתה לא מתבלבל בין ה-c המסוים הזה למשתנה מקומי או פרמטר אתה יכול להגדיל ולעשות this->c.

זה הכל.

נ.ב.:
הקובץ שניסית לצרף לא עלה. אולי בעיה בתפוז, אולי ניסית לעלות zip בלי לשנות סיומת. קורה...
 

פרסאוס

New member
אני בספק אם מישהו יעשה העתק הדבק

לכל הודעה לצורך יצירת פרוייקט חדש כדי שיוכל לראות על מה אתה מדבר.
יותר מזה, אני יכול לומר לך שכמעט שלחתי את התשובה הזאת להודעה הלא-נכונה מפאת האורך...
אז מה כן?
צרף את הקובץ, אם אם אין ברירה את הפרוייקט. ניתן לצרף קבצי ZIP וTXT להודעה.
ואז, תכתוב באיזו שורה הבעיה, או מה אתה מנסה להשיג.
 
למעלה