作者:绿色风
分类:
时间:2022-08-17
浏览:164
楼主 xmyjk |
Q:如何运用VBA在窗体里面画画?
A:用运用API调用GDI函数咯。 效果如图
- Option Explicit
- Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
- Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
- Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
- Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long '
- Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
- Private Declare Function Ellipse Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
- Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
- Private Sub CommandButton1_Click()
- Dim Dc As Long, Pen As Long, Color As Long
- Dc = GetDC(FindWindow(vbNullString, UserForm1.Caption)) '获取窗体的上下文设备
- Pen = CreatePen(0, 1, vbRed) '创建红色钢笔,用钢笔画边框
- Color = CreateSolidBrush(vbBlack) '创建黑色画刷,用画填充实体
- SelectObject Dc, Pen '将钢笔放入上下文设备
- SelectObject Dc, Color '将画刷放入上下文设备
- Ellipse Dc, 150 - 100, 150 - 100, 150 + 100, 150 + 100 '开始画画,并设置坐标位置和圆的内径
- DeleteObject Pen '删除钢笔
- DeleteObject Color '删除画刷
- End Sub
画圆.zip |
2楼 い卋玑┾宝珼 |
继续 学习API |
3楼 老糊涂 |
学习 |
免责声明
有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素,
经与ExcelTip.Net站长Apolloh商议并征得其同意,
现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示,
供有需要的人士查询使用,也慰缅曾经的论坛时代。
所示各个帖子的原作者如对版权有异议,
可与本人沟通提出,或于本站点留言,我们会尽快处理。
在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一