WPF登录跳转到指定页面

文章目录


<TextBox x:Name="account" Grid.Row="1" Grid.Column="1" Height="30" Width="180" FontSize="14" 
         MaxLength="20" TextBlock.LineHeight="22" TextBlock.LineStackingStrategy="BlockLineHeight" 
         Foreground="Black" BorderBrush="#0c0c0c" Margin="0 10 0 50" />
<PasswordBox x:Name="password" Grid.Row="1" Grid.Column="1" Height="30" Width="180" FontSize="14" 
             MaxLength="20" TextBlock.LineHeight="22" TextBlock.LineStackingStrategy="BlockLineHeight" 
             Foreground="Black" BorderBrush="#0c0c0c" Margin="0,40,0,20"/>
...
<Button Content="登   录" Height="30" Width="180" FontSize="12"
        Background="SkyBlue" Cursor="Hand" Foreground="White" 
        BorderBrush="SkyBlue" Grid.Column="1" Margin="0,10" Grid.Row="2"
        Click="SignIn_Click"/>
...
namespace wpfbase
{
    
    
  public partial class LoginWindow : Window
  {
    
    
    ...
    private void SignIn_Click(object sender, RoutedEventArgs e) {
    
    
      string accountstr = account.Text.ToString();
      IntPtr p = System.Runtime.InteropServices.Marshal.SecureStringToBSTR(
          password.SecurePassword);                
      string passwordstr = System.Runtime.InteropServices.Marshal.PtrToStringBSTR(p);
      if("123" == accountstr && "123" == passwordstr) {
    
    
        MessageBox.Show("登录成功!");
        MainWindow mainwindow = new MainWindow();
        mainwindow.Show();
        this.Close();
      }  
      else
        MessageBox.Show("用户不存在或密码错误!");
    }
  }
}

猜你喜欢

转载自blog.csdn.net/qq_40670171/article/details/130419008
今日推荐