WPF中自定义窗体标题栏
生活随笔
收集整理的這篇文章主要介紹了
WPF中自定义窗体标题栏
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
最新文章:Virson's Blog
這個例子是在看《深入淺出WPF》第5章控件與布局的Canvas控件時,對書上的例子做了一下小擴展;在此記下,以備后用:
XAML代碼:
1 <Window x:Class="TestCanvas.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 Title="登錄" Height="110px" Width="300px" WindowStartupLocation="CenterScreen" WindowStyle="None" 5 MaxHeight="110px" MaxWidth="300px" MinHeight="110px" MinWidth="300px" MouseMove="Mouse_moveHandler"> 6 <Canvas> 7 <TextBlock Text="用戶名:" Canvas.Left="12px" Canvas.Top="12px"/> 8 <TextBox Height="23px" Width="200px" BorderBrush="Black" Canvas.Left="66px" Canvas.Top="9px"/> 9 <TextBlock Text="密碼:" Canvas.Left="12px" Canvas.Top="40.72px" Height="16px" Width="36px"/> 10 <TextBox Height="23px" Width="200px" BorderBrush="Black" Canvas.Left="66px" Canvas.Top="38px"/> 11 <Button Content="登錄" Width="80px" Height="23px" Canvas.Left="66" Canvas.Top="67px"/> 12 <Button Content="退出" Width="80px" Height="23px" Canvas.Left="186" Canvas.Top="67px" Click="Close_clickHandler"/> 13 </Canvas> 14 </Window>CSharp代碼:
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Runtime.InteropServices; 5 using System.Text; 6 using System.Threading.Tasks; 7 using System.Windows; 8 using System.Windows.Controls; 9 using System.Windows.Data; 10 using System.Windows.Documents; 11 using System.Windows.Input; 12 using System.Windows.Media; 13 using System.Windows.Media.Imaging; 14 using System.Windows.Navigation; 15 using System.Windows.Shapes; 16 17 namespace TestCanvas 18 { 19 /// <summary> 20 /// MainWindow.xaml 的交互邏輯 21 /// </summary> 22 public partial class MainWindow : Window 23 { 24 public MainWindow() 25 { 26 InitializeComponent(); 27 } 28 29 public void Close_clickHandler(Object sender, RoutedEventArgs e) 30 { 31 this.Close(); 32 } 33 34 private void Mouse_moveHandler(object sender, MouseEventArgs e) 35 { 36 if (e.LeftButton == MouseButtonState.Pressed&& e.Source == this) this.DragMove(); 37 } 38 } 39 }?
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的WPF中自定义窗体标题栏的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 服务器群集解决方案
- 下一篇: 动态创建html元素的几种方法