标题:制作美化的系统右击菜单
取消只看楼主
heyu52
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2008-4-11
 问题点数:0 回复次数:0 
制作美化的系统右击菜单
using System.Drawing;
using System.Windows.Forms;

namespace
{
    public class ChangeSystemMenuColor
    {
        public static void SystemMenuColor(Form frm, Color color)
        {

            Win32.MENUINFO MENUINFO = new Win32.MENUINFO();
            MENUINFO.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(MENUINFO);
            MENUINFO.fMask = 2;

            Bitmap bmp = new Bitmap(200, 200);

            Brush b;
            b = new SolidBrush(color);

            Graphics g = Graphics.FromImage(bmp);
            g.FillRectangle(b, new Rectangle(0, 0, 200, 200));

            if (bmp == null) MENUINFO.hbrBack = 0; else MENUINFO.hbrBack = Win32.CreatePatternBrush((bmp.GetHbitmap()).ToInt32());
            try
            {
                Win32.SetMenuInfo(Win32.GetSystemMenu(frm.Handle.ToInt32(), 0), ref MENUINFO);

            }
            catch
            {


            }
        }

        public static void SystemMenuColor(Form frm, Image image)
        {
            Win32.MENUINFO MENUINFO = new Win32.MENUINFO();
            MENUINFO.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(MENUINFO);
            MENUINFO.fMask = 2;

            Bitmap bmp = new Bitmap(200, 200);

            Brush b;
            b = new System.Drawing.TextureBrush(image);

            Graphics g = Graphics.FromImage(bmp);
            g.FillRectangle(b, new Rectangle(0, 0, 200, 200));

            if (bmp == null) MENUINFO.hbrBack = 0; else MENUINFO.hbrBack = Win32.CreatePatternBrush((bmp.GetHbitmap()).ToInt32());
            try
            {
                Win32.SetMenuInfo(Win32.GetSystemMenu(frm.Handle.ToInt32(), 0), ref MENUINFO);

            }
            catch
            {


            }
        }

        public static void SystemMenuColor(Form frm, Color color1, Color color2, int direct)
        {
            Win32.MENUINFO MENUINFO = new Win32.MENUINFO();
            MENUINFO.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(MENUINFO);
            MENUINFO.fMask = 2;

            Bitmap bmp = new Bitmap(200, 200);

            Brush b;
            Point p1, p2;
            if (direct == 0)
            {
                p1 = new Point(0, 0);
                p2 = new Point(200, 0);
            }
            else if (direct == 1)
            {
                p1 = new Point(0, 0);
                p2 = new Point(0, 200);
            }
            else if (direct == 2)
            {
                p2 = new Point(0, 0);
                p1 = new Point(200, 200);
            }
            else
            {
                p2 = new Point(200, 0);
                p1 = new Point(0, 200);
            }
            b = new System.Drawing.Drawing2D.LinearGradientBrush(p1, p2, color1, color2);

            Graphics g = Graphics.FromImage(bmp);
            g.FillRectangle(b, new Rectangle(0, 0, 200, 200));

            if (bmp == null)
                MENUINFO.hbrBack = 0;
            else
                MENUINFO.hbrBack = Win32.CreatePatternBrush((bmp.GetHbitmap()).ToInt32());
            try
            {
                Win32.SetMenuInfo(Win32.GetSystemMenu(frm.Handle.ToInt32(), 0), ref MENUINFO);
            }
            catch
            {


            }
        }

        public static void UnSystemMenuColor(Form frm)
        {
            Win32.MENUINFO MENUINFO = new Win32.MENUINFO();
            MENUINFO.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(MENUINFO);
            MENUINFO.fMask = 2;
            MENUINFO.hbrBack = 0;
            try
            {
                Win32.SetMenuInfo(Win32.GetSystemMenu(frm.Handle.ToInt32(), 0), ref MENUINFO);

            }
            catch
            {


            }
        }

    }
}

未命名.jpg (15.34 KB)
搜索更多相关主题的帖子: 菜单 系统 制作 
2008-04-11 13:18



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-208402-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.091793 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved