C#程序设计之windows应用程序进阶

C#程序设计之windows应用程序进阶


题目描述
编写一个使用文件对话框的项目

代码

Form1.cs

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace ModeDialog
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Button btnShowDialog;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox txtOK;
		private System.Windows.Forms.TextBox txtPass;
		private System.Windows.Forms.TextBox txtNO;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label6;
		static int intTemp1;
		static int intTemp2;
		static int intTemp3;
		static int intTotal;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Label label8;
        private System.Windows.Forms.TextBox txtTotal;

		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.btnShowDialog = new System.Windows.Forms.Button();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.label8 = new System.Windows.Forms.Label();
            this.txtTotal = new System.Windows.Forms.TextBox();
            this.label7 = new System.Windows.Forms.Label();
            this.label6 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            this.txtNO = new System.Windows.Forms.TextBox();
            this.txtPass = new System.Windows.Forms.TextBox();
            this.txtOK = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label1 = new System.Windows.Forms.Label();
            this.groupBox1.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.SuspendLayout();
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.btnShowDialog);
            this.groupBox1.Location = new System.Drawing.Point(16, 8);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(272, 88);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "市场调查:";
            // 
            // btnShowDialog
            // 
            this.btnShowDialog.Location = new System.Drawing.Point(96, 40);
            this.btnShowDialog.Name = "btnShowDialog";
            this.btnShowDialog.Size = new System.Drawing.Size(72, 24);
            this.btnShowDialog.TabIndex = 0;
            this.btnShowDialog.Text = "调查";
            this.btnShowDialog.Click += new System.EventHandler(this.btnShowDialog_Click);
            // 
            // groupBox2
            // 
            this.groupBox2.Controls.Add(this.label8);
            this.groupBox2.Controls.Add(this.txtTotal);
            this.groupBox2.Controls.Add(this.label7);
            this.groupBox2.Controls.Add(this.label6);
            this.groupBox2.Controls.Add(this.label5);
            this.groupBox2.Controls.Add(this.label4);
            this.groupBox2.Controls.Add(this.txtNO);
            this.groupBox2.Controls.Add(this.txtPass);
            this.groupBox2.Controls.Add(this.txtOK);
            this.groupBox2.Controls.Add(this.label3);
            this.groupBox2.Controls.Add(this.label2);
            this.groupBox2.Controls.Add(this.label1);
            this.groupBox2.Location = new System.Drawing.Point(16, 112);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(272, 176);
            this.groupBox2.TabIndex = 1;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "调查结果:";
            // 
            // label8
            // 
            this.label8.Location = new System.Drawing.Point(240, 144);
            this.label8.Name = "label8";
            this.label8.Size = new System.Drawing.Size(24, 16);
            this.label8.TabIndex = 11;
            this.label8.Text = "人";
            // 
            // txtTotal
            // 
            this.txtTotal.Location = new System.Drawing.Point(104, 141);
            this.txtTotal.Name = "txtTotal";
            this.txtTotal.Size = new System.Drawing.Size(128, 21);
            this.txtTotal.TabIndex = 10;
            // 
            // label7
            // 
            this.label7.Location = new System.Drawing.Point(16, 141);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(64, 16);
            this.label7.TabIndex = 9;
            this.label7.Text = "总计调查:";
            // 
            // label6
            // 
            this.label6.Location = new System.Drawing.Point(240, 104);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(24, 16);
            this.label6.TabIndex = 8;
            this.label6.Text = "人";
            // 
            // label5
            // 
            this.label5.Location = new System.Drawing.Point(240, 72);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(24, 16);
            this.label5.TabIndex = 7;
            this.label5.Text = "人";
            // 
            // label4
            // 
            this.label4.Location = new System.Drawing.Point(240, 32);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(24, 16);
            this.label4.TabIndex = 6;
            this.label4.Text = "人";
            // 
            // txtNO
            // 
            this.txtNO.Location = new System.Drawing.Point(104, 104);
            this.txtNO.Name = "txtNO";
            this.txtNO.Size = new System.Drawing.Size(128, 21);
            this.txtNO.TabIndex = 5;
            // 
            // txtPass
            // 
            this.txtPass.Location = new System.Drawing.Point(104, 68);
            this.txtPass.Name = "txtPass";
            this.txtPass.Size = new System.Drawing.Size(128, 21);
            this.txtPass.TabIndex = 4;
            // 
            // txtOK
            // 
            this.txtOK.Location = new System.Drawing.Point(104, 32);
            this.txtOK.Name = "txtOK";
            this.txtOK.Size = new System.Drawing.Size(128, 21);
            this.txtOK.TabIndex = 3;
            // 
            // label3
            // 
            this.label3.Location = new System.Drawing.Point(16, 112);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(56, 16);
            this.label3.TabIndex = 2;
            this.label3.Text = "不认可:";
            // 
            // label2
            // 
            this.label2.Location = new System.Drawing.Point(16, 72);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(72, 16);
            this.label2.TabIndex = 1;
            this.label2.Text = "一般认可:";
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(16, 32);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(56, 16);
            this.label1.TabIndex = 0;
            this.label1.Text = "很认可:";
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(296, 303);
            this.Controls.Add(this.groupBox2);
            this.Controls.Add(this.groupBox1);
            this.Name = "Form1";
            this.Text = "市场调查报告";
            this.groupBox1.ResumeLayout(false);
            this.groupBox2.ResumeLayout(false);
            this.groupBox2.PerformLayout();
            this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void btnShowDialog_Click(object sender, System.EventArgs e)
		{
			ModeDialog md=new ModeDialog();
			md.ShowDialog();
			if(md.DialogResult ==DialogResult.OK)
			{
				intTotal=intTotal+1;
				this.txtTotal.Text =Convert.ToString(intTotal);
				if(md.ExchangeData.dataNO>0)
				{
					intTemp1=intTemp1+1;
				}
				//this.txtNO.Text=Convert.ToString(intAdd1(md.ExchangeData.dataNO));
				this.txtNO.Text=Convert.ToString(intTemp1);
				//this.txtOK.Text  =Convert.ToString(intAdd1(md.ExchangeData.dataOK));
				//this.txtPass.Text =Convert.ToString(intAdd1(md.ExchangeData.dataPass));
				if(md.ExchangeData.dataOK>0)
				{
					intTemp2 =intTemp2+1;
				}
				this.txtOK.Text =Convert.ToString(intTemp2);
				if(md.ExchangeData.dataPass>0)
				{
					intTemp3=intTemp3+1;
				}
				this.txtPass.Text =Convert.ToString(intTemp3);
			}
		}
		

		private int intAdd1(int intTemp)
		{
			if(intTemp==1)
			{
				intTemp=intTemp+1;				
			}	
			return intTemp;
		}		

		private void button2_Click(object sender, System.EventArgs e)
		{
			Application.Exit();
		}
	}
}

