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 Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
'类型声明
Private Declare Function DrawFocusRect Lib "user32" (ByVal hdc As Long, lpRect As RECT) As Long
Dim Flag As Boolean
Dim Start As Boolean
Dim Pos As RECT
Dim tempPos As RECT
Private Sub Command1_Click()
Flag = True
'开始绘图
End Sub
Private Sub Command2_Click()
Flag = False
Picture1.Cls
'结束绘图
End Sub
Private Sub Form_Load()
Flag = False
Start = False
'禁止绘图
Me.ScaleMode = 3
Me.Picture1.ScaleMode = 3
'设置对象坐标的度量单位为像素
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Flag Then
Start = True
Pos.Left = X
Pos.Top = Y
Else
Start = False
End If
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Start Then
DrawFocusRect Me.Picture1.hdc, Pos
'擦除原有焦点矩形
Pos.Right = X
Pos.Bottom = Y
DrawFocusRect Me.Picture1.hdc, Pos
'绘制新的焦点矩形
End If
End Sub
Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Start Then
DrawFocusRect Me.Picture1.hdc, Pos
'擦除原有焦点矩形
Pos.Right = X
Pos.Bottom = Y
DrawFocusRect Me.Picture1.hdc, Pos
'绘制新的焦点矩形
Start = False
End If
End Sub

 

转载于:https://www.cnblogs.com/delphi2014/p/4035271.html

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值