VB模仿CAD十字光标

这篇具有很好参考价值的文章主要介绍了VB模仿CAD十字光标。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

Option Explicit
Private Declare Function ShowCursor Lib “user32” (ByVal bShow As Long) As Long
Private Type GdiplusStartupInput
GdiplusVersion As Long
DebugEventCallback As Long
SuppressBackgroundThread As Long
SuppressExternalCodecs As Long
End Type
Private Enum GpStatus
Ok = 0
GenericError = 1
InvalidParameter = 2
OutOfMemory = 3
ObjectBusy = 4
InsufficientBuffer = 5
NotImplemented = 6
Win32Error = 7
WrongState = 8
Aborted = 9
FileNotFound = 10
ValueOverflow = 11
AccessDenied = 12
UnknownImageFormat = 13
FontFamilyNotFound = 14
FontStyleNotFound = 15
NotTrueTypeFont = 16
UnsupportedGdiplusVersion = 17
GdiplusNotInitialized = 18
PropertyNotFound = 19
PropertyNotSupported = 20
End Enum
Private Declare Function GdipCreateFromHDC Lib “gdiplus” (ByVal hdc As Long, Graphics As Long) As GpStatus
Private Declare Function GdipCreateSolidFill Lib “gdiplus” (ByVal argb As Long, Brush As Long) As GpStatus
Private Declare Function GdiplusStartup Lib “gdiplus” (Token As Long, inputbuf As GdiplusStartupInput, Optional ByVal outputbuf As Long = 0) As GpStatus
Private Declare Sub GdiplusShutdown Lib “gdiplus” (ByVal Token As Long)
Private Declare Function GdipDeleteBrush Lib “gdiplus” (ByVal Brush As Long) As GpStatus
Private Declare Function GdipDeleteGraphics Lib “gdiplus” (ByVal Graphics As Long) As GpStatus
Private Declare Function GdipFillRectangle Lib “gdiplus” (ByVal Graphics As Long, ByVal Brush As Long, ByVal X As Single, ByVal Y As Single, ByVal Width As Single, ByVal Height As Single) As GpStatus
Dim mToken As Long, Graphics As Long, Brush As Long
Private Declare Function DeleteObject Lib “gdi32” (ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib “gdi32” (ByVal hdc As Long) As Long
Dim WithEvents District As Shape
Dim XL As Single, YT As Single
Dim Bnt As Boolean
Private Type MARQUEE_AREA
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Enum OpType
None = 0
Draw = 1
Drag = 2
End Enum
Dim BoxArea As MARQUEE_AREA
Dim Ot As OpType
Dim Sbwzxy(1) As Long
Dim SB As Boolean
Dim Distance As Long
Dim LineColor As Long
Dim XqColor As Long

Private Sub Form_Load()
Me.AutoRedraw = True: Me.ScaleMode = 3
Me.BackColor = RGB(0, 0, 0)
Distance = 10
LineColor = RGB(30, 30, 30)
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
XL = X: YT = Y
If SB = True Then SB = False Else SB = True
Call Region(X, Y, Me.ScaleWidth, Me.ScaleHeight)
If X > BoxArea.Left And X < BoxArea.Right + XL And Y > BoxArea.Top And Y < BoxArea.Bottom + YT Then
Sbwzxy(0) = X: Sbwzxy(1) = Y
End If
End If
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.Refresh
Me.Cls
Dim L As Long, T As Long, ll As Long
If SB = True Then
Call Region(X, Y, Me.ScaleWidth, Me.ScaleHeight)
End If
If SB = False Then Me.Line (X - 10, Y - 10)-(X + 10, Y + 10), RGB(255, 255, 255), B
Me.Line (X - 100, Y)-(IIf(SB, X, X - 10), Y), RGB(255, 255, 255), B
Me.Line (IIf(SB, X, X + 10), Y)-(X + 100, Y), RGB(255, 255, 255), B
Me.Line (X, Y - 100)-(X, IIf(SB, Y, Y - 10)), RGB(255, 255, 255), B
Me.Line (X, IIf(SB, Y, Y + 10))-(X, Y + 100), RGB(255, 255, 255), B
End Sub

Private Sub Form_Resize()
Dim X, Y
Me.DrawWidth = 1
Me.Refresh
Me.Cls
Set Me.Picture = LoadPicture(“”)
For X = 0 To Me.ScaleWidth Step Distance
Me.Line (X, 0)-(X, Me.ScaleHeight), LineColor
Next
For Y = 0 To Me.ScaleHeight Step Distance
Me.Line (0, Y)-(Me.ScaleWidth, Y), LineColor
Next
Me.Line (15, Me.ScaleHeight - 30)-(Me.ScaleWidth, Me.ScaleHeight - 30), RGB(100, 0, 0), B
Me.Line (15, Me.ScaleHeight - 30)-(80, Me.ScaleHeight - 30), RGB(255, 255, 255), B
Me.Line (15, 0)-(15, Me.ScaleHeight - 30), RGB(0, 100, 0), B
Me.Line (15, Me.ScaleHeight - 100)-(15, Me.ScaleHeight - 30), RGB(255, 255, 255), B
Me.Line (10, Me.ScaleHeight - 38)-(22, Me.ScaleHeight - 25), RGB(255, 255, 255), B
Me.ForeColor = RGB(255, 255, 255)
Me.CurrentX = 18: Me.CurrentY = Me.ScaleHeight - 110
Me.FontSize = 12
Me.Print “X”
Me.CurrentX = 80: Me.CurrentY = Me.ScaleHeight - 45
Me.FontSize = 12
Me.Print “Y”

Set Me.Picture = Me.Image

End Sub

Private Sub Region(X1 As Single, Y1 As Single, X2 As Single, Y2 As Single)
Dim Lx As Long, Ty As Long, Dcolor As Long
BoxArea.Left = IIf(X1 > XL, XL, IIf(X1 <= 0, 0, X1))
BoxArea.Top = IIf(Y1 > YT, YT, IIf(Y1 <= 0, 0, Y1))
BoxArea.Right = IIf(X1 > XL, IIf(X1 < X2, X1 - XL, X2 - XL), IIf(X1 < 0, XL, XL - X1))
BoxArea.Bottom = IIf(Y1 > YT, IIf(Y1 < Y2, Y1 - YT, Y2 - YT), IIf(Y1 < 0, YT, YT - Y1))

If XL < X1 Then
XqColor = RGB(0, 0, 155): Me.DrawStyle = 0
Lx = X1 + 15: Ty = Y1 - 15: Dcolor = RGB(0, 0, 255)
Else
XqColor = RGB(0, 155, 0): Me.DrawStyle = 2
Lx = X1 + 10: Ty = Y1 - 15: Dcolor = RGB(0, 255, 0)
End If
Call GICpic(Me.hdc, BoxArea.Left, BoxArea.Top, BoxArea.Right, BoxArea.Bottom, XqColor, 100)
Me.Line (BoxArea.Left, BoxArea.Top)-(BoxArea.Left + BoxArea.Right, BoxArea.Top + BoxArea.Bottom), RGB(255, 255, 255), B
Me.Line (X1 + 20, Y1 - 20)-(X1 + 10, Y1 - 10), RGB(255, 255, 255), B
Me.FillStyle = 0
Me.FillColor = Dcolor
Me.Circle (Lx, Ty), 2.5, vbBlack

Me.FillStyle = 1
Me.DrawStyle = 0
End Sub

Private Sub GICpic(hdc As Long, Left As Long, Top As Long, Width As Long, Height As Long, Optional Bcolor As Long, Optional Tming As Long = 255)
Dim GdipInput As GdiplusStartupInput, ColorArr, Fcolor As String, Price As String, Lhdc(4) As Long
Dim Blue&, Red&, Green&
Blue = 0: Red = 0: Green = 0
Blue = Bcolor \ 65536
Green = (Bcolor - 65536 * Blue) \ 256
Red = Bcolor - 65536 * Blue - Green * 256
ColorArr = Array(Red, Green, Blue)
'On Error GoTo Nx
GdipInput.GdiplusVersion = 2
Lhdc(0) = GdiplusStartup(mToken, GdipInput)
Lhdc(1) = GdipCreateFromHDC(hdc, Graphics)
Price = IIf(Len(Hex(Tming)) = 1, “0” & Hex(Tming), Hex(Tming))

Fcolor = IIf(Len(HexKaTeX parse error: Expected 'EOF', got '&' at position 25: …(0))) = 1, "0" &̲ Hex(ColorArr(0)), HexKaTeX parse error: Expected 'EOF', got '&' at position 16: (ColorArr(0))) &̲ IIf(Len(Hex(ColorArr(1))) = 1, “0” & _
Hex ( C o l o r A r r ( 1 ) ) , H e x (ColorArr(1)), Hex (ColorArr(1)),Hex(ColorArr(1))) & IIf(Len(HexKaTeX parse error: Expected 'EOF', got '&' at position 25: …(2))) = 1, "0" &̲ Hex(ColorArr(2)), Hex$(ColorArr(2)))
Lhdc(2) = GdipCreateSolidFill(“&H” & Price & Fcolor, Brush)
Lhdc(3) = GdipFillRectangle(Graphics, Brush, Left, Top, Width, Height)

