winform密码加密后不能在datagridview里显示

winform密码加密后不能在datagridview里显示,第1张

winform密码加密后不能在datagridview里显示解决步骤如下:

1、点击datagridview,打开属性窗口。

2、找到RowsDefaultCellStyle,点击并且进行编辑。

3、把ForeColor设置为Black(其实数据并没有消失,只是数据被白色的背景区域遮挡了,所以设置为Black就可以解决了)。

WinForm,是·Net开发平台中对WindowsForm的一种称谓。

MD5具有很好的安全性(因为它具有不可逆的特征,加过密的密文经过解密后和加密前的东东相同的可能性极小)引用

using System.Security.Cryptography

using System.Text具体代码如下(写在按钮的Click事件里):

byte[] result = Encoding.Default.GetBytes(this.tbPass.Text.Trim()) //tbPass为输入密码的文本框

MD5 md5 = new MD5CryptoServiceProvider()

byte[] output = md5.ComputeHash(result)

this.tbMd5pass.Text = BitConverter.ToString(output).Replace("-","") //tbMd5pass为输出加密文本的文本框

初始化就最小化

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

双击事件:

private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)

{

if (this.Visible == false || this.WindowState == FormWindowState.Minimized)

{

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

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

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


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

原文地址: http://outofmemory.cn/yw/11123255.html

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

发表评论

登录后才能评论

评论列表(0条)

保存