首页 > 代码库 > VB API 之 第十一课 绘制矩形
VB API 之 第十一课 绘制矩形
先来介绍几个画矩形的函数:
DrawFocusRect():画一个焦点矩形;
Rectangle():用当前选定的画笔描绘矩形,并用当前选定的画刷填充;
DrawEdge():用指定的样式描绘一个矩形的边框;
RoundRect():用当前选定的画笔画一个圆角矩形,并用当前选定的画刷填充。
今天用的是DrawFocusRect()函数,函数原型如下
Private Declare Function DrawFocusRect Lib "user32" Alias "DrawFocusRect"
(
ByVal hDC As Long,
lpRect As RECT
) As Long
hDc: Long //设备的句柄
lpRect: RECT结构,绘制矩形的坐标。
返回值为0,表示失败,不为0,则成功
示例:绘制矩形
Option ExplicitPrivate Type RECTLeft As LongTop As LongRight As LongBottom As LongEnd Type‘类型声明Private Declare Function DrawFocusRect Lib "user32" (ByVal hdc As Long, lpRect As RECT) As LongDim Flag As BooleanDim Start As BooleanDim Pos As RECTDim tempPos As RECTPrivate Sub Command1_Click()Flag = True‘开始绘图End SubPrivate Sub Command2_Click()Flag = FalsePicture1.Cls‘结束绘图End SubPrivate Sub Form_Load()Flag = FalseStart = False‘禁止绘图Me.ScaleMode = 3Me.Picture1.ScaleMode = 3‘设置对象坐标的度量单位为像素End SubPrivate Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)If Flag ThenStart = TruePos.Left = XPos.Top = YElseStart = FalseEnd IfEnd SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)If Start ThenDrawFocusRect Me.Picture1.hdc, Pos‘擦除原有焦点矩形Pos.Right = XPos.Bottom = YDrawFocusRect Me.Picture1.hdc, Pos‘绘制新的焦点矩形End IfEnd SubPrivate Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)If Start ThenDrawFocusRect Me.Picture1.hdc, Pos‘擦除原有焦点矩形Pos.Right = XPos.Bottom = YDrawFocusRect Me.Picture1.hdc, Pos‘绘制新的焦点矩形Start = FalseEnd IfEnd Sub
VB API 之 第十一课 绘制矩形
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。