⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 coolbutton.cs

📁 windows mobile 5 下的渐变Button 按钮.
💻 CS
📖 第 1 页 / 共 2 页
字号:
#define Wireless
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Reflection;
using YingShiLib;

namespace PdaButton
{
    [DesignerCategory("YSBT")]
    [DesignTimeVisible(true)]
    [DefaultValue("YSBT")]
    public partial class CoolButton : Control
    {       
        private delegate void CBDelegate();
        private  int ysState = 0;    //状态
        private  int poll = 0;    //人数
        private  float expenditure = 0;   //消费额
        private  string orderForm = string.Empty;    //单号
        private int clearDesk = 0;      //清台状态     
        private int mulDesk = 0;         //一单多台
        private int locationid = 0;      //区域
        private  int varValue = 0;
        private  int nflag = 0;
        private  string strText = string.Empty;       
        private  bool MU;
        private  bool backRed;
        private bool roundRect = false;
        private  EventHandler eh = null;
        private  bool ysFlag = false;
        private  Color frameColor=Color.Empty;   //边框颜色
        private  Color startColor = Color.White;  //渐变色开始颜色
        private  Color endColor = Color.SkyBlue;  //渐变色结束颜色
        private int roundLength =0;
        private  Size ysSize =new Size(70, 20);
        private IntPtr thePen, theBrush, oldPen, oldBrush = IntPtr.Zero;
        
        private const int GRADIENT_FILL_RECT_H = 0x00000000;
        private const int GRADIENT_FILL_RECT_V = 0x00000001;
        private const int GRADIENT_FILL_TRIANGLE = 0x00000002;

        [DllImport("Coredll.dll", EntryPoint = "GetDC")]
        public static extern IntPtr GetDC(IntPtr hWnd);

        [DllImport("coredll.dll", SetLastError = true, EntryPoint = "GradientFill")]
        public static extern bool GradientFill(IntPtr hdc, TRIVERTEX[] pVertex, uint dwNumVertex, GRADIENT_RECT[] pMesh, uint dwNumMesh, uint dwMode);
         [DllImport("Coredll.dll",EntryPoint="RoundRect")]
        public static extern bool DrawRoundRect(IntPtr hdc, int nLeftRect, int nTopRect,int nRightRect, int nBottomRect, int nWidth, int nHeight);

        [DllImport("Coredll.dll")]
        public static extern IntPtr CreateRectRgn(int nLeftRect, int nTopRect, int nRightRect,int nBottomRect);

        [DllImport("Coredll.dll")]
        public static extern IntPtr CreateSolidBrush(uint crColor);

        [DllImport("Coredll.dll")]
        public static extern IntPtr CreatePen(int fnPenStyle, int nWidth, uint crColor);

        [DllImport("Coredll.dll")]
        public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);

        [DllImport("Coredll.dll")]
        public static extern bool DeleteObject(IntPtr hObject);

        [DllImport("Coredll.dll")]
        public static extern uint GetNearestColor(IntPtr hdc,uint crColor); 

        [DllImport("Coredll.dll")]
        public static extern uint GetBkColor(IntPtr hdc);

        [DllImport("Coredll.dll")]
        public static extern uint SetBkColor(IntPtr hdc,uint color);

        [DllImport("Coredll.dll")]
        public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc,int nWidth,int nHeight);
        [DllImport("Coredll.dll")]
        public static extern IntPtr CreatePatternBrush(IntPtr HBITMAP);

        [DllImport("Coredll.dll")]
        public static extern int SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool bRedraw);

        public static uint YsRgb(Color color)
        {
            return (uint)(color.R + color.G * 256 + color.B * 256 * 256);
        } 

        public enum FillDirection
        {
            LeftToRight = GRADIENT_FILL_RECT_H,
            TopToBottom = GRADIENT_FILL_RECT_V,
            TRIANGLE = GRADIENT_FILL_TRIANGLE
        }

        public struct TRIVERTEX
        {
            public int x;
            public int y;
            public ushort Red;
            public ushort Green;
            public ushort Blue;
            public ushort Alpha;
            public TRIVERTEX(int x, int y, Color color):this(x, y, color.R, color.G, color.B, color.A)
            {
            }
            public TRIVERTEX(int x, int y, ushort red, ushort green, ushort blue, ushort alpha)
            {
                this.x = x;
                this.y = y;
                this.Red = (ushort)(red << 8);
                this.Green = (ushort)(green << 8);
                this.Blue = (ushort)(blue << 8);
                this.Alpha = (ushort)(alpha << 8);
            }           
        }

        public struct GRADIENT_RECT
        {
            public uint UpperLeft;
            public uint LowerRight;
            public GRADIENT_RECT(uint ul, uint lr)
            {
                this.UpperLeft = ul;
                this.LowerRight = lr;
            }           
        }

        #region  属性
        /// <summary>
        /// 属性
        /// </summary>
        ///   
        public int RoundLength
        {
            get { return roundLength; }
            set
            {
                roundLength = value;
                OnRoundLengthChanged(new EventArgs());
            }
        }

        protected virtual void OnRoundLengthChanged(EventArgs e)
        {
            if (eh != null)
                eh(this, new EventArgs());
        }
        public bool RoundRect
        {
            get { return roundRect; }
            set
            {
                //roundLength = base.Width / 10;
                roundRect = value;
                OnRoundRectChanged(new EventArgs());
            }
        }

        protected virtual void OnRoundRectChanged(EventArgs e)
        {
            if (eh != null)
                eh(this, new EventArgs());
        }
        //边框颜色
        public Color FrameColor
        {           
            get { return frameColor; }           
            set
            {
                frameColor = value;
                OnFrameColorChanged(new EventArgs());
            }
        }

        protected virtual void OnFrameColorChanged(EventArgs e)
        {
            if (eh != null)
            {
                eh(this, new EventArgs());
            }
        }
