没有合适的资源?快使用搜索试试~ 我知道了~
本文实例讲述了WPF设置窗体可以使用鼠标拖动大小的方法。分享给大家供大家参考。具体实现方法如下: 代码如下:private void Window_Loaded(object sender, RoutedEventArgs e) { // 获取窗体句柄 IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle; // 获得窗体的 样式 int oldstyle = NativeMethods.GetWindowLong(hwnd, NativeMethods.GWL_
资源推荐
资源详情
资源评论
WPF设置窗体可以使用鼠标拖动大小的方法设置窗体可以使用鼠标拖动大小的方法
本文实例讲述了WPF设置窗体可以使用鼠标拖动大小的方法。分享给大家供大家参考。具体实现方法如下:
代码如下:private void Window_Loaded(object sender, RoutedEventArgs e)
{
// 获取窗体句柄
IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
// 获得窗体的 样式
int oldstyle = NativeMethods.GetWindowLong(hwnd, NativeMethods.GWL_STYLE);
// 更改窗体的样式为无边框窗体
NativeMethods.SetWindowLong(hwnd, NativeMethods.GWL_STYLE, oldstyle & ~NativeMethods.WS_CAPTION);
// SetWindowLong(hwnd, GWL_EXSTYLE, oldstyle & ~WS_EX_LAYERED);
// 1 | 2 << 8 | 3 << 16 r=1,g=2,b=3 详见winuse.h文件
// 设置窗体为透明窗体
NativeMethods.SetLayeredWindowAttributes(hwnd, 1 | 2 << 8 | 3 << 16, 0, NativeMethods.LWA_ALPHA);
// 创建圆角窗体 12 这个值可以根据自身项目进行设置
NativeMethods.SetWindowRgn(hwnd, NativeMethods.CreateRoundRectRgn(0, 0, Convert.ToInt32(this.ActualWidth),
Convert.ToInt32(this.ActualHeight), 12, 12), true);
}
NativeMethods.cs的代码:
代码如下:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SEsoft
{
public class NativeMethods
{
/// <summary>
/// 带有外边框和标题的windows的样式
/// </summary>
public const int WS_CAPTION = 0X00C0000;
/// <summary>
/// window 扩展样式 分层显示
/// </summary>
public const int WS_EX_LAYERED = 0x00080000;
/// <summary>
/// 带有alpha的样式
/// </summary>
public const int LWA_ALPHA = 0x00000002;
/// <summary>
/// 颜色设置
/// </summary>
public const int LWA_COLORKEY = 0x00000001;
/// <summary>
/// window的基本样式
/// </summary>
public const int GWL_STYLE = -16;
/// <summary>
/// window的扩展样式
/// </summary>
public const int GWL_EXSTYLE = -20;
/// <summary>
/// 设置窗体的样式
/// </summary>
资源评论
weixin_38622227
- 粉丝: 4
- 资源: 936
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功