• WPF小笔记-Popup拖动


    查看了下MSDN发现Popup没有类拟Drag相关的属性和方法,第一时间想了thumb。忙了一会未果,就想起了强大的google。

    发现中文资料很少,英文的发现有两篇很不错的,所以笔记在博客园里,希望对园里的朋友有用。

    social.msdm

    stackoverflow

    楼主推荐使用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!

  • 相关阅读:
    MYSQL
    Oracle建立表空间和用户
    oracle创建表空间
    MySQL数据库远程连接开启方法
    linux mkfs命令参数及用法详解---linux格式化文件系统命令(包括swap分区)
    小峰Hibernate简介与HelloWorld
    数据结构与算法JavaScript描述——链表
    数据结构与算法JavaScript描述——使用队列
    数据结构与算法JavaScript描述——队列
    数据结构与算法JavaScript描述——栈的使用
  • 原文地址:https://www.cnblogs.com/lisweden/p/3183476.html
Copyright © 2020-2023  润新知