| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 721 人关注过本帖
标题:C#问题
只看楼主 加入收藏
mextb1860
Rank: 1
等 级:新手上路
帖 子:179
专家分:0
注 册:2005-7-10
收藏
 问题点数:0 回复次数:6 
C#问题

--------------------------------------------------------------------------------------------------------------------
Form1.Designer.cs

namespace WindowsApplication5
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows 窗体设计器生成的代码

/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()

{
this.btnOK = new System.Windows.Forms.Button();
this.btnHelp = new System.Windows.Forms.Button();
this.txtName = new System.Windows.Forms.TextBox();
this.txtAddress = new System.Windows.Forms.TextBox();
this.txtAge = new System.Windows.Forms.TextBox();
this.txtOutput = new System.Windows.Forms.TextBox();
this.lblName = new System.Windows.Forms.Label();
this.lblAddress = new System.Windows.Forms.Label();
this.lblAge = new System.Windows.Forms.Label();
this.lblOutput = new System.Windows.Forms.Label();
this.rdoMale = new System.Windows.Forms.RadioButton();
this.rdoFemale = new System.Windows.Forms.RadioButton();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label();
this.cboOccupations = new System.Windows.Forms.ComboBox();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// btnOK
//
this.btnOK.Enabled = false;
this.btnOK.Location = new System.Drawing.Point(311, 12);
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(75, 23);
this.btnOK.TabIndex = 0;
this.btnOK.Text = "OK";
this.btnOK.UseVisualStyleBackColor = true;
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// btnHelp
//
this.btnHelp.Location = new System.Drawing.Point(311, 54);
this.btnHelp.Name = "btnHelp";
this.btnHelp.Size = new System.Drawing.Size(75, 23);
this.btnHelp.TabIndex = 1;
this.btnHelp.Text = "Help";
this.btnHelp.UseVisualStyleBackColor = true;
this.btnHelp.Click += new System.EventHandler(this.btnHelp_Click);
this.btnHelp.CausesValidationChanged += new System.EventHandler(this.btnHelp_Click);
//
// txtName
//
this.txtName.Location = new System.Drawing.Point(91, 12);
this.txtName.Name = "txtName";
this.txtName.Size = new System.Drawing.Size(196, 21);
this.txtName.TabIndex = 2;
this.txtName.Tag = false;
this.txtName.Validating += new System.ComponentModel.CancelEventHandler(this.txtBoxEmpty_Validating);
this.txtName.TextChanged += new System.EventHandler(this.txtBox_TextChanged);
//
// txtAddress
//
this.txtAddress.Location = new System.Drawing.Point(91, 32);
this.txtAddress.Multiline = true;
this.txtAddress.Name = "txtAddress";
this.txtAddress.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtAddress.Size = new System.Drawing.Size(196, 103);
this.txtAddress.TabIndex = 3;
this.txtAddress.Tag = false;
this.txtAddress.Validating += new System.ComponentModel.CancelEventHandler(this.txtBoxEmpty_Validating);
this.txtAddress.TextChanged += new System.EventHandler(this.txtBox_TextChanged);
//
// txtAge
//
this.txtAge.Location = new System.Drawing.Point(91, 195);
this.txtAge.Name = "txtAge";
this.txtAge.Size = new System.Drawing.Size(196, 21);
this.txtAge.TabIndex = 5;
this.txtAge.Tag = false;
this.txtAge.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtAge_KeyPress);
this.txtAge.Validating += new System.ComponentModel.CancelEventHandler(this.txtBoxEmpty_Validating);
this.txtAge.TextChanged += new System.EventHandler(this.txtBox_TextChanged);
//
// txtOutput
//
this.txtOutput.Location = new System.Drawing.Point(5, 225);
this.txtOutput.Multiline = true;
this.txtOutput.Name = "txtOutput";
this.txtOutput.ReadOnly = true;
this.txtOutput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtOutput.Size = new System.Drawing.Size(381, 139);
this.txtOutput.TabIndex = 6;
//
// lblName
//
this.lblName.AutoSize = true;
this.lblName.Location = new System.Drawing.Point(3, 12);
this.lblName.Name = "lblName";
this.lblName.Size = new System.Drawing.Size(29, 12);
this.lblName.TabIndex = 7;
this.lblName.Text = "Name";
//
// lblAddress
//
this.lblAddress.AutoSize = true;
this.lblAddress.Location = new System.Drawing.Point(3, 32);
this.lblAddress.Name = "lblAddress";
this.lblAddress.Size = new System.Drawing.Size(47, 12);
this.lblAddress.TabIndex = 8;
this.lblAddress.Text = "Address";
//
// lblAge
//
this.lblAge.AutoSize = true;
this.lblAge.Location = new System.Drawing.Point(3, 193);
this.lblAge.Name = "lblAge";
this.lblAge.Size = new System.Drawing.Size(23, 12);
this.lblAge.TabIndex = 9;
this.lblAge.Text = "Age";
//
// lblOutput
//
this.lblOutput.AutoSize = true;
this.lblOutput.Location = new System.Drawing.Point(3, 209);
this.lblOutput.Name = "lblOutput";
this.lblOutput.Size = new System.Drawing.Size(41, 12);
this.lblOutput.TabIndex = 11;
this.lblOutput.Text = "Output";
//
// rdoMale
//
this.rdoMale.AutoSize = true;
this.rdoMale.Location = new System.Drawing.Point(145, 15);
this.rdoMale.Name = "rdoMale";
this.rdoMale.Size = new System.Drawing.Size(47, 16);
this.rdoMale.TabIndex = 12;
this.rdoMale.TabStop = true;
this.rdoMale.Text = "Male";
this.rdoMale.UseVisualStyleBackColor = true;
//
// rdoFemale
//
this.rdoFemale.AutoSize = true;
this.rdoFemale.Location = new System.Drawing.Point(6, 15);
this.rdoFemale.Name = "rdoFemale";
this.rdoFemale.Size = new System.Drawing.Size(59, 16);
this.rdoFemale.TabIndex = 13;
this.rdoFemale.TabStop = true;
this.rdoFemale.Text = "Female";
this.rdoFemale.UseVisualStyleBackColor = true;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.rdoFemale);
this.groupBox1.Controls.Add(this.rdoMale);
this.groupBox1.Location = new System.Drawing.Point(5, 159);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(300, 34);
this.groupBox1.TabIndex = 16;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Sex";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(3, 138);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(71, 12);
this.label1.TabIndex = 17;
this.label1.Text = "Occupations";
//
// cboOccupations
//
this.cboOccupations.FormattingEnabled = true;
this.cboOccupations.Location = new System.Drawing.Point(91, 138);
this.cboOccupations.Name = "cboOccupations";
this.cboOccupations.Size = new System.Drawing.Size(121, 20);
this.cboOccupations.TabIndex = 18;
this.cboOccupations.KeyDown += new System.Windows.Forms.KeyEventHandler(this.cboOccupations_KeyDown);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(395, 364);
this.Controls.Add(this.cboOccupations);
this.Controls.Add(this.label1);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.lblOutput);
this.Controls.Add(this.lblAge);
this.Controls.Add(this.lblAddress);
this.Controls.Add(this.lblName);
this.Controls.Add(this.txtOutput);
this.Controls.Add(this.txtAge);
this.Controls.Add(this.txtAddress);
this.Controls.Add(this.txtName);
this.Controls.Add(this.btnHelp);
this.Controls.Add(this.btnOK);
this.Name = "Form1";
this.Text = "Form1";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Button btnHelp;
private System.Windows.Forms.TextBox txtName;
private System.Windows.Forms.TextBox txtAddress;
private System.Windows.Forms.TextBox txtAge;
private System.Windows.Forms.TextBox txtOutput;
private System.Windows.Forms.Label lblName;
private System.Windows.Forms.Label lblAddress;
private System.Windows.Forms.Label lblAge;
private System.Windows.Forms.Label lblOutput;
private System.Windows.Forms.RadioButton rdoMale;
private System.Windows.Forms.RadioButton rdoFemale;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox cboOccupations;
}
}

