ページ 11

VC.netでの質問

Posted: 2009年8月16日(日) 12:48
by
何度も投稿してしまい申し訳ございません。
VC++でアプリを作っております。
皆さんのおかげで2つのフォーム間での値のやり取り(サブ→メイン)へ
はなんとかできました。
しかしその逆ができす困っております。
(メインの値をサブに送りたいです。)

F2で名前を変更するフォームを呼び出すのですが
ここでタブ名を渡してあげたいです。

添付ファイルがメインフォームです
//サブフォーム
#pragma once

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;


namespace Sample {

	/// <summary>
	/// Form2 の概要
	///
	/// 警告: このクラスの名前を変更する場合、このクラスが依存するすべての .resx ファイルに関連付けられた
	///          マネージ リソース コンパイラ ツールに対して 'Resource File Name' プロパティを
	///          変更する必要があります。この変更を行わないと、
	///          デザイナと、このフォームに関連付けられたローカライズ済みリソースとが、
	///          正しく相互に利用できなくなります。
	/// </summary>
	public ref class Form2 : public System::Windows::Forms::Form
	{
	public:
		Form2(void)
		{
			InitializeComponent();
			//
			//TODO: ここにコンストラクタ コードを追加します
			//
		}
	public: String^ GetTextBoxText(){
			return nameTextBox->Text;
	} 
	/*
	public: void TextBoxSet(String^ Str){
		this->nameTextBox->Text = Str;
	}
	*/
	protected:
		/// <summary>
		/// 使用中のリソースをすべてクリーンアップします。
		/// </summary>
		~Form2()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  nameButton;
	private: System::Windows::Forms::TextBox^ nameTextBox;

	protected: 

	private:
		/// <summary>
		/// 必要なデザイナ変数です。
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
		/// コード エディタで変更しないでください。
		/// </summary>
		void InitializeComponent(void)
		{
			this->nameButton = (gcnew System::Windows::Forms::Button());
			this->nameTextBox = (gcnew System::Windows::Forms::TextBox());
			this->SuspendLayout();
			// 
			// nameButton
			// 
			this->nameButton->Location = System::Drawing::Point(70, 36);
			this->nameButton->Name = L"nameButton";
			this->nameButton->Size = System::Drawing::Size(57, 23);
			this->nameButton->TabIndex = 0;
			this->nameButton->Text = L"変更";
			this->nameButton->UseVisualStyleBackColor = true;
			this->nameButton->Click += gcnew System::EventHandler(this, &Form2::nameButton_Click);
	//		this->nameButton->Select();
			// 
			// nameTextBox
			// 
			this->nameTextBox->Location = System::Drawing::Point(12, 11);
			this->nameTextBox->Name = L"nameTextBox";
			this->nameTextBox->Size = System::Drawing::Size(170, 19);
			this->nameTextBox->TabIndex = 1;
			this->nameTextBox->ImeMode = System::Windows::Forms::ImeMode::Hiragana;
			this->nameTextBox->Text = Form1
			//tabPage[this->tabControl1->SelectedIndex]->Text = nameForm->GetTextBoxText();
		//	this->nameTextBox->SelectionStart();
			// 
			// Form2
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(192, 66);
			this->Controls->Add(this->nameTextBox);
			this->Controls->Add(this->nameButton);
			this->Load += gcnew System::EventHandler(this, &Form2::Form2_Load);
//			this->Icon = (cli::safe_cast<System::Drawing::Icon^  >(resources->GetObject(L"$this.Icon")));
			this->MaximizeBox = false;
//			this->MaximumSize = System::Drawing::Size(200, 100);
			this->MinimizeBox = false;
			this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
//			this->MinimumSize = System::Drawing::Size(200, 100);
			this->Name = L"Form1";
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
			this->Text = L"Tab名変更";
			this->KeyPreview = true;
			this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Form2::Form2_KeyDown);
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	
	//フォームロード時
	private: System::Void Form2_Load(System::Object^  sender, System::EventArgs^  e) {
				 this->nameTextBox->Text = this->GetTextBoxText();
		 }
	private: System::Void nameButton_Click(System::Object^  sender, System::EventArgs^  e) {
//				 tabPage[this->tabControl1->SelectedIndex]->Text = this->nameTextBox->Text;
				 this->Close();
			 }
			
	private: System::Void Form2_KeyDown(System::Object^  sender, System::Windows::Forms::KeyEventArgs^  e){
		 //  F2
		if(e->KeyCode == System::Windows::Forms::Keys::F2){
			this->nameTextBox->Text = "";
			this->Close();
		}
			 }
	};
}

Re:VC.netでの質問

Posted: 2009年8月16日(日) 14:03
by pooka
メインの方のTabNameSet関数で
nameForm->TextBoxSet(tabPage[this->tabControl1->SelectedIndex]->Text);
nameForm->ShowDialog(this);
この順にすれば渡せると思います。

Re:VC.netでの質問

Posted: 2009年8月16日(日) 14:46
by
できました~
ありがとうございます。