ModeDialog.cs

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace ModeDialog
{
	/// <summary>
	/// ModeDialog 的摘要说明。
	/// </summary>
	public class ModeDialog : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.RadioButton rdbOK;
		private System.Windows.Forms.RadioButton rdbPass;
		private System.Windows.Forms.RadioButton rdbNO;
		private System.Windows.Forms.Button btnOK;
		private System.Windows.Forms.Button btnCancel;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public ModeDialog()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.rdbNO = new System.Windows.Forms.RadioButton();
            this.rdbPass = new System.Windows.Forms.RadioButton();
            this.rdbOK = new System.Windows.Forms.RadioButton();
            this.btnOK = new System.Windows.Forms.Button();
            this.btnCancel = new System.Windows.Forms.Button();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.rdbNO);
            this.groupBox1.Controls.Add(this.rdbPass);
            this.groupBox1.Controls.Add(this.rdbOK);
            this.groupBox1.Location = new System.Drawing.Point(24, 24);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(240, 168);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "产品认可度调查:";
            // 
            // rdbNO
            // 
            this.rdbNO.Location = new System.Drawing.Point(24, 128);
            this.rdbNO.Name = "rdbNO";
            this.rdbNO.Size = new System.Drawing.Size(88, 24);
            this.rdbNO.TabIndex = 2;
            this.rdbNO.Text = "不认可";
            this.rdbNO.CheckedChanged += new System.EventHandler(this.rdbNO_CheckedChanged);
            // 
            // rdbPass
            // 
            this.rdbPass.Location = new System.Drawing.Point(24, 84);
            this.rdbPass.Name = "rdbPass";
            this.rdbPass.Size = new System.Drawing.Size(88, 24);
            this.rdbPass.TabIndex = 1;
            this.rdbPass.Text = "一般认可";
            this.rdbPass.CheckedChanged += new System.EventHandler(this.rdbPass_CheckedChanged);
            // 
            // rdbOK
            // 
            this.rdbOK.Location = new System.Drawing.Point(24, 40);
            this.rdbOK.Name = "rdbOK";
            this.rdbOK.Size = new System.Drawing.Size(88, 24);
            this.rdbOK.TabIndex = 0;
            this.rdbOK.Text = "很认可";
            this.rdbOK.CheckedChanged += new System.EventHandler(this.rdbOK_CheckedChanged);
            // 
            // btnOK
            // 
            this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.btnOK.Location = new System.Drawing.Point(48, 208);
            this.btnOK.Name = "btnOK";
            this.btnOK.Size = new System.Drawing.Size(72, 24);
            this.btnOK.TabIndex = 1;
            this.btnOK.Text = "提交";
            // 
            // btnCancel
            // 
            this.btnCancel.Location = new System.Drawing.Point(152, 208);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size(72, 24);
            this.btnCancel.TabIndex = 2;
            this.btnCancel.Text = "退出";
            this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
            // 
            // ModeDialog
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(292, 246);
            this.ControlBox = false;
            this.Controls.Add(this.btnCancel);
            this.Controls.Add(this.btnOK);
            this.Controls.Add(this.groupBox1);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "ModeDialog";
            this.Text = "市场调查";
            this.groupBox1.ResumeLayout(false);
            this.ResumeLayout(false);

		}
		#endregion

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private int intOK=0;
		private int intPass=0;
		private int intNO=0;

		private void rdbOK_CheckedChanged(object sender, System.EventArgs e)
		{
			if(this.rdbOK.Checked)
				this.intOK=this.intOK+1;
		}

		private void rdbPass_CheckedChanged(object sender, System.EventArgs e)
		{
			if(this.rdbPass.Checked)
				this.intPass=this.intPass+1;
		}

		private void rdbNO_CheckedChanged(object sender, System.EventArgs e)
		{
			if(this.rdbNO.Checked)
				this.intNO =this.intNO+1;
		}		

		public DataExchange ExchangeData
		{
			get
			{
				DataExchange de=new DataExchange();
				de.dataNO=this.intNO;
				de.dataOK =this.intOK;
				de.dataPass =this.intPass;
				return de;
			}
			set
			{
				DataExchange de=new DataExchange();
				de.dataNO=this.intNO;
				de.dataOK =this.intOK;
				de.dataPass =this.intPass;
				//return de;

			}
		}

	}
}

