您的位置:首页 > 其它

WPF中自定义窗体标题栏

2013-01-17 23:15 344 查看
最新文章:Virson's Blog

这个例子是在看《深入浅出WPF》第5章控件与布局的Canvas控件时,对书上的例子做了一下小扩展;在此记下,以备后用:

XAML代码:

<Window x:Class="TestCanvas.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="登录" Height="110px" Width="300px" WindowStartupLocation="CenterScreen" WindowStyle="None"
MaxHeight="110px" MaxWidth="300px" MinHeight="110px" MinWidth="300px" MouseMove="Mouse_moveHandler">
<Canvas>
<TextBlock Text="用户名:" Canvas.Left="12px" Canvas.Top="12px"/>
<TextBox Height="23px" Width="200px" BorderBrush="Black" Canvas.Left="66px" Canvas.Top="9px"/>
<TextBlock Text="密码:" Canvas.Left="12px" Canvas.Top="40.72px" Height="16px" Width="36px"/>
<TextBox Height="23px" Width="200px" BorderBrush="Black" Canvas.Left="66px" Canvas.Top="38px"/>
<Button Content="登录" Width="80px" Height="23px" Canvas.Left="66" Canvas.Top="67px"/>
<Button Content="退出" Width="80px" Height="23px" Canvas.Left="186" Canvas.Top="67px" Click="Close_clickHandler"/>
</Canvas>
</Window>


CSharp代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
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 TestCanvas
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

public void Close_clickHandler(Object sender, RoutedEventArgs e)
{
this.Close();
}

private void Mouse_moveHandler(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed&& e.Source == this) this.DragMove();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: