110,534
社区成员
发帖
与我相关
我的任务
分享
private void Button_Click(object sender, RoutedEventArgs e)
{
if (txtBox1.Text.Trim() == "userName")
{
if (txtBox2.Text.Trim() == "passWord")
{
MainWindow window = new MainWindow();
window.Show();
this.Close();
}
else
{
MessageBox.Show("密码不正确");
}
}
else
{
MessageBox.Show("用户名不正确");
}
}
if(账号密码不正确)
{
LoginMessage box = new LoginMessage();
box.Title = "温馨提示!";
box.Message = "您输入的账号密码不正确!";
box.ShowDialog();
}
<Window x:Class="WpfApplication1.LoginMessage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
x:Name="window"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="LoginMessage" AllowsTransparency="True" WindowStyle="None" Background="Transparent" WindowStartupLocation="CenterScreen" ClipToBounds="False" Topmost="True" Height="400" Width="600">
<Window.Resources>
<Storyboard x:Key="WindowsEnterStoryboard">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="grid">
<EasingDoubleKeyFrame KeyTime="0" Value="-600"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="WindowsLeaveStoryboard">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="grid">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="-600"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<Window.Triggers>
<EventTrigger RoutedEvent="Loaded" SourceName="window">
<BeginStoryboard x:Name="WindowsEnterStoryboard_BeginStoryboard" Storyboard="{StaticResource WindowsEnterStoryboard}"/>
</EventTrigger>
</Window.Triggers>
<Grid x:Name="grid" RenderTransformOrigin="0.5,0.5">
<Grid.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform />
</TransformGroup>
</Grid.RenderTransform>
<Border BorderBrush="Gray" BorderThickness="10" CornerRadius="10" Background="DarkGray">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="15,0">
<Image Source="{Binding RelativeSource={RelativeSource AncestorType=Window,Mode=FindAncestor},Path=ImageSource}" Height="60" />
<TextBlock HorizontalAlignment="Center" Foreground="White" Text="{Binding RelativeSource={RelativeSource AncestorType=Window,Mode=FindAncestor},Path=Title}" FontSize="30" />
<TextBlock HorizontalAlignment="Center" Foreground="White" Text="{Binding RelativeSource={RelativeSource AncestorType=Window,Mode=FindAncestor},Path=Message}" FontSize="26" TextWrapping="Wrap"/>
</StackPanel>
<Button Content="确定" Grid.Row="1" Margin="30" Width="200" Height="50" Click="Button_Click"/>
</Grid>
</Border>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
namespace WpfApplication1
{
/// <summary>
/// LoginMessage.xaml 的交互逻辑
/// </summary>
public partial class LoginMessage : Window
{
private Storyboard _leaveStroy;
public Storyboard LeaveStory
{
get
{
if (_leaveStroy == null)
{
_leaveStroy= this.Resources["WindowsLeaveStoryboard"] as Storyboard;
_leaveStroy.Completed += new EventHandler(_leaveStroy_Completed);
}
return _leaveStroy;
}
set { _leaveStroy = value; }
}
void _leaveStroy_Completed(object sender, EventArgs e)
{
this.Close();
}
public LoginMessage()
{
InitializeComponent();
}
public string Message
{
get { return (string)GetValue(MessageProperty); }
set { SetValue(MessageProperty, value); }
}
public static readonly DependencyProperty MessageProperty =
DependencyProperty.Register("Message", typeof(string), typeof(LoginMessage), new UIPropertyMetadata("注意!"));
public ImageSource ImageSource
{
get { return (ImageSource)GetValue(ImageSourceProperty); }
set { SetValue(ImageSourceProperty, value); }
}
public static readonly DependencyProperty ImageSourceProperty =
DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(LoginMessage), new UIPropertyMetadata(null));
private void Button_Click(object sender, RoutedEventArgs e)
{
this.LeaveStory.Begin();
}
public void CustomerClose()
{
this.LeaveStory.Begin();
}
}
}