VB 如何在屏幕上 画一个红色边框 并随鼠标移动? 25

程序中我用API函数Rectangle在屏幕上画的边框。请问如何让它在屏幕上并随鼠标移动?(不要把VB窗体全屏化了模拟屏幕)因为我的桌面是动态桌面所以不要锁屏哦!我QQ2... 程序中我用 API函数Rectangle 在屏幕上画的边框。请问 如何让它在屏幕上 并随鼠标移动?(不要把VB窗体全屏化了模拟屏幕) 因为我的桌面是动态桌面 所以不要锁屏哦!我QQ271072330
不要把VB 窗体透明了 覆盖屏幕 也不要挖空窗体搞成边框 也不要用四个VB窗体代替四边来代替边框 因为以上几种太浪费资源了 我就想用Rectangle画上去 再用个函数擦除!
展开
 我来答
sohostars
2008-11-12 · TA获得超过226个赞
知道小有建树答主
回答量:691
采纳率:0%
帮助的人:421万
展开全部
把窗体的图象整个储存在一个bitmap里或者直接储存在显存里,然后鼠标移动时先用bitmap画窗体,再画框,这样是占用资源最少的。用.net的System.Drawing里的画图功能或者directX去做这件事情。
实际上所谓的擦除就是重新画一张背景,然后再背景上画移动的东西,和我们平时写字然后搽掉的概念不同的,显卡显示的方式都是一块一块的图案往上贴而已。就是说实际上擦除只是在后台把背景画一次,然后再上面再画移动的东西,然后再把这个画好的合成图案再画到前台显示出来
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
feiyangqingyun
2008-11-12 · TA获得超过393个赞
知道小有建树答主
回答量:350
采纳率:0%
帮助的人:284万
展开全部
这是按钮随鼠标移动的代码,你可以修改一下就可以了。

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Command1.Left = X
Command1.Top = Y
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
し★Ve→ME
2008-11-12 · 超过44用户采纳过TA的回答
知道答主
回答量:132
采纳率:0%
帮助的人:0
展开全部
留个脚印
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
ljl88900
2008-11-12 · TA获得超过2661个赞
知道大有可为答主
回答量:2197
采纳率:100%
帮助的人:2634万
展开全部
'在窗体上加入控件timer1,然后复制下面代码,运行即可。

Option Explicit

Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject 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 Rectangle 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 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 GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function SetROP2 Lib "gdi32.dll" (ByVal hdc As Long, ByVal nDrawMode As Long) As Long

Private Const R2_XORPEN As Long = 7
Private Const R2_BLACK As Long = 1
Private Const R2_NOT As Long = 6
Private Const PS_SOLID As Long = 0
Private Const PS_DASH As Long = 1

Private Type POINTAPI
x As Long
y As Long
End Type

Dim deskdc As Long
Dim OldX As POINTAPI
Dim hPen As Long, hOldPen As Long

Private Sub Form_Load()
hPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0))
deskdc = GetDC(0)
hOldPen = SelectObject(deskdc, hPen)

End Sub

Private Sub Form_Unload(Cancel As Integer)
SelectObject deskdc, hOldPen
DeleteObject hPen
deskdc = ReleaseDC(0, deskdc)

End Sub

Private Sub Timer1_Timer()
Dim p As POINTAPI
GetCursorPos p
If p.x <> OldX.x And p.y <> OldX.y Then
SetROP2 deskdc, R2_NOT
Rectangle deskdc, OldX.x, OldX.y, OldX.x - 10, OldX.y - 10
OldX.x = p.x: OldX.y = p.y
Rectangle deskdc, p.x, p.y, p.x - 10, p.y - 10
End If
End Sub
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式