ModeDialog1.cs

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace ModeDialog
{
	/// <summary>
	/// ModeDialog1 的摘要说明。
	/// </summary>
	public class ModeDialog1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.TextBox textBox1;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public ModeDialog1()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.button1 = new System.Windows.Forms.Button();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			// 
			// button1
			// 
			this.button1.DialogResult = System.Windows.Forms.DialogResult.OK;
			this.button1.Location = new System.Drawing.Point(48, 216);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(80, 16);
			this.button1.TabIndex = 0;
			this.button1.Text = "button1";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(96, 48);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(112, 21);
			this.textBox1.TabIndex = 1;
			this.textBox1.Text = "";
			// 
			// ModeDialog1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(292, 266);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.button1);
			this.Name = "ModeDialog1";
			this.Text = "ModeDialog1";
			this.ResumeLayout(false);

		}
		#endregion

//		public string strTemp
//		{
//			get
//			{
//				return str1;
//			}
//			set
//			{
//				str1=value;
//			}
//		}
		public string str1;

		private void button1_Click(object sender, System.EventArgs e)
		{
			//this.strTemp=this.textBox1.Text;
			this.str1 =this.textBox1.Text;
		}
	}
}

运行结果
在这里插入图片描述
在这里插入图片描述

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

稚皓君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值