搜索更多相关主题的帖子: private null 资源 
2006-03-14 17:17
mextb1860
Rank: 1
等 级:新手上路
帖 子:179
专家分:0
注 册:2005-7-10
收藏
得分:0 

VS2005做的

Form1.cs

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


namespace WindowsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
LoadOccupations();
}
public override void Dispose()
{
SaveOccupation();
base.Dispose();
if (components != null)
components.Dispose();


}

private void btnOK_Click(object sender, EventArgs e)
{
string output;
output="Name:"+this.txtName.Text+"\r\n";
output += "Address:" + this.txtAddress.Text + "\r\n";
output+="Occuption:"+cboOccupations.Text+"\r\n";
output += "Sex:" + (string)(this.rdoFemale.Checked ? "Female" : "Male") + "\r\n";
output += "Age:" + this.txtAge.Text;
this.txtOutput.Text = output;
}
private void txtBoxEmpty_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
TextBox tb = (TextBox)sender;
if (tb.Text.Length == 0)
{
tb.BackColor = Color.Red;
tb.Tag = false;
}
else
{
tb.BackColor = System.Drawing.SystemColors.Window;
tb.Tag = true;
}
ValidateAll();
}

private void txtAge_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8)
e.Handled = true;
}
private void txtBox_TextChanged(object sender, System.EventArgs e)
{
TextBox tb = (TextBox)sender;
if(tb.Text.Length==0)
{
tb.Tag=false;
tb.BackColor=Color.Red;
}
else
{
tb.Tag=true;
tb.BackColor=SystemColors.Window;
}
ValidateAll();
}
private void ValidateAll()
{
this.btnOK.Enabled = ((bool)(this.txtAddress.Tag) && (bool)(this.txtAge.Tag) && (bool)(this.txtName.Tag));
}
private void btnHelp_Click(object sender, EventArgs e)
{
string output;
output = "Name=your name\r\n";
output += "Address=Your address\r\n";
output += "Programmer=Check'Programmer'if you are a programmer\r\n";
output += "Sex=Choose your sex\r\n";
output += "Ag=Your age";
this.txtOutput.Text = output;
}
private void LoadOccupations()
{
try
{
System.IO.StreamReader sr = new System.IO.StreamReader("Occupation.txt");
string input;

do
{
input = sr.ReadLine();
if (input != "")
this.cboOccupations.Items.Add(input);

} while (sr.Peek() != -1);
sr.Close();

}
catch (System.Exception)
{
MessageBox.Show("File not found");

}
}

