zoukankan      html  css  js  c++  java
  • 创建鼠标指针图标

    using System.Runtime.InteropServices;
    private struct IconInfo
    {
        public bool fIcon;
        public Int32 xHotspot;
        public Int32 yHotspot;
        public IntPtr hbmMask;
        public IntPtr hbmColor;        
    }

    [DllImport("user32.dll")]
    private static extern IntPtr CreateIconIndirect(ref IconInfo iconInfo);

    public Cursor RectCursor(Color AForeColor, Color ATransparent, int ASize)
    {
        if (ASize <= 0) return null;
        Bitmap vBitmap = new Bitmap(32, 32,
            System.Drawing.Imaging.PixelFormat.Format24bppRgb);
        Graphics vGraphics = Graphics.FromImage(vBitmap);
        vGraphics.FillRectangle(new SolidBrush(ATransparent), 0, 0, 32, 32);
        vGraphics.FillRectangle(new SolidBrush(AForeColor), 0, 0, ASize, ASize);
        vGraphics.Dispose();
        vBitmap.MakeTransparent(ATransparent);

        IconInfo vIconInfo = new IconInfo();
        vIconInfo.fIcon = false;
        vIconInfo.xHotspot = ASize / 2;
        vIconInfo.yHotspot = ASize / 2;
        vIconInfo.hbmMask = vBitmap.GetHbitmap();
        vIconInfo.hbmColor = vBitmap.GetHbitmap();
        IntPtr vHandle = CreateIconIndirect(ref vIconInfo);
        return new Cursor(vHandle);
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Cursor = RectCursor(Color.Red, Color.Black, 16);
    }
  • 相关阅读:
    学习进度笔记
    博雅数据机器学习07
    学习进度笔记
    博雅数据机器学习06
    《一级架构师》阅读笔记
    学习进度笔记
    博雅数据机器学习05
    递归的概念
    CSS学习笔记3:选择器及优先级
    CSS学习笔记2:伪类
  • 原文地址:https://www.cnblogs.com/xiaoko/p/1437074.html
Copyright © 2011-2022 走看看