用VB设计聚焦框程序
说明: 在以下程序中可以使Picture控件得到聚焦框,且程序调用API函数来完成。
首先,在FORM1上新建一个Picture1和一个Command1,然后输入以下代码:
Private Declare Function DrawFocusRect Lib ″
user32″ (ByVal hdc As Long, lpRect As RECT)
As Long
Private Type RECT
X1 As Long
Y1 As Long
X2 As Long
Y2 As Long
End Type
Dim lpRect As RECT ′在通用中声明调用API函数
Private Sub Form_Load()
Form1.WindowState = 2 ′最大化窗口
Picture1.Picture = LoadPicture(″C:\BMP\1.BMP″) ′请读者根据自己选择图片
Command1.Caption =″设置聚焦框″
End Sub
Private Sub Form_Activate()
Picture1.Move (Form1.ScaleWidth - Picture1.ScaleWidth) / 2,
(Form1.ScaleHeight - Picture1.ScaleHeight) /2′使Picture1居中显示
End Sub
Private Sub Command1_Click()
Dim DENG As Long
lpRect.X1 = Picture1.Left - 10
lpRect.Y1 = Picture1.Top - 10
lpRect.X2 = lpRect.X1 + Picture1.Width + 20
lpRect.Y2 = lpRect.Y1 + Picture1.Height + 20
DENG = DrawFocusRect(hdc, lpRect)
End Sub
OK,大功告成,按F5运行,通过单击按钮Command1就可以实现Picture1控件被聚焦! 当然你也可以作适当调整,使它符合你个人的需要。