基本信息
源码名称:WPF 自定义标题的winform窗体实现源码
源码大小:0.14M
文件格式:.zip
开发语言:C#
更新时间:2013-10-06
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
两个属性一个事件
WindowStyle="None" 去标题
AllowsTransparency="True" 去边框
MouseMove="TitleBar_MouseMove" 鼠标拖动标题栏
// 支持标题栏拖动
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
// 获取鼠标相对标题栏位置
Point position = e.GetPosition(TitleBar);
// 如果鼠标位置在标题栏内,允许拖动
if (e.LeftButton == MouseButtonState.Pressed)
{
if (position.X >= 0 && position.X < TitleBar.ActualWidth && position.Y >= 0 && position.Y < TitleBar.ActualHeight)
{
this.DragMove();
}
}
}
<Window x:Class="WpfApplication1.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" WindowStyle="None"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" WindowStartupLocation="CenterScreen" Topmost="False"
SizeToContent="WidthAndHeight" BorderBrush="#d5d8e5" AllowsTransparency="True" >
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="150"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300"/>
</Grid.ColumnDefinitions>
<Grid Grid.Row=" 0" x:Name="TitleBar" Height="Auto" MouseMove="TitleBar_MouseMove" Background="#448dab">
<TextBlock Text="这是标题栏" FontSize="15" />
</Grid>
<Grid Grid.Row=" 1" Background="#e4e7f5"></Grid>
</Grid>
</Window>