最近研究一下wpf ,wpf确实很强大、很炫, 简单做个注册功能,下面用到了 passwordBox 控件
前台代码
<Window x:Class="Main.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="注册" Height="350" Width="530" WindowStartupLocation="CenterScreen" ResizeMode="NoResize"> <Grid > <Label Width="70" Height="30" Content="登陆姓名:" Margin="115,93,323,188" /> <TextBox Background="Yellow" Name="txtName" Margin="205,101,114,191" FontSize="20" /> <Label Content="登陆密码:" Height="30" Margin="115,148,323,133" Width="70" /> <PasswordBox HorizontalAlignment="Left" Margin="205,148,0,141" Name="txtPwd" FontSize="20" Width="202" Background="Yellow" /> <Button Content="注册" Background="GreenYellow" Name="btnLogin" Height="30" Width="60" Margin="205,222,243,59" Click="btnLogin_Click" /> <Button Background="GreenYellow" Content="重置" Height="30" Margin="334,222,114,59" Name="btnReset" Width="60" />
登陆按钮里面的事件
/// <summary> /// 登陆事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLogin_Click(object sender, RoutedEventArgs e) { if (this.txtName.Text.Trim().ToString() != "" && this.txtPwd.SecurePassword.ToString().Trim() != "") { userInfo info = new userInfo(); info.UserName = this.txtName.Text.Trim().ToString();
// 使用一个IntPtr类型值来存储加密字符串的起始点 IntPtr p = System.Runtime.InteropServices.Marshal.SecureStringToBSTR(this.txtPwd.SecurePassword); // 使用.NET内部算法把IntPtr指向处的字符集合转换成字符串 string password = System.Runtime.InteropServices.Marshal.PtrToStringBSTR(p); info.UserPwd = password; userInfoManager um = new userInfoManager(); int count = um.AdduserInfo(info); if (count > 0) { MessageBox.Show("注册成功!"); } else { MessageBox.Show("注册失败!"); } } else { MessageBox.Show("用户名或密码为空!"); }
}
</Grid></Window>
---------------------
作者:阿呆0123
来源:CSDN
原文:https://blog.csdn.net/pengfeihe0123/article/details/5985219
版权声明:本文为博主原创文章,转载请附上博文链接!
WPF之PasswordBox用法
猜你喜欢
转载自blog.csdn.net/Andrewniu/article/details/83305914
今日推荐
周排行