Call GdipDeleteBrush(Brush)
Call GdipDeleteGraphics(Graphics)
Call GdiplusShutdown(mToken)
Call DeleteObject(mToken)

For Lhdc(4) = 0 To 3
Call DeleteDC(Lhdc(Lhdc(4)))
Call DeleteObject(Lhdc(Lhdc(4)))
Next
'Nx:
End Sub文章来源地址https://www.toymoban.com/news/detail-430107.html

到了这里,关于VB模仿CAD十字光标的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 教你学会使用Angular 应用里的 export declare const X Y

    摘要: export declare const X: Y语法用于在Angular应用程序中声明一个具有指定类型的常量变量,并将其导出,以便在其他文件中使用。 本文分享自华为云社区《关于 Angular 应用里的 export declare const X Y 的用法》,作者:Jerry Wang。 最近做 Spartacus 的 Angular 开发时,遇到下面这种 T

    2024年02月11日
    浏览(46)
  • TypeScript系列, 通过vue3实例说说declare module语法怎么用[模块声明篇]

    本系列文章是我20年开始写的, 这个模块声明也是本系列的最后一课, 中间因为时间安排间隔了1年, 当时答应大家要补充的, 现在来还债😊. 中间的时间我写了vue3的入门教程, 现在写了一半了吧, 带视频的, 如果有需要的小伙伴可以去看看. https://www.yuque.com/books/share/c0ab3348-87ab-4

    2023年04月22日
    浏览(36)
  • explicit 关键字

    c++ 提供了 explicit ,禁止通过构造函数进行的隐式转换。声明为 explicit 的构造函数不能在隐式转换中使用。 [explicit 注意 ] explicit 用于修饰构造函数 , 防止隐式转化。 是针对单参数的构造函数 ( 或者除了第一个参数外其余参数都有默认值的多参构造 ) 而言。

    2024年02月09日
    浏览(76)
  • C++(20):explicit(true/false)

    explicit通常用于声明是否运行隐式转换: C++20扩展了explicit,可以通过explicit(false)来禁用,或通过explicit(true)来启用explicit

    2024年02月06日
    浏览(43)
  • Elasticsearch:Explicit mapping - 显式映射

    显式映射相比较动态映射(Dynamic mapping)是需要我们在索引创建时就定义字段及其类型。这个和我们传统的 RDMS 数据库一样,在我们写入数据到数据库之前,我们需要工整地定义好每个字段及其类型和长度。Elasticsearch 既可以使用显式映射也可以同时使用动态映射。在许多的

    2024年02月02日
    浏览(46)
  • selenium Explicit 和 Implicit Waits区别

    The Selenium Browser Automation Project | Selenium Explicit and Implicit Waits Waiting is having the automated task execution elapse a certain amount of time before continuing with the next step. You should choose to use Explicit Waits or Implicit Waits. WARNING: Do not mix implicit and explicit waits. Doing so can cause unpredictable wait times. For example

    2024年02月10日
    浏览(33)
  • 切换pycharm光标类型(解决pycharm光标变粗)

    这种粗光标是插入模式,输入内容会替换掉原本的内容,回车则是单纯换行 在禁用小键盘的情况下,使用 INSERT 键(也就是小键盘的 0 )进行切换 小键盘如果是启用状态,则按住 shift + 小键盘的 0 即可切换光标类型

    2024年01月24日
    浏览(22)
  • C++——初始化列表 | explicit关键字 | static成员

    🌸作者简介: 花想云 ,在读本科生一枚,致力于 C/C++、Linux 学习。 🌸 本文收录于 C++系列 ,本专栏主要内容为 C++ 初阶、C++ 进阶、STL 详解等,专为大学生打造全套 C++ 学习教程,持续更新! 🌸 相关专栏推荐: C语言初阶系列 、 C语言进阶系列 、 数据结构与算法 本章我们

    2023年04月11日
    浏览(50)
  • vue获取+设置光标位置 光标定位 选择输入框文本

    版本:vue2、vant2 在vue是用ref、 r e f s 获取 d o m 的,在 v a n t 框架里 v a n − f i e l d 是输入框组件,它不支持直接设置光标的方法 s e t S e l e c t i o n R a n g e ( ) ,所以通过 t h i s . refs获取dom的,在vant框架里van-field是输入框组件,它不支持直接设置光标的方法setSelectionRange(),所

    2024年02月16日
    浏览(52)
  • 稀疏矩阵转十字链表

    定义: 十字链表(Orthogonal List)是有向图的另一种链式存储结构。该结构可以看成是将有向图的邻接表和逆邻接表结合起来得到的。用十字链表来存储有向图,可以达到高效的存取效果。同时,代码的可读性也会得到提升。 ● 特点         • 只保存非零值           • 为每一

    2024年02月02日
    浏览(37)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包