Wpf 实现登陆窗口

来源:互联网 发布:动态桌面主题下载软件 编辑:程序博客网 时间:2024/05/20 19:15

首先先来看一下效果图
这里写图片描述

这个是一个二次元风格的登陆窗口。
先来看一个窗口的布局文件。

<Window x:Class="QQDemo1.MainWindow"        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        Title="MainWindow" Height="634" Width="737" Loaded="Window_Loaded" Name="winmain">    <!--引用动画资源-->    <Window.Resources>                    <!--表示太阳的动画资源-->        <Storyboard x:Key="sunRote">            <!--Forener不停旋转-->                              <!--旋转角度-->  <!--旋转的频率-->          <!--需要添加旋转的对象-->       <!--以角度的方式旋转-->            <DoubleAnimation RepeatBehavior="Forever"  From="0" To="360" Duration="0:0:5" Storyboard.TargetName="sunImg" Storyboard.TargetProperty="RenderTransform.Angle"></DoubleAnimation>                                                      <!--运动的起始结束位置-->                                                       <!--向左移动-->               <!--是否来回播放-->            <DoubleAnimation RepeatBehavior="Forever" From="0" To="395" Duration="0:0:10" Storyboard.TargetName="sunImg" Storyboard.TargetProperty="(Canvas.Left)" AutoReverse="True"></DoubleAnimation>                                                                                                                             <!--当前控件的不透命度-->                                    <DoubleAnimation RepeatBehavior="Forever" From="1" To="0" Duration="0:0:10" Storyboard.TargetName="sunImg" Storyboard.TargetProperty="Opacity"></DoubleAnimation>            <!--多个点之间的动画效果-->            <DoubleAnimationUsingKeyFrames Storyboard.TargetName="wwImg" RepeatBehavior="Forever" Storyboard.TargetProperty="RenderTransform.Angle">                <!--设置当前控件的角度-->       <!--时间间隔-->                <EasingDoubleKeyFrame Value="10" KeyTime="0:0:2"></EasingDoubleKeyFrame>                <EasingDoubleKeyFrame Value="30" KeyTime="0:0:4"></EasingDoubleKeyFrame>                <EasingDoubleKeyFrame Value="0" KeyTime="0:0:6"></EasingDoubleKeyFrame>                <EasingDoubleKeyFrame Value="-30" KeyTime="0:0:8"></EasingDoubleKeyFrame>              </DoubleAnimationUsingKeyFrames>            <!--当前控件从右向左移动-->            <DoubleAnimation RepeatBehavior="Forever" From="0" To="-350" Duration="0:0:10" Storyboard.TargetName="wwImg" Storyboard.TargetProperty="(Canvas.Left)" AutoReverse="True"></DoubleAnimation>        </Storyboard>    </Window.Resources>    <!--触发-->    <Window.Triggers>                      <!--表示在加载的时候触发动画效果-->        <EventTrigger RoutedEvent="Loaded">                            <!--触发哪一个的动画的资源-->            <BeginStoryboard Storyboard="{StaticResource sunRote}"></BeginStoryboard>        </EventTrigger>    </Window.Triggers>    <Canvas Width="474" Height="505">                                                                     <!--表示图片的位置-->   <!--执行动画的中心坐标-->                 <Image Name="wwImg" Width="100" Height="128" Margin="374,-55" Source="Images/ww.png" RenderTransformOrigin="0.5,0.5" Canvas.Left="-23" Canvas.Top="14">            <!--当动画需要角度的改变时,需要在对应的动画里面进行声明-->            <Image.RenderTransform>                <RotateTransform></RotateTransform>            </Image.RenderTransform>        </Image>        <!--最大化和最小化的按钮 Panel.ZIndex 表示当前对象的显示布局 Maegin 当前对象的布局--><!--背景颜色-->                          <!--向当前对象添加Text 字体的宽度-->  <!--按钮的单击时间-->        <Button Width="40" Height="20" Margin="360,53" Panel.ZIndex="1" Background="#623D6A" Foreground="White" Content="Min" FontWeight="SemiBold" Click="Button_Click_1"></Button>        <Button Width="40" Height="20" Margin="405,53" Panel.ZIndex="1" Background="#623D6A" Foreground="White" Content="Tchu" FontWeight="SemiBold" Click="Button_Click"></Button>        <Image Source="Images/Sun.png" Name="sunImg" RenderTransformOrigin="0.5,0.5" Width="100">            <Image.RenderTransform>                <RotateTransform>                </RotateTransform>            </Image.RenderTransform>        </Image>        <!--当需要添加图片作为背景是,需要将图片放置在一个Border里面 然后利用Image 便签添加需要的图片 须记住图片的宽度略小于Border的宽度 -->        <Border Width="400" Height="310" Background="#87E5F1" Name="Border1"  CornerRadius="10" Canvas.Left="50" Canvas.Top="50"></Border>        <Border Width="400" Height="145" Margin="50" Background="#522963" CornerRadius="10">            <Image Width="395" Height="145" Margin="0,1" Source="/QQDemo1;component/Images/0b55b319ebc4b745dafde012cdfc1e178a82154c.jpg" Stretch="Fill"></Image>        </Border>        <Label Width="50" Height="30" Margin="120,210" Content="账号:"></Label>        <!--当需要添加下划线的时候,不能用Label 标签-->                                                                        <!--添加文字下划线-->       <!--鼠标的点击事件-->        <TextBlock Name="zhuce" Width="60" Height="30" Margin="336,215" TextDecorations="Underline" MouseUp="TextBlock_MouseUp"> 注册账号</TextBlock>        <Label Width="50" Height="30" Margin="120,260" Content="密码:"></Label>        <TextBlock Name="wangji" Width="60" Height="30" Margin="336,265" TextDecorations="Underline" MouseUp="wangji_MouseUp"> 忘记密码</TextBlock>        <Border Width="150" Height="30" Margin="180,210" Background="White" CornerRadius="15">            <!--当需要文本框的边框有弧度的时候,需要添加Border 标签 改变CornerRadius的值来改变弧度的大小-->            <TextBox MaxLength="13" Name="Username" Width="130" Height="25" BorderThickness="0" Margin="0,5" Text="电话/邮箱/微博账号"   TextBlock.FontFamily="幼圆" MouseEnter="TextBox_MouseEnter" MouseLeave="Username_MouseLeave">            </TextBox>        </Border>        <Border Width="150" Height="30" Margin="180,260" Background="White" CornerRadius="15">            <!--在wfc中 密码框有其特定的格式-->                                     <!--用来改变密码框输入文字的样式-->            <PasswordBox Name="Password" Width="130" Height="25" BorderThickness="0" MaxLength="20" PasswordChar="*" Margin="0,5">            </PasswordBox>        </Border>        <CheckBox Margin="148,298" Content="记住账号"></CheckBox>        <CheckBox Margin="299,298" Content="自动登陆"></CheckBox>        <Button Width="200" Margin="160,319"  Content="登陆" Background="#63BD21" Foreground="Wheat" FontSize="16" FontFamily="KaiTi" FontWeight="UltraBold"  Height="30" Click="Button_Click_2"></Button>        <!--在wpf中需要取得当前控件的属性,通过设定name的值在后台代码中去调用-->    </Canvas></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;namespace QQDemo1{    /// <summary>    /// MainWindow.xaml 的交互逻辑    /// </summary>    public partial class MainWindow : Window    {        public MainWindow()        {            InitializeComponent();            this.WindowStyle = System.Windows.WindowStyle.None;//去掉边框            this.AllowsTransparency = true;//透明            this.Background = Brushes.Transparent;//背景透明5            this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;        }        String username = "";        String password = "";        private void TextBox_MouseEnter(object sender, MouseEventArgs e)        {            this.Username.Text = username;                this.Username.Text = "";        }        private void Window_Loaded(object sender, RoutedEventArgs e)        {            //this.Border1.            this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;        }        private void Username_MouseLeave(object sender, MouseEventArgs e)        {            username = this.Username.Text;            this.Username.Text = username;            if (this.Username.Text == "")            {                this.Username.Text = "电话/邮箱/微博账号";            }            else            {                this.Password.Password = "";            }        }        private void Button_Click(object sender, RoutedEventArgs e)        {            //this.winmain.WindowState = System.Windows.WindowState.Maximized;            this.Close();                   }        private void Button_Click_1(object sender, RoutedEventArgs e)        {            this.winmain.WindowState = System.Windows.WindowState.Minimized;        }        private void Button_Click_2(object sender, RoutedEventArgs e)        {            this.username = this.Username.Text;            this.password = this.Password.Password;            if (username == (18892080098).ToString() && password == (123456).ToString())            {                Demo2 d = new Demo2();                d.Show();            }            else            {                MessageBox.Show("用户名或者密码错误", "警告");            }        }        private void TextBlock_MouseUp(object sender, MouseButtonEventArgs e)        {                Demo2 d = new Demo2();                d.Show();            //MessageBox.Show("嘿嘿!就是不让你注册", "警告");        }        private void wangji_MouseUp(object sender, MouseButtonEventArgs e)        {            //MessageBox.Show("密码都记不住,你能干啥!重新注册吧!", "警告");            DateTimew t = new DateTimew();            t.Show();        }    }}
0 0
原创粉丝点击