C#程序设计之windows应用程序进阶
Posted shangzh!
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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以上是关于C#程序设计之windows应用程序进阶的主要内容,如果未能解决你的问题,请参考以下文章