0

これは非常に単純な問題のように思えますが、私の人生では (私はコーディングにかなり慣れていないため) 答えを見つけることができません。

したがって、基本は、listbox1という名前のリストボックスがあり、いくつかのボタンの1つを押してさまざまなエントリを入力します(各ボタンにはリストに追加する「値」が設定されています)が、リスト内の各要素を増加しました。例えば:

  1. オブジェクト Z
  2. オブジェクト F
  3. オブジェクト W

などなど。しかし、これまでに管理したことは、個々のボタンごとにカウントを取得することだけです。つまり、カウントはすべてではなく、同じボタンに対してのみ増加します。例えば:

  1. 不動のブーツ
  2. レイジファイアブーツ
  3. レイジファイアブーツ
  4. 不動のブーツ

リストボックスに何が表示されるかを示す画像: プログラムの画像

したがって、右側のボタンを押すと、リストボックスにエントリが追加されます/

private: System::Void btn_steadfast_Click(System::Object^  sender, System::EventArgs^  e) 
     {
        static int i = 1;
        this->listBox1->Items->Add(i + ". Steadfast Boots ");
        i++;

private: System::Void btn_ragefire_Click(System::Object^  sender, System::EventArgs^  e) {
        static int i = 0;
        this->listBox1->Items->Add(i + ". Ragefire Boots ");
        i++;
     }

各ボタンが押されたときに参照するグローバルカウンターが必要だと思いますが、どうすればよいかわかりません。

どんな助けでも本当にありがたいです。

よろしくジェイミー


追加情報


これは私が試したコードです(コメントアウトされているのは私が入れようとしたものですが、「i」の使用などの古い情報を削除し、「Form1」をBDLGlacorsに変更してフォーム名を表現しようとしましたが、これは役に立ちませんでしたはプログラムの 2 番目の形式です):

#pragma endregion
private: System::Void BDLGlacors_Load(System::Object^  sender, System::EventArgs^  e) {
         }
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

             MessageBox::Show("Return to Menu?");
             BDLGlacors::Close();
         }
private: System::Void listView1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
         }
/*public ref class Form1 : public System::Windows::Forms::Form{
private:
    int buttonPressCount;

public:
    Form1()
    {
        buttonPressCount = 0;

    }*/
private: System::Void btn_steadfast_Click(System::Object^  sender, System::EventArgs^  e) 
     {
        static int i = 1;
        this->listBox1->Items->Add(/*buttonPressCount*/ i + ". Steadfast Boots ");
        //buttonPressCount++;
        i++;            
     }

private: System::Void btn_ragefire_Click(System::Object^  sender, System::EventArgs^  e) 
     {
        static int i = 1;
        this->listBox1->Items->Add(/*buttonPressCount*/i + ". Ragefire Boots ");
        //buttonPressCount++;
        i++;
     }

長い編集で申し訳ありません。

4

1 に答える 1

0

よくわかりませんが、フィールドとしてカウントが必要な場合があります。

public ref class Form1 : public System::Windows::Forms::Form
{
private:
    int buttonPressCount;

public:
    Form1()
    {
        buttonPressCount = 0;
        // ...
    }

private: System::Void btn_steadfast_Click(System::Object^  sender, System::EventArgs^  e) 
    {
        this->listBox1->Items->Add(buttonPressCount + ". Steadfast Boots ");
        buttonPressCount++;

private: System::Void btn_ragefire_Click(System::Object^  sender, System::EventArgs^  e) {
        this->listBox1->Items->Add(buttonPressCount + ". Ragefire Boots ");
        buttonPressCount++;
     }
};
于 2013-02-13T16:40:22.807 に答える