private void cboOccupations_KeyDown(object sender, KeyEventArgs e)
{
int index = 0;
ComboBox cbo = (ComboBox)sender;
if (e.KeyCode == Keys.Enter)
index = cbo.FindStringExact(cbo.Text);
if (index < 0)
cbo.SelectedIndex = index;
e.Handled = true;

}
private void SaveOccupation()
{
try
{
System.IO.StreamWriter sw = new System.IO.StreamWriter("Occupation.txt");
foreach (string item in this.cboOccupations.Items)
sw.WriteLine(item);
sw.Flush();
sw.Close();}
catch(System.Exception)
{
MessageBox.Show("File not found or moved");



}



}


}


}

-------------------------------------------------------------------------------------------------
错误信息
错误 2 “WindowsApplication5.Form1.Dispose()”: 继承成员“System.ComponentModel.Component.Dispose()”未被标记为 virtual、abstract 或 override,无法进行重写 C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\WindowsApplication5\WindowsApplication5\Form1.cs 19 30 WindowsApplication5
-------------------------------------------------------------------------------------------------
private void cboOccupations_KeyDown(object sender, KeyEventArgs e)
{
int index = 0;
ComboBox cbo = (ComboBox)sender;
if (e.KeyCode == Keys.Enter)
index = cbo.FindStringExact(cbo.Text);
if (index < 0)
cbo.SelectedIndex = index;
e.Handled = true;

}
还有这句不能理解..是干什么用的???看不到效果


-------------------------------------------------------------------------------------------------
public override void Dispose()
{
SaveOccupation();
base.Dispose();
if (components != null)
components.Dispose();
这个意思也不懂

[此贴子已经被作者于2006-3-14 17:21:34编辑过]

2006-03-14 17:17
mextb1860
Rank: 1
等 级:新手上路
帖 子:179
专家分:0
注 册:2005-7-10
收藏
得分:0 
有人回答吗
2006-03-14 22:54
ytyt654
Rank: 2
等 级:新手上路
威 望:4
帖 子:195
专家分:0
注 册:2006-2-13
收藏
得分:0 
private void cboOccupations_KeyDown(object sender, KeyEventArgs e)
{
int index = 0;
ComboBox cbo = (ComboBox)sender;
if (e.KeyCode == Keys.Enter)
index = cbo.FindStringExact(cbo.Text);
if (index < 0)
cbo.SelectedIndex = index;
e.Handled = true;

}
查找到文本对应的索引后, 没有进一步处理.


2006-03-15 08:54
mextb1860
Rank: 1
等 级:新手上路
帖 子:179
专家分:0
注 册:2005-7-10
收藏
得分:0 
有人能回答吗
2006-03-15 12:09
mextb1860
Rank: 1
等 级:新手上路
帖 子:179
专家分:0
注 册:2005-7-10
收藏
得分:0 
这句。自己到自己的文本里找??index = cbo.FindStringExact(cbo.Text);

这句什么意思 e.Handled = true;

public override void Dispose()
{
SaveOccupation();
base.Dispose();
if (components != null)
components.Dispose();
这个意思也不懂
2006-03-16 00:47
ytyt654
Rank: 2
等 级:新手上路
威 望:4
帖 子:195
专家分:0
注 册:2006-2-13
收藏
得分:0 
e.Handled // 获取或设置一个值,该值指示是否处理过此事件。


public override void Dispose() // 释放资源
{
SaveOccupation();
base.Dispose();
if (components != null)
components.Dispose();
}

2006-03-16 08:37
快速回复:C#问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016427 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved