C# winForm窗体程序 锁定问题求赐教。

C# winForm窗体程序 锁定问题求赐教。,第1张

初始化就最小化:

加个notifyIcon1到窗体,加载时候窗体就最小化:

双击事件:

private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)

{

if (thisVisible == false || thisWindowState == FormWindowStateMinimized)

{

//输入密码验证,比可以新建一个窗体d出来验证,我这是一个类生成的窗体验证

bool res = DialogsShowInputBox("权限验证", "请输入验证密码:", "", '', out inputText)

if(res){//验证正确

normalForm();

}else{ //验证失败

messageboxshow("验证失败");

}

else

{

thisVisible = false;

}

}

private void normalForm()

{

thisVisible = true;

thisWindowState = FormWindowStateNormal;

}

新建一个类:类名为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();

fmSuspendLayout();

//Label

lTipAutoSize = true;

lTipLocation = new SystemDrawingPoint(13, 13);

lTipSize = new SystemDrawingSize(89, 12);

lTipTabIndex = 0;

lTipText = Tip;

//输入框

tbInputAnchor = AnchorStylesLeft | AnchorStylesTop | AnchorStylesRight | AnchorStylesBottom;

tbInputLocation = new SystemDrawingPoint(15, 29);

tbInputMultiline = true;

tbInputPasswordChar = PasswordChar;

tbInputScrollBars = SystemWindowsFormsScrollBarsVertical;

tbInputSize = new SystemDrawingSize(295, 21);

tbInputTabIndex = 1;

tbInputText = DefaultText;

// btnOK

btnOKAnchor = AnchorStylesRight | AnchorStylesBottom;

btnOKDialogResult = SystemWindowsFormsDialogResultOK;

btnOKLocation = new SystemDrawingPoint(139, 67);

btnOKSize = new SystemDrawingSize(75, 23);

btnOKTabIndex = 2;

btnOKText = "确定";

btnOKUseVisualStyleBackColor = true;

//btnOKClick += new EventHandler(btnOK_Click);

// btnCancel

btnCancelAnchor = AnchorStylesRight | AnchorStylesBottom;

btnCancelDialogResult = SystemWindowsFormsDialogResultCancel;

btnCancelLocation = new SystemDrawingPoint(220, 67);

btnCancelSize = new SystemDrawingSize(75, 23);

btnCancelTabIndex = 3;

btnCancelText = "取消";

btnCancelUseVisualStyleBackColor = true;

// 窗体

fmAutoScaleDimensions = new SystemDrawingSizeF(6F, 12F);

fmAutoScaleMode = SystemWindowsFormsAutoScaleModeFont;

fmClientSize = new SystemDrawingSize(322, 102);

fmControlBox = false;

fmControlsAdd(btnCancel);

fmControlsAdd(btnOK);

fmControlsAdd(tbInput);

fmControlsAdd(lTip);

fmMaximizeBox = false;

fmMinimizeBox = false;

fmStartPosition = SystemWindowsFormsFormStartPositionCenterScreen;

fmText = Caption;

fmResumeLayout(false);

fmPerformLayout();

fmAcceptButton = btnOK;

fmCancelButton = btnCancel;

tbInputSelectAll();

tbInputFocus();

DialogResult dr = fmShowDialog();

if (dr == DialogResultOK)

{

inputText = tbInputText;

return true;

}

inputText = "";

return false;

我的根你差不多,只不过就一个输入框和确定按钮。

楼主你好~

如果是WinForm程序的话,那么可以使用TextBoxPasswordChar属性设定一个屏蔽符号,这时候输入文本框的任何信息都会被符号屏蔽,类似密码框。

如果是WPF程序,可以直接使用控件PasswordBox,使用Password属性来读取当前输入的内容。

如果楼主想要实现的是不管用户输入什么内容,文本框内不显示任何东西,但是仍然能取到文本值的话,那么请在XXXXXXChanged事件中做相应处理,似的输入值被存到一个目标中,并把文本框清空。

请追问~

以上就是关于C# winForm窗体程序 锁定问题求赐教。全部的内容,包括:C# winForm窗体程序 锁定问题求赐教。、C#中在文本框中输入的字符串怎么让它隐藏、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/10625395.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-10
下一篇 2023-05-10

发表评论

登录后才能评论

评论列表(0条)

保存