excel VBA 窗体之拖动边界改变大小窗体 实现代码
时间:2022-10-11 15:58:14
我们已经有了一系列怎样增强 VBA 窗体的文章,VBA 的窗体和一般正常的窗体区别很大,比如就不可以通过用鼠标拖动窗体的边框,我们今天就讲讲怎样给 VBA 窗体添加这个功能。
操作如下:
◾在Excel 的VBE窗口中插入一个用户窗体,将其命名为 frmNotEnabledCloseIcon。然后再添加一个模块。在窗体和模块中添加后面所列代码。
◾在工作薄中的工作表中添加一窗体按钮控件,指定其设置宏 ShowNotEnabledCloseIconForm, 其供示范之用.
具体代码:
"frmThickFram" 窗体代码
'********************************
'---此模块演示怎样删除窗体标题栏---
www.office26.com
'********************************
'以下声明API函数
#If Win64 Then '64位
'取得窗体样式位
Private Declare PtrSafe Function GetWindowLong _
Lib "user32" _
Alias "GetWindowLongPtrA" ( _
ByVal Hwnd As LongPtr, _
ByVal nIndex As Long) _
As LongPtr
'查找窗口
Private Declare PtrSafe Function FindWindow _
Lib "user32" _
Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As LongPtr
'设置窗体样式位
Private Declare PtrSafe Function SetWindowLong _
Lib "user32" _
Alias "SetWindowLongPtrA" ( _
ByVal Hwnd As LongPtr, _
ByVal nIndex As Long, _
ByVal dwNewLong As LongPtr) _
As LongPtr
'绘制窗体标题栏
Private Declare PtrSafe Function DrawMenuBar _
Lib "user32" ( _
ByVal Hwnd As LongPtr) _
As Long
#Else
'取得窗体样式位
Private Declare Function GetWindowLong _
Lib "user32" _
Alias "GetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long) _
As Long
'查找窗口
Private Declare Function FindWindow _
Lib "user32" _
Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long
'设置窗体样式位
Private Declare Function SetWindowLong _
Lib "user32" _
Alias "SetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) _
As Long
'绘制窗体标题栏
Private Declare Function DrawMenuBar _
Lib "user32" ( _
ByVal hwnd As Long) _
As Long
#End If
#If Win64 Then '64位
Private hWndForm As LongPtr
Private FIstype As LongPtr
#Else
Private hWndForm As Long
Private FIstype As Long
#End If
'以下定义常数和变量
Private Const GWL_STYLE = (-16) '窗口样式
Private Const WS_THICKFRAME = &H40000 '可更改大小
'---关闭按钮---
Private Sub btnClose_Click()
Unload Me
End Sub
'---窗体初始化---
Private Sub UserForm_Initialize()
On Error Resume Next
'查找窗体句柄
hWndForm = FindWindow("ThunderDFrame", Me.Caption)
'取得窗体样式
FIstype = GetWindowLong(hWndForm, GWL_STYLE)
'窗体样式:原样式和可拖动边框改变大小
FIstype = FIstype Or WS_THICKFRAME
'重设窗体样式
SetWindowLong hWndForm, GWL_STYLE, FIstype
'重绘窗体标题栏
DrawMenuBar hWndForm
End Sub
"mdThickfram" 模块代码
Option Explicit '
此过程为工作表内按钮调用
Sub ShowThickFramForm()
frmThickFram.Show
End Sub
1文件名称 | 1下载链接 |
---|---|
1禁用窗体关闭按钮.zip | http://pan.baidu.com/s/1i39T4X3 |
excel VBA 窗体之拖动边界改变大小窗体 实现代码的下载地址:
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Excel2010界面指南和相对绝对引用视频教程
excel 绘图工具栏的调出和插入形状的设置
![](https://img.aspxhome.com/file/2023/6/a155136_0s.gif)
Excel表格中怎么运用函数求差
Excel表格如何设置数据的有效性 Excel表格设置数据有效性方法
![](https://img.aspxhome.com/file/2023/3/39763_0s.jpg)
Excel中设置员工生日提醒的方法
![](https://img.aspxhome.com/file/2023/5/a140105_0s.png)
wps永远关闭弹出广告的设置方法
![](https://img.aspxhome.com/file/2023/5/a163915_0s.jpg)
Win10系统System Idle Process占用率高怎么解决?
![](https://img.aspxhome.com/file/2023/6/46376_0s.png)
官方win10怎么安装?官方win10安装教程
![](https://img.aspxhome.com/file/2023/8/47598_0s.jpg)
excel三角函数使用方法
Excel怎么设置密码 1
![](https://img.aspxhome.com/file/2023/5/37585_0s.jpg)
word中怎么设置行号,word行号设置方法
WPS表格中共享工作簿功能怎么用
![](https://img.aspxhome.com/file/2023/9/a163659_0s.jpg)
在Excel单元格中输入汉字“○”的两种方法
如何在多个excel工作簿中任意切换
![](https://img.aspxhome.com/file/2023/1/a154711_0s.jpg)
神舟战神G9笔记本一键安装win11系统教程
![](https://img.aspxhome.com/file/2023/9/53339_0s.png)
Win10资源管理器占用内存高如何解决?Win10资源管理器占用内存高教程
![](https://img.aspxhome.com/file/2023/8/51698_0s.png)
Excel中如何使用数据透视表快速汇总?
![](https://img.aspxhome.com/file/2023/8/a153398_0s.jpg)
Excel函数用途.参数.用法速查表
excel2010中的时间函数运用
![](https://img.aspxhome.com/file/2023/0/38600_0s.jpg)
Word工作界面介绍:界面简介、状态栏初识与内容被覆盖?
![](https://img.aspxhome.com/file/2023/0/34260_0s.png)