当前位置:网站首页>VB. Net class library to obtain the color under the mouse in the screen (Advanced - 3)
VB. Net class library to obtain the color under the mouse in the screen (Advanced - 3)
2022-06-26 21:56:00 【Xiaoyu 163】
In the solution :
Create a new one new class:myScreen
quote :
One more this time System.Windows.Forms, Because we need to use button event
Then write the three segment function
Public Class myScreen
Public Image As Bitmap
Private ispick As Boolean = False
Private bmp As Bitmap
Private g As Graphics
''' <summary>
''' Be careful , Please do not call this function alone , also , This function corresponds to button The event is MouseDown. Get the mouse status and return the mouse style
''' </summary>
''' <param name="e"> Mouse events , It's the left key </param>
''' <param name="cur"> Incoming mouse style , And returns a mouse style of 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>
''' Be careful , Please do not call this function alone , also , This function corresponds to button The event is MouseMove. Get the mouse condition and return the color of the mouse pointer area
''' </summary>
''' <param name="e"> Mouse events </param>
''' <param name="but"> obtain 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>
''' Be careful , Please do not call this function alone , also , This function corresponds to button The event is MouseUp. Get the mouse status and return the mouse style
''' </summary>
''' <param name="cur"> Incoming mouse style , And returns a mouse style of Default</param>
''' <returns></returns>
Public Function PickColorUp(cur As Cursor)
ispick = False
cur = Cursors.Default
Return cur
End Function
End Class
Here is a reference VB.net Big guy's article .
Call on form :
in front : Make a statement myScreen Class
Public GDIscr As New GDI_Make_NET4_5.myScreen
Code in :
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
have a look :
边栏推荐
- Parsing complex JSON in fluent
- 传纸条【动态规划】
- Brief analysis of the self inspection contents of the blue team in the attack and defense drill
- 在哪个平台买股票开户最安全?求分享
- Flower shop window layout [dynamic planning]
- Test comparison of linear model LN, single neural network SNN, deep neural network DNN and CNN
- Leetcode (122) - the best time to buy and sell stocks II
- 打新债注册开户有没有什么风险?安全吗?
- How to create an OData service with the graphical modeler on the sap BTP platform
- 在哪家券商公司开户最方便最安全可靠
猜你喜欢
What are the accounting elements
Parsing complex JSON in fluent
MATLAB与Mysql数据库连接并数据交换(基于ODBC)
【题解】剑指 Offer 15. 二进制中1的个数(C语言)
ICML2022 | Neurotoxin:联邦学习的持久后门
leetcode:6103. 从树中删除边的最小分数【dfs + 联通分量 + 子图的值记录】
YOLOv6:又快又准的目標檢測框架開源啦
Implementation of collaborative filtering evolution version neuralcf and tensorflow2
About appium trample pit: encountered internal error running command: error: cannot verify the signature of (solved)
「连续学习Continual learning, CL」最新2022研究综述
随机推荐
Which platform is the safest for buying stocks and opening accounts? Ask for sharing
[LeetCode]-链表-2
MATLAB and MySQL database connection and data exchange (based on ODBC)
茂莱光学科创板上市:拟募资4亿 范一与范浩兄弟为实控人
The sharp sword of API management -- eolink
卷积神经网络(CNN)详解及TensorFlow2代码实现
模块五作业
不同的子序列问题I
Operator介绍
Unity3D插件 AnyPortrait 2D骨骼动画制作
leetcode:6103. Delete the minimum score of the edge from the tree [DFS + connected component + value record of the subgraph]
在Flutter中解析复杂的JSON
【数学建模】基于matlab GUI随机节点的生成树【含Matlab源码 1919期】
Centos7 compiling and installing redis
KDD2022 | 基于知识增强提示学习的统一会话推荐系统
leetcode:152. Product maximum subarray [consider DP of two dimensions]
基于启发式搜索的一字棋
AI智能抠图工具--头发丝都可见
curl: (35) LibreSSL SSL_ connect: SSL_ ERROR_ SYSCALL in connection
Flutter 中 ValueNotifier<List<T>> 监听问题解决