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);
    }
  • 相关阅读:
    Solr4.7+Tomcat7.0配置
    Solr suggest 搜索建议功能 配置问题
    Solr 通过经纬度指定范围搜索
    Quartz.net 实例
    log4net简单实例
    依赖注入(Autofac)
    设计模式_状态模式_C#
    C# XML操作
    策略模式_C#_设计模式
    STM32随记
  • 原文地址:https://www.cnblogs.com/xiaoko/p/1437074.html
Copyright © 2011-2022 走看看