form1.h

来自「Visual_C++.NET实用编程百例」· C头文件 代码 · 共 229 行

H
229
字号
#pragma once


namespace test
{
	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> 
	/// Form1 摘要
	///
	/// 警告: 如果您更改该类的名称,则需要更改 
	///          与该类所依赖的所有 .resx 文件关联的托管资源编译器工具的 
	///          “资源文件名”属性。  否则,
	///          设计器将不能与此窗体关联的
	///          本地化资源正确交互。
	/// </summary>
	public __gc class Form1 : public System::Windows::Forms::Form
	{	
	public:
		Form1(void)
		{
			InitializeComponent();
		}
  
	protected:
		void Dispose(Boolean disposing)
		{
			if (disposing && components)
			{
				components->Dispose();
			}
			__super::Dispose(disposing);
		}
	private: System::Windows::Forms::RadioButton *  radioButton1;
	private: System::Windows::Forms::RadioButton *  radioButton2;
	private: System::Windows::Forms::GroupBox *  groupBox1;
	private: System::Windows::Forms::GroupBox *  groupBox2;
	private: System::Windows::Forms::CheckBox *  checkBox1;
	private: System::Windows::Forms::CheckBox *  checkBox2;
	private: System::Windows::Forms::CheckBox *  checkBox3;
	private: System::Windows::Forms::Label *  label1;
	private: System::Windows::Forms::RadioButton *  radioButton3;

	private:
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		System::ComponentModel::Container * components;

		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		void InitializeComponent(void)
		{
			this->radioButton1 = new System::Windows::Forms::RadioButton();
			this->radioButton2 = new System::Windows::Forms::RadioButton();
			this->groupBox1 = new System::Windows::Forms::GroupBox();
			this->radioButton3 = new System::Windows::Forms::RadioButton();
			this->groupBox2 = new System::Windows::Forms::GroupBox();
			this->checkBox3 = new System::Windows::Forms::CheckBox();
			this->checkBox2 = new System::Windows::Forms::CheckBox();
			this->checkBox1 = new System::Windows::Forms::CheckBox();
			this->label1 = new System::Windows::Forms::Label();
			this->groupBox1->SuspendLayout();
			this->groupBox2->SuspendLayout();
			this->SuspendLayout();
			// 
			// radioButton1
			// 
			this->radioButton1->Checked = true;
			this->radioButton1->Location = System::Drawing::Point(16, 32);
			this->radioButton1->Name = S"radioButton1";
			this->radioButton1->Size = System::Drawing::Size(56, 24);
			this->radioButton1->TabIndex = 0;
			this->radioButton1->TabStop = true;
			this->radioButton1->Text = S"红色";
			this->radioButton1->CheckedChanged += new System::EventHandler(this, rb_CheckChanged);
			// 
			// radioButton2
			// 
			this->radioButton2->Location = System::Drawing::Point(84, 32);
			this->radioButton2->Name = S"radioButton2";
			this->radioButton2->Size = System::Drawing::Size(56, 24);
			this->radioButton2->TabIndex = 1;
			this->radioButton2->Text = S"绿色";
			this->radioButton2->CheckedChanged += new System::EventHandler(this, rb_CheckChanged);
			// 
			// groupBox1
			// 
			this->groupBox1->Controls->Add(this->radioButton1);
			this->groupBox1->Controls->Add(this->radioButton2);
			this->groupBox1->Controls->Add(this->radioButton3);
			this->groupBox1->Location = System::Drawing::Point(32, 64);
			this->groupBox1->Name = S"groupBox1";
			this->groupBox1->Size = System::Drawing::Size(224, 72);
			this->groupBox1->TabIndex = 2;
			this->groupBox1->TabStop = false;
			this->groupBox1->Text = S"颜色";
			// 
			// radioButton3
			// 
			this->radioButton3->Location = System::Drawing::Point(152, 32);
			this->radioButton3->Name = S"radioButton3";
			this->radioButton3->Size = System::Drawing::Size(56, 24);
			this->radioButton3->TabIndex = 5;
			this->radioButton3->Text = S"蓝色";
			this->radioButton3->CheckedChanged += new System::EventHandler(this, rb_CheckChanged);
			// 
			// groupBox2
			// 
			this->groupBox2->Controls->Add(this->checkBox3);
			this->groupBox2->Controls->Add(this->checkBox2);
			this->groupBox2->Controls->Add(this->checkBox1);
			this->groupBox2->Location = System::Drawing::Point(32, 144);
			this->groupBox2->Name = S"groupBox2";
			this->groupBox2->Size = System::Drawing::Size(224, 72);
			this->groupBox2->TabIndex = 3;
			this->groupBox2->TabStop = false;
			this->groupBox2->Text = S"字形";
			// 
			// checkBox3
			// 
			this->checkBox3->Location = System::Drawing::Point(152, 32);
			this->checkBox3->Name = S"checkBox3";
			this->checkBox3->Size = System::Drawing::Size(64, 24);
			this->checkBox3->TabIndex = 2;
			this->checkBox3->Text = S"下划线";
			this->checkBox3->CheckedChanged += new System::EventHandler(this, cb_CheckChanged);
			// 
			// checkBox2
			// 
			this->checkBox2->Location = System::Drawing::Point(84, 32);
			this->checkBox2->Name = S"checkBox2";
			this->checkBox2->Size = System::Drawing::Size(64, 24);
			this->checkBox2->TabIndex = 1;
			this->checkBox2->Text = S"斜体";
			this->checkBox2->CheckedChanged += new System::EventHandler(this, cb_CheckChanged);
			// 
			// checkBox1
			// 
			this->checkBox1->Location = System::Drawing::Point(16, 32);
			this->checkBox1->Name = S"checkBox1";
			this->checkBox1->Size = System::Drawing::Size(64, 24);
			this->checkBox1->TabIndex = 0;
			this->checkBox1->Text = S"粗体";
			this->checkBox1->CheckedChanged += new System::EventHandler(this, cb_CheckChanged);
			// 
			// label1
			// 
			this->label1->Font = new System::Drawing::Font(S"宋体", 16, (System::Drawing::FontStyle)(System::Drawing::FontStyle::Bold | System::Drawing::FontStyle::Italic));
			this->label1->Location = System::Drawing::Point(40, 24);
			this->label1->Name = S"label1";
			this->label1->Size = System::Drawing::Size(216, 24);
			this->label1->TabIndex = 4;
			this->label1->Text = S"注意字体的变化";
			// 
			// Form1
			// 
			this->AutoScaleBaseSize = System::Drawing::Size(6, 14);
			this->ClientSize = System::Drawing::Size(280, 230);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->groupBox2);
			this->Controls->Add(this->groupBox1);
			this->Name = S"Form1";
			this->Text = S"修改字体";
			this->Load += new System::EventHandler(this, Form1_Load);
			this->groupBox1->ResumeLayout(false);
			this->groupBox2->ResumeLayout(false);
			this->ResumeLayout(false);

		}	




private: System::Void rb_CheckChanged(System::Object *  sender, System::EventArgs *  e)
		 {
			 if(radioButton1->Checked)
				 label1->ForeColor = Color::Red;
			 else if(radioButton2->Checked)
				 label1->ForeColor = Color::Green;
			 else if(radioButton3->Checked)
				 label1->ForeColor = Color::Blue;
		 }

private: System::Void cb_CheckChanged(System::Object *  sender, System::EventArgs *  e)
		 {
			 if(checkBox1->Checked)
				 if(checkBox2->Checked)
					 if(checkBox3->Checked)
						 label1->Font = new System::Drawing::Font("宋体",16,(System::Drawing::FontStyle)(FontStyle::Bold | FontStyle::Italic| FontStyle::Underline));
					 else
						 label1->Font = new System::Drawing::Font("宋体",16,(System::Drawing::FontStyle)(FontStyle::Bold | FontStyle::Italic));
				 else
					 if(checkBox3->Checked)
						 label1->Font = new System::Drawing::Font("宋体",16,(System::Drawing::FontStyle)(FontStyle::Bold | FontStyle::Underline));
					 else
						 label1->Font = new System::Drawing::Font("宋体",16,(System::Drawing::FontStyle)(FontStyle::Bold ));
			 else
				 if(checkBox2->Checked)
					 if(checkBox3->Checked)
						 label1->Font = new System::Drawing::Font("宋体",16,(System::Drawing::FontStyle)( FontStyle::Italic| FontStyle::Underline));
					 else
						 label1->Font = new System::Drawing::Font("宋体",16,(System::Drawing::FontStyle)(FontStyle::Italic));
				 else
					 if(checkBox3->Checked)
						 label1->Font = new System::Drawing::Font("宋体",16,(System::Drawing::FontStyle)(FontStyle::Underline));
					 else
						 label1->Font = new System::Drawing::Font("宋体",16,(System::Drawing::FontStyle)(FontStyle::Regular));

		 }

private: System::Void Form1_Load(System::Object *  sender, System::EventArgs *  e)
		 {
			 label1->Font = new System::Drawing::Font("宋体",16,(System::Drawing::FontStyle)(FontStyle::Regular));
			 label1->ForeColor = Color::Red;
		 }

};
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?