C# WPF 登录界面设计

一、WPF相关属性补充

①主窗体设计部分常用英文补充

Title="登录界面"   //主窗体标题

Height =300 //主窗体高度

Width=390   //主窗体宽度

WindowStyle="None" //窗体无边框

WindowStartupLocation="CenterScreen" //窗体启动初始位置居中

 ResizeMode="NoResize" //窗体不允许拖动

MouseLeftButtonDown="Window_MouseLeftButtonDown"> //给窗体注册拖动事件,(需要手动编写后台代码)

②控件部分常用补充

ImageSource //图片加载路径

Content //设置控件显示的文本

Foreground //控件显示的文字颜色

FontSize //控件显示的字体大小

Name //给控件起名字(重要)

VerticalAlignment // 垂直方向对齐

HorizontalAlignment  //水平方向对齐

BorderBrush //控件边框颜色

Background="Orange"  //设置控件显示的背景颜色

二、登录部分代码如下(xaml)


    
    
        
            
            
        
        
            

登录部分后台代码如下(cs)

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 StudentManageWPF
{
    /// 
    /// MainWindow.xaml 的交互逻辑
    /// 
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            txtLoginId.Focus();//获取焦点
        }
        /// 
        /// 无边框窗体拖动
        /// 
        /// 
        /// 
        private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);
            //获取鼠标相对标题栏位置
            Point point = e.GetPosition(this);
            if (e.LeftButton==MouseButtonState.Pressed)
            {
                if (point.X>=0&&point.X=0&&point.Y
        /// 退出按钮
        /// 
        /// 
        /// 
        private void btn_Exit_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}

运行结果:

C# WPF 登录界面设计_第1张图片

你可能感兴趣的:(WPF,c#,wpf)