C# winForm窗体程序 锁定问题求赐教。
初始化就最小化:加个notifyIcon1到窗体,加载时候窗体就最小化:双击事件: private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) { if (this.Visible == false || this.WindowState == FormWindowState.Minimized) { //输入密码验证,比可以新建一个窗体弹出来验证,我这是一个类生成的窗体验证 bool res = Dialogs.ShowInputBox("权限验证", "请输入验证密码:", "", '*', out inputText) if(res){//验证正确 normalForm(); }else{ //验证失败 messagebox.show("验证失败"); } else { this.Visible = false; } } private void normalForm() { this.Visible = true; this.WindowState = FormWindowState.Normal; }新建一个类:类名为Dialogs: public static bool ShowInputBox(string Caption, string Tip, string DefaultText, char PasswordChar, out string inputText) { Form fm = new Form(); Label lTip = new Label(); TextBox tbInput = new TextBox(); Button btnOK = new Button(); Button btnCancel = new Button(); fm.SuspendLayout(); //Label lTip.AutoSize = true; lTip.Location = new System.Drawing.Point(13, 13); lTip.Size = new System.Drawing.Size(89, 12); lTip.TabIndex = 0; lTip.Text = Tip; //输入框 tbInput.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom; tbInput.Location = new System.Drawing.Point(15, 29); tbInput.Multiline = true; tbInput.PasswordChar = PasswordChar; tbInput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; tbInput.Size = new System.Drawing.Size(295, 21); tbInput.TabIndex = 1; tbInput.Text = DefaultText; // btnOK btnOK.Anchor = AnchorStyles.Right | AnchorStyles.Bottom; btnOK.DialogResult = System.Windows.Forms.DialogResult.OK; btnOK.Location = new System.Drawing.Point(139, 67); btnOK.Size = new System.Drawing.Size(75, 23); btnOK.TabIndex = 2; btnOK.Text = "确定"; btnOK.UseVisualStyleBackColor = true; //btnOK.Click += new EventHandler(btnOK_Click); // btnCancel btnCancel.Anchor = AnchorStyles.Right | AnchorStyles.Bottom; btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; btnCancel.Location = new System.Drawing.Point(220, 67); btnCancel.Size = new System.Drawing.Size(75, 23); btnCancel.TabIndex = 3; btnCancel.Text = "取消"; btnCancel.UseVisualStyleBackColor = true; // 窗体 fm.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); fm.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; fm.ClientSize = new System.Drawing.Size(322, 102); fm.ControlBox = false; fm.Controls.Add(btnCancel); fm.Controls.Add(btnOK); fm.Controls.Add(tbInput); fm.Controls.Add(lTip); fm.MaximizeBox = false; fm.MinimizeBox = false; fm.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; fm.Text = Caption; fm.ResumeLayout(false); fm.PerformLayout(); fm.AcceptButton = btnOK; fm.CancelButton = btnCancel; tbInput.SelectAll(); tbInput.Focus(); DialogResult dr = fm.ShowDialog(); if (dr == DialogResult.OK) { inputText = tbInput.Text; return true; } inputText = ""; return false; 我的根你差不多,只不过就一个输入框和确定按钮。
winform里textbox怎么才能设为输入密码的格式?
web控件将 TextBox 控件的 TextMode 属性设置为 Password。
在代码中,使用 TextBoxMode 枚举设置文本模式。
winform控件将 TextBox 控件的 PasswordChar 属性设置为某个特定字符。
PasswordChar 属性指定在文本框中显示的字符。
例如,如果希望在密码框中显示星号,请在“属性”窗口中将 PasswordChar 属性指定为“*”。
然后,无论用户在文本框中键入什么字符,都显示为星号。
转载请注明出处51数据库 » winform passwordchar
挂念DJQ-miss