wpf仿qq登录框处女作,未完成稿

登录框部分

界面代码

<Window x:Class="exam.LoginMain"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApplication1"
        mc:Ignorable="d"
        WindowStyle="None"
        AllowsTransparency="False"
        Background="Transparent"
        OpacityMask="White"
        ResizeMode="NoResize"
        Title="无纸化在线考试系统" Height="365" Width="430">
    <DockPanel >
        <StackPanel DockPanel.Dock="Top" Height="365" VerticalAlignment="Top" >
            <Grid  Background="#0098d2" Height="184" Name="title_bar">
                <Grid.RowDefinitions>
                    <RowDefinition Height="30"/>
                    <RowDefinition Height="154"/>
                </Grid.RowDefinitions>
                <Grid HorizontalAlignment="Right" FlowDirection="RightToLeft">
                    <Button x:Name="login_close" Margin="5,0,0,0" HorizontalAlignment="Right" Width="15" Height="15" Click="close_login" Cursor="Hand">
                        <Button.Style>
                            <Style TargetType="{x:Type Button}">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type Button}">
                                            <Image Name="login_close" Source="/images/close.png" />
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </Button.Style>
                    </Button>
                </Grid>
                <Grid Grid.Row="1" >
                    <Image x:Name="logo_png" Width="200" Height="100" Source="images/logo.png" Stretch="Fill"/>
                </Grid>
            </Grid>
            <Grid  Background="#ffffff" Height="156">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="35"/>
                    <ColumnDefinition Width="80"/>
                    <ColumnDefinition Width="200" />
                    <ColumnDefinition Width="65" />
                    <ColumnDefinition Width="15" />
                    <ColumnDefinition Width="35" />
                </Grid.ColumnDefinitions>
                <Grid>
                    <Button x:Name="add_user" HorizontalAlignment="Center" VerticalAlignment="Bottom" Width="23" Height="23" Click="user_add" Margin="0,0,0,5">
                        <Button.Style>
                            <Style TargetType="{x:Type Button}">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type Button}">
                                            <Image Name="add_user" Source="/images/adduser.png" />
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </Button.Style>
                    </Button>
                </Grid>
                <Grid Grid.Column="1" VerticalAlignment="Top" >
                    <Border BorderThickness="0" BorderBrush="#ffffff" CornerRadius="3" Margin="0,12,0,0" Width="65" Height="65">
                        <Image x:Name="nologin_face" Source="Images/nologin_face.jpg" Width="65" Height="65"  />
                    </Border>
                </Grid>
                <Grid Grid.Column="2" VerticalAlignment="Top" HorizontalAlignment="Center" >
                    <StackPanel Orientation="Vertical" VerticalAlignment="Stretch">
                        <Border BorderBrush="#d1d1d1"  Margin="0,12,0,0" BorderThickness="1" CornerRadius="3" Width="194">
                            <StackPanel Orientation="Vertical" VerticalAlignment="Stretch">
                                <TextBox x:Name="user_name" Width="194"  Height="32.5" BorderThickness="0" GotFocus="user_name_GotFocus" LostFocus="user_name_LostFocus" Padding="5,9,5,5" MaxLength="20" VerticalAlignment="Center" Foreground="#333333">用户名/工号/工作QQ</TextBox>
                                <PasswordBox x:Name="user_password" Width="194" Height="32.5" Padding="5,9,5,5" BorderThickness="0,1,0,0" BorderBrush="#d1d1d1" VerticalAlignment="Center"/>
                            </StackPanel>
                        </Border>
                        <Grid VerticalAlignment="Center" Height="25" Margin="0,3,0,0" Width="192">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="96"></ColumnDefinition>
                                <ColumnDefinition Width="96"></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <Grid Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left">
                                <CheckBox Content="记住密码" FontSize="13"></CheckBox>
                            </Grid>
                            <Grid Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Right">
                                <CheckBox Content="自动登录" FontSize="13"></CheckBox>
                            </Grid>
                        </Grid>
                        <Grid VerticalAlignment="Center" Height="30" Width="192" Margin="0,7,0,0">
                            <Border BorderBrush="#09a3dc" BorderThickness="1" CornerRadius="3">
                                <Button x:Name="login_btn"  HorizontalAlignment="Center" VerticalAlignment="Center" Width="194" Height="32" Click="login_btn_Click"  Cursor="Hand" Content="登 录">
                                    <Button.Style>
                                        <Style TargetType="{x:Type Button}">
                                            <Setter Property="Background" Value="#09a3dc"/>
                                            <Setter Property="BorderBrush" Value="#09a3dc"/>
                                            <Setter Property="FontSize" Value="14"/>
                                            <Setter Property="Foreground" Value="#ffffff"/>
                                            <Setter Property="BorderThickness" Value="0"/>
                                            <Setter Property="HorizontalContentAlignment" Value="Center"/>
                                            <Setter Property="VerticalContentAlignment" Value="Center"/>
                                            <Setter Property="Padding" Value="0"/>
                                        </Style>
                                    </Button.Style>
                                </Button>
                            </Border>
                        </Grid>
                    </StackPanel>
                </Grid>
            </Grid>
            <Grid  Background="#f9f4d5" Height="25">
               
            </Grid>
        </StackPanel>
    </DockPanel>
</Window>


后台逻辑

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 exam
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class LoginMain : Window
    {
        public LoginMain()
        {
            InitializeComponent();
        }
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);
            // 获取鼠标相对标题栏位置  
            Point position = e.GetPosition(title_bar);
            // 如果鼠标位置在标题栏内,允许拖动  
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                if (position.X >= 0 && position.X < title_bar.ActualWidth && position.Y >= 0 && position.Y < title_bar.ActualHeight)
                {
                    this.DragMove();
                }
            }
        }
        private void close_login(object sender, RoutedEventArgs e)
        {
            Application.Current.MainWindow.Close();
        }
        private void user_add(object sender, RoutedEventArgs e)
        {
            Application.Current.MainWindow.Close();
        }
        private void login_btn_Click(object sender, RoutedEventArgs e)
        {
            var un = user_name.Text;
            var pw = user_password.Password;
            MessageBox.Show("帐号:"+un + "密码:" + pw);
        }
        void user_name_GotFocus(object sender, RoutedEventArgs e)
        {
            var un = user_name.Text;
            if (un == "用户名/工号/工作QQ")
            {
                user_name.Clear();
            }
        }
        private void user_name_LostFocus(object sender, RoutedEventArgs e)
        {
            var un = user_name.Text;
            if (un =="" )
            {
                user_name.Text = "用户名/工号/工作QQ";
            }
          
        }
    }
}


原文链接:,转发请注明来源!
「wpf仿qq登录框处女作,未完成稿」评论列表

发表评论