Top / JUNK / 特殊なカーソル

五輪のカーソルを作ってみました。

Option Strict On
Imports System.Runtime.InteropServices

Public Class Form1
    <StructLayout(LayoutKind.Sequential)>
    Private Class ICONINFO
        Public fIcon As Integer
        Public xHotspot As Integer
        Public yHotspot As Integer
        Public hbmMask As IntPtr = IntPtr.Zero
        Public hbmColor As IntPtr = IntPtr.Zero
    End Class

    <DllImport("user32.dll")>
    Private Shared Function GetIconInfo(ByVal hicon As IntPtr, ByVal iconinfo As ICONINFO) As Boolean
    End Function

    <DllImport("user32.dll")>
    Private Shared Function CreateIconIndirect(ByVal iconinfo As ICONINFO) As IntPtr
    End Function

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Using bmp As New Bitmap(32, 32)
            Using g As Graphics = Graphics.FromImage(bmp)
                Dim es As New Size(10, 10)
                g.DrawEllipse(Pens.Blue, New Rectangle(New Point(0, 0), es))
                g.DrawEllipse(Pens.Gold, New Rectangle(New Point(es.Width \ 2, es.Height \ 2), es))
                g.DrawEllipse(Pens.Black, New Rectangle(New Point(es.Width, 0), es))
                g.DrawEllipse(Pens.Green, New Rectangle(New Point(es.Width * 3 \ 2, es.Height \ 2), es))
                g.DrawEllipse(Pens.Red, New Rectangle(New Point(es.Width * 2, 0), es))
            End Using
            Using tmpIcon As New Cursor(bmp.GetHicon())
                Dim info As New ICONINFO()
                GetIconInfo(tmpIcon.Handle, info)
                info.xHotspot = 0
                info.yHotspot = 0
                info.fIcon = 0
                Dim newIcon As IntPtr = CreateIconIndirect(info)
                Cursor = New Cursor(newIcon)
            End Using
        End Using
    End Sub

End Class

olympic.png



トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   最終更新のRSS
Last-modified: 2019-08-01 (木) 21:42:43 (83d)