当前位置:网站首页>VB.net类库,获取屏幕内鼠标下的颜色(进阶——3)
VB.net类库,获取屏幕内鼠标下的颜色(进阶——3)
2022-06-26 20:40:00 【小虞163】
在解决方案中:
新建一个new class:myScreen

引用:
这一次多出一个System.Windows.Forms,因为我们需要用到button事件
接着写入三段函数
Public Class myScreen
Public Image As Bitmap
Private ispick As Boolean = False
Private bmp As Bitmap
Private g As Graphics
''' <summary>
''' 注意,请不要单独调用此函数,并且,该函数对应的button事件为MouseDown。获取鼠标情况并返回鼠标样式
''' </summary>
''' <param name="e">鼠标事件,是左键</param>
''' <param name="cur">传入鼠标的样式,并返回一个鼠标样式为Cross</param>
''' <returns></returns>
Public Function PickColorDown(e As MouseEventArgs, cur As Cursor)
If e.Button = MouseButtons.Left Then
ispick = True
Dim scr As Screen = Screen.PrimaryScreen
Dim recSc As Rectangle = scr.Bounds
bmp = New Bitmap(recSc.Width, recSc.Height)
g = Graphics.FromImage(bmp)
g.CopyFromScreen(New Point(0, 0), New Point(0, 0), New Size(recSc.Width, recSc.Height))
cur = Cursors.Cross
Return cur
End If
End Function
''' <summary>
''' 注意,请不要单独调用此函数,并且,该函数对应的button事件为MouseMove。获取鼠标情况并返回鼠标指针区域的颜色
''' </summary>
''' <param name="e">鼠标事件</param>
''' <param name="but">获取button</param>
''' <returns></returns>
Public Function PickColorMove(e As MouseEventArgs, but As Button)
Dim x, y As Integer
Dim p As Point = New Point(e.X, e.Y)
Dim colorpoint As Color
If ispick = True Then
x = but.PointToScreen(p).X
y = but.PointToScreen(p).Y
colorpoint = bmp.GetPixel(x, y)
Return colorpoint
End If
End Function
''' <summary>
''' 注意,请不要单独调用此函数,并且,该函数对应的button事件为MouseUp。获取鼠标情况并返回鼠标样式
''' </summary>
''' <param name="cur">传入鼠标的样式,并返回一个鼠标样式为Default</param>
''' <returns></returns>
Public Function PickColorUp(cur As Cursor)
ispick = False
cur = Cursors.Default
Return cur
End Function
End Class这里参考了一下VB.net大佬的文章。
窗体上的调用:
在前面:声明一下myScreen的类
Public GDIscr As New GDI_Make_NET4_5.myScreen代码加入:
Private Sub Button3_MouseDown(sender As Object, e As MouseEventArgs) Handles Button3.MouseDown
Cursor = GDIscr.PickColorDown(e, Cursor)
End Sub
Private Sub Button3_MouseMove(sender As Object, e As MouseEventArgs) Handles Button3.MouseMove
Pic.BackColor = GDIscr.PickColorMove(e, Button3)
End Sub
Private Sub Button3_MouseUp(sender As Object, e As MouseEventArgs) Handles Button3.MouseUp
Cursor = GDIscr.PickColorUp(Cursor)
End Sub看看:
边栏推荐
- 515. find the maximum value in each tree row
- Disruptor本地线程队列_使用transProcessor处理器和WorkPool两种方式进行消费对比---线程间通信工作笔记005
- [Bayesian classification 2] naive Bayesian classifier
- Fixed length memory pool
- 515. 在每个树行中找最大值
- Two methods of QT to realize timer
- leetcode刷题:字符串04(颠倒字符串中的单词)
- Record a redis large key troubleshooting
- 基于QT实现简单的连连看小游戏
- 与 MySQL 建立连接
猜你喜欢
MongoDB实现创建删除数据库、创建删除表(集合)、数据增删改查
![[serialization] how to master the core technology of opengauss database? Secret 5: master database security (6)](/img/a8/622cddae2ac8c383979ed51d36bca9.jpg)
[serialization] how to master the core technology of opengauss database? Secret 5: master database security (6)

mongoDB的三种基础备份方法

C language 99 multiplication table

leetcode刷题:字符串04(颠倒字符串中的单词)

Feitian +cipu body brings more imagination to the metauniverse

【 protobuf 】 quelques puits causés par la mise à niveau de protobuf

Many gravel 3D material mapping materials can be obtained with one click

大家都能看得懂的源码(一)ahooks 整体架构篇

QT两种方法实现定时器
随机推荐
手机股票注册开户有没有什么风险?安全吗?
【贝叶斯分类4】贝叶斯网
Fixed length memory pool
定长内存池
[Bayesian classification 3] semi naive Bayesian classifier
【山东大学】考研初试复试资料分享
Arduino UNO + DS1302利用31字节静态RAM存储数据并串口打印
不要做巨婴了
710. 黑名单中的随机数
网上开户万一免五到底安不安全?
云计算技术的发展与芯片处理器的关系
Redis + Guava 本地缓存 API 组合,性能炸裂!
慕课11、微服务的用户认证与授权
Separate save file for debug symbols after strip
Feitian +cipu body brings more imagination to the metauniverse
12个MySQL慢查询的原因分析
Is it safe to open an online account in case of five-year exemption?
MySQL stored procedure
Looking back at the moon
IDEA 报错:Process terminated【已解决】