WPF小笔记-Popup拖动
2024-08-24 16:12:12
查看了下MSDN发现Popup没有类拟Drag相关的属性和方法,第一时间想了thumb。忙了一会未果,就想起了强大的google。
发现中文资料很少,英文的发现有两篇很不错的,所以笔记在博客园里,希望对园里的朋友有用。
楼主推荐使用social.msdm的方法,试过很好用:
<Popup Name="puSkills" Placement="MousePoint" PopupAnimation="Scroll" AllowsTransparency="True" IsEnabled="True" IsOpen="False">
<Border BorderBrush="DarkCyan" BorderThickness="3">
<StackPanel Background="AliceBlue" VerticalAlignment="Center" Height="400" Width="400">
<Label Name="lblCaption" FontWeight="Bold" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="Blue" Background="Blue" MouseLeftButtonDown="lblCaption_MouseLeftButtonDown">Move</Label>
<StackPanel> <TextBlock HorizontalAlignment="Right">
Some Contents...........
</TextBlock>
</StackPanel>
</StackPanel>
</Border>
</Popup>
后台CS代码:
[DllImport("user32.dll")]
public static extern IntPtr WindowFromPoint(POINT Point); [DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetCursorPos(out POINT lpPoint); [DllImportAttribute("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); [DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture(); [StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int X;
public int Y;
} public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2; private void lblCaption_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
POINT curPos;
IntPtr hWndPopup; GetCursorPos(out curPos);
hWndPopup = WindowFromPoint(curPos); ReleaseCapture();
SendMessage(hWndPopup, WM_NCLBUTTONDOWN, new IntPtr(HT_CAPTION), IntPtr.Zero);
}
Click the Move Content in label.. then move the mouse. Thank you!
最新文章
- Intellij idea 和android studio 代码给混淆
- GOLANG SDK下载
- VS中Qt的探索02
- 深入浅出设计模式——解释器模式(Interpreter Pattern)
- 调用存储过程从EntityFramework
- zzuli oj 1165 实数的小数部分(指针专题)
- Struts2 文件的上传与下载
- C语言初学 俩数相除问题
- 去确认CP210x UART Bridge的USB的VID和PID
- Callable 获取线程返回值
- opencv在arm和x86在移植
- VS调试的简单技巧
- [kuangbin带你飞]专题四 最短路练习 POJ 2253 Frogger
- qt实现一个简单的计算器
- mysql常用脚本及命令记录
- sql server 锁与事务拨云见日(下)
- Angular学习第一步
- Makefile依赖关系中的竖线“|”
- Node的关系型数据库ORM库:bookshelf
- PAT甲题题解-1029. Median (25)-求两序列的中位数,题目更新了之后不水了
热门文章
- OpenCV编译步骤
- ag
- ios开发视频播放后台下载功能实现 :1,ios播放视频 ,包含基于AVPlayer播放器,2,实现下载,iOS后台下载(多任务同时下载,单任务下载,下载进度,下载百分比,文件大小,下载状态)(真机调试功能正常)
- [TypeScript] Using ES6 and ESNext with TypeScript
- iOS 取消多余tableView的横线的写法
- java开发环境配置(windows下JDK7+tomcat7)
- Azure Messaging-ServiceBus Messaging
- SWFTools PDF转换为SWF
- 将 WPF、UWP 以及其他各种类型的旧 csproj 迁移成基于 Microsoft.NET.Sdk 的新 csproj
- rabbitmq集群 + Mirror Queue + 使用C#