取消按钮的小问题。 你的按钮里面有没有写代码this.close()?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我手上的这份程序也没有任何代码!不知道为什么,在添加this.close();是可以关闭的。 你说的 是不是打开对话框里按钮呀如是应该在打开按钮事件里写rr yy=new rr();if(yy.ShowDialog(this)==DialogResult.OK){//执行的操作}yy.Dispose(); using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using FzService.Class;namespace FzService{ /// <summary> /// frmLogin 的摘要说明。 /// </summary> public class frmLogin : System.Windows.Forms.Form { private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.ComboBox cmbUsers; private System.Windows.Forms.TextBox txtPass; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Button btnOk; private System.Windows.Forms.Button btnCancel; private string userid; private Public pc; public string UserID { get { return userid; } set { userid=value; } } /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; public frmLogin() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmLogin)); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.label1 = new System.Windows.Forms.Label(); this.txtPass = new System.Windows.Forms.TextBox(); this.cmbUsers = new System.Windows.Forms.ComboBox(); this.label2 = new System.Windows.Forms.Label(); this.btnOk = new System.Windows.Forms.Button(); this.btnCancel = new System.Windows.Forms.Button(); this.groupBox1.SuspendLayout(); this.SuspendLayout(); // // groupBox1 // this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] { this.label1, this.txtPass, this.cmbUsers, this.label2}); this.groupBox1.Location = new System.Drawing.Point(7, 0); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(289, 104); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; this.groupBox1.Text = "登录信息"; this.groupBox1.Enter += new System.EventHandler(this.groupBox1_Enter); // // label1 // this.label1.Location = new System.Drawing.Point(32, 32); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(56, 16); this.label1.TabIndex = 2; this.label1.Text = "用户名:"; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // txtPass // this.txtPass.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.txtPass.Location = new System.Drawing.Point(96, 64); this.txtPass.Name = "txtPass"; this.txtPass.PasswordChar = '#'; this.txtPass.Size = new System.Drawing.Size(144, 21); this.txtPass.TabIndex = 1; this.txtPass.Text = ""; // // cmbUsers // this.cmbUsers.Location = new System.Drawing.Point(96, 28); this.cmbUsers.Name = "cmbUsers"; this.cmbUsers.Size = new System.Drawing.Size(144, 20); this.cmbUsers.TabIndex = 0; this.cmbUsers.Text = "选择用户"; // // label2 // this.label2.Location = new System.Drawing.Point(32, 69); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(56, 16); this.label2.TabIndex = 2; this.label2.Text = "口 令:"; this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // btnOk // this.btnOk.FlatStyle = System.Windows.Forms.FlatStyle.Popup; this.btnOk.Location = new System.Drawing.Point(120, 110); this.btnOk.Name = "btnOk"; this.btnOk.TabIndex = 1; this.btnOk.Text = "确定"; this.btnOk.Click += new System.EventHandler(this.btnOk_Click); // // btnCancel // this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Popup; this.btnCancel.Location = new System.Drawing.Point(216, 110); this.btnCancel.Name = "btnCancel"; this.btnCancel.TabIndex = 2; this.btnCancel.Text = "取消"; // // frmLogin // this.AcceptButton = this.btnOk; this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.CancelButton = this.btnCancel; this.ClientSize = new System.Drawing.Size(306, 135); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.btnCancel, this.btnOk, this.groupBox1}); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "frmLogin"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "用户登录"; this.Load += new System.EventHandler(this.frmLogin_Load); this.groupBox1.ResumeLayout(false); this.ResumeLayout(false); } #endregion #region 自定义方法 /// <summary> /// 将用户列表绑定到cmbUser /// </summary> private void LoadUser() { try { pc=new Public(); DataView dv=new DataView(); dv=pc.UserEmailList("用户").Tables[0].DefaultView; dv.RowFilter="生效=1"; this.cmbUsers.DataSource=dv; this.cmbUsers.DisplayMember="用户名"; } catch(System.Exception ee) { if(MessageBox.Show(ee.Message,this.Text,MessageBoxButtons.RetryCancel,MessageBoxIcon.Warning)==DialogResult.Retry) LoadUser(); } } #endregion private void frmLogin_Load(object sender, System.EventArgs e) { LoadUser(); } private void btnOk_Click(object sender, System.EventArgs e) { if(this.txtPass.Text=="") MessageBox.Show("请输入用户口令!"); else { userid=pc.UserLogin(this.cmbUsers.Text,this.txtPass.Text.Trim()); if(userid!=null) this.DialogResult=DialogResult.OK; else { MessageBox.Show("用户名或口令错误!",this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning); this.txtPass.Focus(); } } } private void groupBox1_Enter(object sender, System.EventArgs e) { } }} 结构体中的数组 在已有的短信平台上做webservice 【杭州】我们公司招.net开发人员,有兴趣的朋友联系我啊。 c# activex 安装问题,一定给分! C# 调用麦克分学习功能 c#获取另一个窗体动态生成的控件信息 循环插入10000条记录 一个访问类成员的问题 为什么一个表不能被多次使用 装了Vs.net beat1后,我的office 2000变了限次版了,兄弟们救救我吧!!! 如何获得Text光标? 高分求好的界面和表格控件
如是应该
在打开按钮事件里写
rr yy=new rr();
if(yy.ShowDialog(this)==DialogResult.OK)
{
//执行的操作
}
yy.Dispose();
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using FzService.Class;namespace FzService
{
/// <summary>
/// frmLogin 的摘要说明。
/// </summary>
public class frmLogin : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.ComboBox cmbUsers;
private System.Windows.Forms.TextBox txtPass;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button btnOk;
private System.Windows.Forms.Button btnCancel;
private string userid;
private Public pc;
public string UserID
{
get
{
return userid;
}
set
{
userid=value;
}
}
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public frmLogin()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmLogin));
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label();
this.txtPass = new System.Windows.Forms.TextBox();
this.cmbUsers = new System.Windows.Forms.ComboBox();
this.label2 = new System.Windows.Forms.Label();
this.btnOk = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label1,
this.txtPass,
this.cmbUsers,
this.label2});
this.groupBox1.Location = new System.Drawing.Point(7, 0);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(289, 104);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "登录信息";
this.groupBox1.Enter += new System.EventHandler(this.groupBox1_Enter);
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 16);
this.label1.TabIndex = 2;
this.label1.Text = "用户名:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// txtPass
//
this.txtPass.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtPass.Location = new System.Drawing.Point(96, 64);
this.txtPass.Name = "txtPass";
this.txtPass.PasswordChar = '#';
this.txtPass.Size = new System.Drawing.Size(144, 21);
this.txtPass.TabIndex = 1;
this.txtPass.Text = "";
//
// cmbUsers
//
this.cmbUsers.Location = new System.Drawing.Point(96, 28);
this.cmbUsers.Name = "cmbUsers";
this.cmbUsers.Size = new System.Drawing.Size(144, 20);
this.cmbUsers.TabIndex = 0;
this.cmbUsers.Text = "选择用户";
//
// label2
//
this.label2.Location = new System.Drawing.Point(32, 69);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 16);
this.label2.TabIndex = 2;
this.label2.Text = "口 令:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// btnOk
//
this.btnOk.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnOk.Location = new System.Drawing.Point(120, 110);
this.btnOk.Name = "btnOk";
this.btnOk.TabIndex = 1;
this.btnOk.Text = "确定";
this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
//
// btnCancel
//
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnCancel.Location = new System.Drawing.Point(216, 110);
this.btnCancel.Name = "btnCancel";
this.btnCancel.TabIndex = 2;
this.btnCancel.Text = "取消";
//
// frmLogin
//
this.AcceptButton = this.btnOk;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.CancelButton = this.btnCancel;
this.ClientSize = new System.Drawing.Size(306, 135);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.btnCancel,
this.btnOk,
this.groupBox1});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "frmLogin";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "用户登录";
this.Load += new System.EventHandler(this.frmLogin_Load);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false); }
#endregion
#region 自定义方法
/// <summary>
/// 将用户列表绑定到cmbUser
/// </summary>
private void LoadUser()
{
try
{
pc=new Public();
DataView dv=new DataView();
dv=pc.UserEmailList("用户").Tables[0].DefaultView;
dv.RowFilter="生效=1";
this.cmbUsers.DataSource=dv;
this.cmbUsers.DisplayMember="用户名";
}
catch(System.Exception ee)
{
if(MessageBox.Show(ee.Message,this.Text,MessageBoxButtons.RetryCancel,MessageBoxIcon.Warning)==DialogResult.Retry)
LoadUser();
} }
#endregion private void frmLogin_Load(object sender, System.EventArgs e)
{
LoadUser();
} private void btnOk_Click(object sender, System.EventArgs e)
{
if(this.txtPass.Text=="")
MessageBox.Show("请输入用户口令!");
else
{
userid=pc.UserLogin(this.cmbUsers.Text,this.txtPass.Text.Trim());
if(userid!=null)
this.DialogResult=DialogResult.OK;
else
{
MessageBox.Show("用户名或口令错误!",this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
this.txtPass.Focus();
}
}
} private void groupBox1_Enter(object sender, System.EventArgs e)
{
}
}
}