C ++ / CLI单击表单2上的按钮时,在表单1上启用文本框

时间:2013-11-26 14:02:00

标签: winforms visual-studio c++-cli

我目前正在开发一个visual c ++程序,我的第一个表单上有多个文本框,所有文本框都需要一个数字。这些是做什么的要求输入一个数字(具体费用的数额)。对于我的一些费用,他们需要多笔较小的费用来计算费用。为了实现这一点,我首先禁用了相应的文本框,并在每个禁用的文本框旁边都有一个按钮。当用户单击每个文本框旁边的按钮时,它会显示一个单独的表单(同时仍保持主窗体打开),提示用户输入在该表单上单击按钮时总计的所有较小费用。然后,一旦他们单击按钮以总计表单上的费用,就会出现一个返回按钮,当单击该按钮关闭表单并仅打开主费用表单时。我的困境是我需要发回特定费用的总计算值,将其放在主费用表格的相应文本框中,以及启用该文本​​框。我相信我的方法是将值返回到主费用表单,然后将其分配给文本框,但是我不太确定如果用户单击按钮返回主费用表单后如何启用文本框较小的弹出费用表格。任何提示或想法将不胜感激。

好奇心的旁注:我是否需要在主费用表上启用文本框以便将返回的值放入其中,然后在计算中使用该值,该计算涉及主费用表上的所有费用? / p>

//ExpensesForm.h
#pragma once
#include "MiscExpensesCalculateForm.h"

    namespace Project1 {

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

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

protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~ExpensesForm()
    {
        if (components)
        {
            delete components;
        }
    }
private: System::Windows::Forms::Label^  label1;
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::MaskedTextBox^  maskedTextBox1;
private: System::Windows::Forms::MaskedTextBox^  maskedTextBox2;
private: System::Windows::Forms::MaskedTextBox^  maskedTextBox3;
private: System::Windows::Forms::MaskedTextBox^  maskedTextBox4;
private: System::Windows::Forms::MaskedTextBox^  maskedTextBox5;
private: System::Windows::Forms::MaskedTextBox^  maskedTextBox6;
private: System::Windows::Forms::Label^  label7;
private: System::Windows::Forms::MaskedTextBox^  maskedTextBox7;
private: System::Windows::Forms::Button^  button1;
private: System::Windows::Forms::Button^  button2;
private: System::Windows::Forms::Label^  label8;
private: System::Windows::Forms::Button^  button3;
private: System::Windows::Forms::MaskedTextBox^  maskedTextBox8;
private: System::Windows::Forms::Button^  button4;
private: System::Windows::Forms::MaskedTextBox^  maskedTextBox9;
private: System::Windows::Forms::Label^  label9;
private: System::Windows::Forms::Label^  label10;
private: System::Windows::Forms::Label^  label11;
private: System::Windows::Forms::Button^  button5;
public: System::Windows::Forms::MaskedTextBox^  misctotaltextbox;

private: System::Windows::Forms::Label^  label12;
private: System::Windows::Forms::Label^  label13;
protected:

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)
    {
        System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(ExpensesForm::typeid));
        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->maskedTextBox1 = (gcnew System::Windows::Forms::MaskedTextBox());
        this->maskedTextBox2 = (gcnew System::Windows::Forms::MaskedTextBox());
        this->maskedTextBox3 = (gcnew System::Windows::Forms::MaskedTextBox());
        this->maskedTextBox4 = (gcnew System::Windows::Forms::MaskedTextBox());
        this->maskedTextBox5 = (gcnew System::Windows::Forms::MaskedTextBox());
        this->maskedTextBox6 = (gcnew System::Windows::Forms::MaskedTextBox());
        this->label7 = (gcnew System::Windows::Forms::Label());
        this->maskedTextBox7 = (gcnew System::Windows::Forms::MaskedTextBox());
        this->button1 = (gcnew System::Windows::Forms::Button());
        this->button2 = (gcnew System::Windows::Forms::Button());
        this->label8 = (gcnew System::Windows::Forms::Label());
        this->button3 = (gcnew System::Windows::Forms::Button());
        this->maskedTextBox8 = (gcnew System::Windows::Forms::MaskedTextBox());
        this->button4 = (gcnew System::Windows::Forms::Button());
        this->maskedTextBox9 = (gcnew System::Windows::Forms::MaskedTextBox());
        this->label9 = (gcnew System::Windows::Forms::Label());
        this->label10 = (gcnew System::Windows::Forms::Label());
        this->label11 = (gcnew System::Windows::Forms::Label());
        this->button5 = (gcnew System::Windows::Forms::Button());
        this->misctotaltextbox = (gcnew System::Windows::Forms::MaskedTextBox());
        this->label12 = (gcnew System::Windows::Forms::Label());
        this->label13 = (gcnew System::Windows::Forms::Label());
        this->SuspendLayout();
        // 
        // label1
        // 
        this->label1->AutoSize = true;
        this->label1->Location = System::Drawing::Point(22, 86);
        this->label1->Name = L"label1";
        this->label1->Size = System::Drawing::Size(74, 13);
        this->label1->TabIndex = 0;
        this->label1->Text = L"Cell Phone Bill";
        // 
        // label2
        // 
        this->label2->AutoSize = true;
        this->label2->Location = System::Drawing::Point(22, 230);
        this->label2->Name = L"label2";
        this->label2->Size = System::Drawing::Size(111, 13);
        this->label2->TabIndex = 1;
        this->label2->Text = L"Doctors Appointments";
        // 
        // label3
        // 
        this->label3->AutoSize = true;
        this->label3->Location = System::Drawing::Point(22, 124);
        this->label3->Name = L"label3";
        this->label3->Size = System::Drawing::Size(73, 13);
        this->label3->TabIndex = 2;
        this->label3->Text = L"Car Insurance";
        // 
        // label4
        // 
        this->label4->AutoSize = true;
        this->label4->Location = System::Drawing::Point(22, 195);
        this->label4->Name = L"label4";
        this->label4->Size = System::Drawing::Size(91, 13);
        this->label4->TabIndex = 3;
        this->label4->Text = L"Therapy Sessions";
        // 
        // label5
        // 
        this->label5->AutoSize = true;
        this->label5->Location = System::Drawing::Point(22, 160);
        this->label5->Name = L"label5";
        this->label5->Size = System::Drawing::Size(88, 13);
        this->label5->TabIndex = 4;
        this->label5->Text = L"Health Insurance";
        // 
        // label6
        // 
        this->label6->AutoSize = true;
        this->label6->Location = System::Drawing::Point(22, 343);
        this->label6->Name = L"label6";
        this->label6->Size = System::Drawing::Size(30, 13);
        this->label6->TabIndex = 5;
        this->label6->Text = L"Rent";
        // 
        // maskedTextBox1
        // 
        this->maskedTextBox1->Location = System::Drawing::Point(158, 83);
        this->maskedTextBox1->Mask = L"000.00";
        this->maskedTextBox1->Name = L"maskedTextBox1";
        this->maskedTextBox1->Size = System::Drawing::Size(100, 20);
        this->maskedTextBox1->TabIndex = 6;
        // 
        // maskedTextBox2
        // 
        this->maskedTextBox2->Location = System::Drawing::Point(158, 121);
        this->maskedTextBox2->Mask = L"000.00";
        this->maskedTextBox2->Name = L"maskedTextBox2";
        this->maskedTextBox2->Size = System::Drawing::Size(100, 20);
        this->maskedTextBox2->TabIndex = 7;
        // 
        // maskedTextBox3
        // 
        this->maskedTextBox3->Location = System::Drawing::Point(158, 157);
        this->maskedTextBox3->Mask = L"000.00";
        this->maskedTextBox3->Name = L"maskedTextBox3";
        this->maskedTextBox3->Size = System::Drawing::Size(100, 20);
        this->maskedTextBox3->TabIndex = 8;
        // 
        // maskedTextBox4
        // 
        this->maskedTextBox4->Location = System::Drawing::Point(158, 192);
        this->maskedTextBox4->Mask = L"000.00";
        this->maskedTextBox4->Name = L"maskedTextBox4";
        this->maskedTextBox4->Size = System::Drawing::Size(100, 20);
        this->maskedTextBox4->TabIndex = 9;
        // 
        // maskedTextBox5
        // 
        this->maskedTextBox5->Location = System::Drawing::Point(158, 227);
        this->maskedTextBox5->Mask = L"000.00";
        this->maskedTextBox5->Name = L"maskedTextBox5";
        this->maskedTextBox5->Size = System::Drawing::Size(100, 20);
        this->maskedTextBox5->TabIndex = 10;
        // 
        // maskedTextBox6
        // 
        this->maskedTextBox6->Enabled = false;
        this->maskedTextBox6->Location = System::Drawing::Point(158, 340);
        this->maskedTextBox6->Mask = L"000.00";
        this->maskedTextBox6->Name = L"maskedTextBox6";
        this->maskedTextBox6->Size = System::Drawing::Size(100, 20);
        this->maskedTextBox6->TabIndex = 11;
        // 
        // label7
        // 
        this->label7->AutoSize = true;
        this->label7->Location = System::Drawing::Point(22, 379);
        this->label7->Name = L"label7";
        this->label7->Size = System::Drawing::Size(44, 13);
        this->label7->TabIndex = 12;
        this->label7->Text = L"Grocery";
        // 
        // maskedTextBox7
        // 
        this->maskedTextBox7->Enabled = false;
        this->maskedTextBox7->Location = System::Drawing::Point(158, 376);
        this->maskedTextBox7->Mask = L"000.00";
        this->maskedTextBox7->Name = L"maskedTextBox7";
        this->maskedTextBox7->Size = System::Drawing::Size(100, 20);
        this->maskedTextBox7->TabIndex = 13;
        // 
        // button1
        // 
        this->button1->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"button1.BackgroundImage")));
        this->button1->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Center;
        this->button1->FlatAppearance->BorderSize = 0;
        this->button1->Location = System::Drawing::Point(127, 373);
        this->button1->Name = L"button1";
        this->button1->Size = System::Drawing::Size(25, 25);
        this->button1->TabIndex = 14;
        this->button1->UseVisualStyleBackColor = true;
        // 
        // button2
        // 
        this->button2->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"button2.BackgroundImage")));
        this->button2->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Center;
        this->button2->FlatAppearance->BorderSize = 0;
        this->button2->Location = System::Drawing::Point(127, 337);
        this->button2->Name = L"button2";
        this->button2->Size = System::Drawing::Size(25, 25);
        this->button2->TabIndex = 15;
        this->button2->UseVisualStyleBackColor = true;
        // 
        // label8
        // 
        this->label8->AutoSize = true;
        this->label8->Location = System::Drawing::Point(22, 306);
        this->label8->Name = L"label8";
        this->label8->Size = System::Drawing::Size(61, 13);
        this->label8->TabIndex = 16;
        this->label8->Text = L"Gas/Travel";
        // 
        // button3
        // 
        this->button3->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"button3.BackgroundImage")));
        this->button3->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Center;
        this->button3->FlatAppearance->BorderSize = 0;
        this->button3->Location = System::Drawing::Point(127, 300);
        this->button3->Name = L"button3";
        this->button3->Size = System::Drawing::Size(25, 25);
        this->button3->TabIndex = 18;
        this->button3->UseVisualStyleBackColor = true;
        // 
        // maskedTextBox8
        // 
        this->maskedTextBox8->Enabled = false;
        this->maskedTextBox8->Location = System::Drawing::Point(158, 303);
        this->maskedTextBox8->Mask = L"000.00";
        this->maskedTextBox8->Name = L"maskedTextBox8";
        this->maskedTextBox8->Size = System::Drawing::Size(100, 20);
        this->maskedTextBox8->TabIndex = 17;
        // 
        // button4
        // 
        this->button4->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"button4.BackgroundImage")));
        this->button4->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Center;
        this->button4->FlatAppearance->BorderSize = 0;
        this->button4->Location = System::Drawing::Point(127, 259);
        this->button4->Name = L"button4";
        this->button4->Size = System::Drawing::Size(25, 25);
        this->button4->TabIndex = 20;
        this->button4->UseVisualStyleBackColor = true;
        // 
        // maskedTextBox9
        // 
        this->maskedTextBox9->Enabled = false;
        this->maskedTextBox9->Location = System::Drawing::Point(158, 262);
        this->maskedTextBox9->Mask = L"000.00";
        this->maskedTextBox9->Name = L"maskedTextBox9";
        this->maskedTextBox9->Size = System::Drawing::Size(100, 20);
        this->maskedTextBox9->TabIndex = 19;
        this->maskedTextBox9->MaskInputRejected += gcnew System::Windows::Forms::MaskInputRejectedEventHandler(this, &ExpensesForm::maskedTextBox9_MaskInputRejected);
        // 
        // label9
        // 
        this->label9->AutoSize = true;
        this->label9->Location = System::Drawing::Point(22, 265);
        this->label9->Name = L"label9";
        this->label9->Size = System::Drawing::Size(64, 13);
        this->label9->TabIndex = 21;
        this->label9->Text = L"Medications";
        // 
        // label10
        // 
        this->label10->AutoSize = true;
        this->label10->Location = System::Drawing::Point(416, 50);
        this->label10->Name = L"label10";
        this->label10->Size = System::Drawing::Size(80, 13);
        this->label10->TabIndex = 22;
        this->label10->Text = L"The Run-Down";
        // 
        // label11
        // 
        this->label11->AutoSize = true;
        this->label11->Location = System::Drawing::Point(345, 81);
        this->label11->Name = L"label11";
        this->label11->Size = System::Drawing::Size(228, 351);
        this->label11->TabIndex = 23;
        this->label11->Text = resources->GetString(L"label11.Text");
        // 
        // button5
        // 
        this->button5->BackgroundImage = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"button5.BackgroundImage")));
        this->button5->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Center;
        this->button5->FlatAppearance->BorderSize = 0;
        this->button5->Location = System::Drawing::Point(127, 408);
        this->button5->Name = L"button5";
        this->button5->Size = System::Drawing::Size(25, 25);
        this->button5->TabIndex = 26;
        this->button5->UseVisualStyleBackColor = true;
        this->button5->Click += gcnew System::EventHandler(this, &ExpensesForm::button5_Click);
        // 
        // misctotaltextbox
        // 
        this->misctotaltextbox->Enabled = false;
        this->misctotaltextbox->Location = System::Drawing::Point(158, 411);
        this->misctotaltextbox->Mask = L"000.00";
        this->misctotaltextbox->Name = L"misctotaltextbox";
        this->misctotaltextbox->Size = System::Drawing::Size(100, 20);
        this->misctotaltextbox->TabIndex = 25;
        // 
        // label12
        // 
        this->label12->AutoSize = true;
        this->label12->Location = System::Drawing::Point(22, 414);
        this->label12->Name = L"label12";
        this->label12->Size = System::Drawing::Size(32, 13);
        this->label12->TabIndex = 24;
        this->label12->Text = L"Misc.";
        // 
        // label13
        // 
        this->label13->AutoSize = true;
        this->label13->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
            static_cast<System::Byte>(0)));
        this->label13->Location = System::Drawing::Point(263, 12);
        this->label13->Name = L"label13";
        this->label13->Size = System::Drawing::Size(95, 24);
        this->label13->TabIndex = 27;
        this->label13->Text = L"Expenses";
        // 
        // ExpensesForm
        // 
        this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
        this->ClientSize = System::Drawing::Size(637, 499);
        this->Controls->Add(this->label13);
        this->Controls->Add(this->button5);
        this->Controls->Add(this->misctotaltextbox);
        this->Controls->Add(this->label12);
        this->Controls->Add(this->label11);
        this->Controls->Add(this->label10);
        this->Controls->Add(this->label9);
        this->Controls->Add(this->button4);
        this->Controls->Add(this->maskedTextBox9);
        this->Controls->Add(this->button3);
        this->Controls->Add(this->maskedTextBox8);
        this->Controls->Add(this->label8);
        this->Controls->Add(this->button2);
        this->Controls->Add(this->button1);
        this->Controls->Add(this->maskedTextBox7);
        this->Controls->Add(this->label7);
        this->Controls->Add(this->maskedTextBox6);
        this->Controls->Add(this->maskedTextBox5);
        this->Controls->Add(this->maskedTextBox4);
        this->Controls->Add(this->maskedTextBox3);
        this->Controls->Add(this->maskedTextBox2);
        this->Controls->Add(this->maskedTextBox1);
        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->Name = L"ExpensesForm";
        this->Text = L"Budget Buddy - Expenses";
        this->Load += gcnew System::EventHandler(this, &ExpensesForm::ExpensesForm_Load);
        this->ResumeLayout(false);
        this->PerformLayout();

    }
    #pragma endregion
        private: System::Void maskedTextBox9_MaskInputRejected(System::Object^  sender, System::Windows::Forms::MaskInputRejectedEventArgs^  e) {
}
    private: System::Void button5_Click(System::Object^  sender, System::EventArgs^  e) {
         MiscExpensesCalculateForm^ mecf = gcnew MiscExpensesCalculateForm();
         mecf->ShowDialog();
 }

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

我发现了this帖子,这正是我需要做的,但我只是不知道在哪里放置代码。

1 个答案:

答案 0 :(得分:0)

通常做的事情(参见像FileDialog这样的类型)是将一些公共属性放在模态表单类中(这里是MiscExpensesCalculateForm)并在调用ShowDialog之前简单地设置它们并读取他们之后)。

private: System::Void button5_Click(System::Object^  sender, System::EventArgs^  e) {
    MiscExpensesCalculateForm^ mecf = gcnew MiscExpensesCalculateForm();
    mecf->SomeInputData = blahblah;
    DialogResult dr = mecf->ShowDialog();
    if(dr == DialogResult.OK) {
        textBoxResult->Text = mecf->MyResultData;
        textBoxResult->Enabled = true;
    }
}