#if Wireless
       
        /// <summary>
        /// 清台状态
        /// </summary>
        public int ClearDesk
        {
            get { return clearDesk; }
            set
            {
                clearDesk = value;
                OnClearDeskChanged(new EventArgs());
            }
        }

        protected virtual void OnClearDeskChanged(EventArgs e)
        {
            if (eh != null)
            {
                eh(this, new EventArgs());
            }
        }

        //状态
        public int YsState
        {
            get { return ysState; }
            set { ysState = value; OnYsStateChanged(new EventArgs()); }
        }
        protected virtual void OnYsStateChanged(EventArgs e)
        {
            if (eh != null)
            {
                eh(this, new EventArgs());
            }
        }

        /// <summary>
        /// 人数
        /// </summary>
        [DefaultValue(0)]
        public int Poll
        {
            get { return poll; }
            set { poll = value; OnPollChanged(new EventArgs()); }
        }

        protected virtual void OnPollChanged(EventArgs e)
        {
            if (eh != null)
            {
                eh(this, new EventArgs());
            }
        }

        /// <summary>
        /// 消费额
        /// </summary>
        public float Expenditure
        {
            get { return expenditure; }
            set { expenditure = value; OnExpenditureChanged(new EventArgs()); }
        }

        protected virtual void OnExpenditureChanged(EventArgs e)
        {
            if (eh != null)
            {
                eh(this, new EventArgs());
            }
        }

        /// <summary>
        /// 单号
        /// </summary>
        public string OrderForm
        {
            get { return orderForm; }
            set { orderForm = value; OnOrderFormChanged(new EventArgs()); }
        }

        protected virtual void OnOrderFormChanged(EventArgs e)
        {
            if (eh != null)
            {
                eh(this, new EventArgs());
            }
        }

        //一单多台
        public int MulDesk
        {
            get { return mulDesk; }
            set
            {
                mulDesk = value;
                OnMulDeskChanged(new EventArgs());
            }
        }
        protected virtual void OnMulDeskChanged(EventArgs e)
        {
            if (eh != null)
            {
                eh(this, new EventArgs());
            }
        }

        public int LocationID
        {
            get { return locationid; }
            set
            {
                locationid = value;
                OnLocationIDChanged(new EventArgs());
            }
        }
        protected virtual void OnLocationIDChanged(EventArgs e)
        {
            if (eh != null)
                eh(this, new EventArgs());
        }
#endif
        public bool BackRed
        {
            get { return backRed; }
            set { backRed = value; OnBackRed(new EventArgs()); }
        }
        protected virtual void OnBackRed(EventArgs e)
        {
            if (eh != null)
            {
                eh(this, new EventArgs());
            }
        }
        [DefaultValue(false)]
        public bool ButtonMU
        {
            get
            {
                return MU;
            }
            set
            {
                MU = value;
                OnButtonMUChanged(new EventArgs());
            }
        }
        protected virtual void OnButtonMUChanged(EventArgs e)
        {
            if (eh != null)
            {
                eh(this, new EventArgs());
            }
        }
        /// <summary>
        /// 控件颜色
        /// </summary>
        /// <remarks>控件颜色</remarks>
        /// <value>
        /// nFlag=0   默认值(蓝色)
        /// nFlag=1   (金色)
        /// nFlag=2  (红色)
        /// </value>
        [DefaultValue(0)]
        public int ButtonFlag
        {
            get
            {
                return nflag;
            }
            set
            {
                nflag = value;
                OnButtonFlagChanged(new EventArgs());
            }
        }
        protected virtual void OnButtonFlagChanged(EventArgs e)
        {
            if (eh != null)
            {
                eh(this, new EventArgs());
            }
        }
        protected virtual void OnButtonValueChanged(EventArgs e)
        {
            if (eh != null)
            {
                eh(this, new EventArgs());
            }
        }
        public int ButtonValue
        {
            get
            {
                return varValue;
            }
            set
            {
                varValue = value;
                OnButtonValueChanged(new EventArgs());
            }
        }
        #region    控件文本
        /// <summary>
        /// 控件文本
        /// </summary>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -