示例#1
0
        /// <summary>
        /// 为DUI样式控件赋值样式
        /// </summary>
        /// <param name="control">DUI样式控件基类对象</param>
        public override void SetControlStyle(IDUIStyleControl control)
        {
            DUIStyleLabel label = control as DUIStyleLabel;

            if (label == null)
            {
                return;
            }

            DUIFont labelFont = DUISkinManager.GetCurrentSkinManager().GetFont(_fontName);

            if (labelFont != null)
            {
                if (labelFont.Font != null)
                {
                    label.Font = labelFont.Font;
                }
                if (labelFont.BackColor != Color.Empty)
                {
                    label.BackColor = labelFont.BackColor;
                }
                if (labelFont.ForeColor != Color.Empty)
                {
                    label.ForeColor = labelFont.ForeColor;
                }
            }
        }
        /// <summary>
        /// 为DUI样式控件赋值样式
        /// </summary>
        /// <param name="control">DUI样式控件基类对象</param>
        public override void SetControlStyle(IDUIStyleControl control)
        {
            DUIStyleButton button = control as DUIStyleButton;
            if (button == null)
            {
                return;
            }

            //获得皮肤全局字体对象
            DUIFont buttonFont = DUISkinManager.GetCurrentSkinManager().GetFont(_fontName);
            if (buttonFont != null)
            {
                if (buttonFont.Font != null)
                {
                    button.Font = buttonFont.Font;
                }
                if (buttonFont.BackColor != Color.Empty)
                {
                    button.BackColor = buttonFont.BackColor;
                }
                if (buttonFont.ForeColor != Color.Empty)
                {
                    button.ForeColor = buttonFont.ForeColor;
                }
            }
            button.FlatStyle = _flatStyle;
        }
示例#3
0
        public override void OnSkinChanged(DUISkinManager skinManager)
        {
            base.OnSkinChanged(skinManager);

            int listView1LocationX
                = Convert.ToInt32(DUISkinManager.GetCurrentSkinManager().GetParameter("listview1-location-x"));
            int listView1LocationY
                = Convert.ToInt32(DUISkinManager.GetCurrentSkinManager().GetParameter("listview1-location-y"));

            this.listView1.Location = new System.Drawing.Point(listView1LocationX, listView1LocationY);

            int listView1LocationWidth
                = Convert.ToInt32(DUISkinManager.GetCurrentSkinManager().GetParameter("listview1-location-width"));
            int listView1LocationHeight
                = Convert.ToInt32(DUISkinManager.GetCurrentSkinManager().GetParameter("listview1-location-height"));

            this.listView1.Size = new System.Drawing.Size(listView1LocationWidth, listView1LocationHeight);

            int button1LocationX
                = Convert.ToInt32(DUISkinManager.GetCurrentSkinManager().GetParameter("button1-location-x"));
            int button1LocationY
                = Convert.ToInt32(DUISkinManager.GetCurrentSkinManager().GetParameter("button1-location-y"));

            this.button1.Location = new Point(button1LocationX, button1LocationY);

            int button2LocationX
                = Convert.ToInt32(DUISkinManager.GetCurrentSkinManager().GetParameter("button2-location-x"));
            int button2LocationY
                = Convert.ToInt32(DUISkinManager.GetCurrentSkinManager().GetParameter("button2-location-y"));

            this.button2.Location = new Point(button2LocationX, button2LocationY);
        }
        /// <summary>
        /// 为DUI样式控件赋值样式
        /// </summary>
        /// <param name="control">DUI样式控件基类对象</param>
        public override void SetControlStyle(IDUIStyleControl control)
        {
            DUIStyleTextBox textBox = control as DUIStyleTextBox;

            if (textBox == null)
            {
                return;
            }

            //获得皮肤全局字体对象
            DUIFont textboxFont = DUISkinManager.GetCurrentSkinManager().GetFont(_fontName);

            if (textboxFont != null)
            {
                if (textboxFont.Font != null)
                {
                    textBox.Font = textboxFont.Font;
                }
                if (textboxFont.BackColor != Color.Empty)
                {
                    textBox.BackColor = textboxFont.BackColor;
                }
                if (textboxFont.ForeColor != Color.Empty)
                {
                    textBox.ForeColor = textboxFont.ForeColor;
                }
            }
            textBox.BorderStyle = _borderStyle;
        }
示例#5
0
 /// <summary>
 /// 根据DUIStyleName从配置读取并设置自身样式
 /// </summary>
 public void ProcessDUIStyle()
 {
     if (!string.IsNullOrEmpty(this._dUIStyleName))
     {
         IDUIStyle DUIStyle = DUISkinManager.GetCurrentSkinManager().GetStyle(this.GetType(), this._dUIStyleName);
         if (DUIStyle != null)
         {
             DUIStyle.SetControlStyle(this);
         }
     }
 }
示例#6
0
        /// <summary>
        /// 测试点p是否在当前按钮的矩形范围内
        /// </summary>
        /// <param name="backBufferBitmap">当前双缓冲绘图缓存的背景图片</param>
        /// <param name="offsetPoint">偏移点,用于消除窗口最大化时窗口边框厚度对点计算造成的误差</param>
        /// <param name="p">待测试点</param>
        /// <returns></returns>
        public bool RectangleContains(Image backBufferBitmap, Point offsetPoint, Point p)
        {
            //此处计算按钮矩形范围以按钮普通状态的贴图图片大小为准,
            //理论上要求同一个按钮的各种状态的图片尺寸需一样,否则可能造成后续状态判断鼠标位置偏差
            Image     buttonImage     = DUISkinManager.GetCurrentSkinManager().GetImageSource(this._normalSourceName);
            Rectangle buttonRectangle = new Rectangle(
                CommonFunctions.GetImagePoint(backBufferBitmap, offsetPoint.X, offsetPoint.Y, this._position).X,
                CommonFunctions.GetImagePoint(backBufferBitmap, offsetPoint.X, offsetPoint.Y, this._position).Y,
                buttonImage.Width,
                buttonImage.Height);
            //拷贝一份,防止被修改
            Point tempPoint = new Point(p.X, p.Y);

            tempPoint.Offset(-offsetPoint.X, -offsetPoint.Y);
            return(buttonRectangle.Contains(tempPoint));
        }
示例#7
0
        public Form1()
        {
            InitializeComponent();

            this.comboBox1.DataSource    = DUISkinManager.GetSkinInfoList(true);
            this.comboBox1.DisplayMember = "SkinDisplayName";
            this.comboBox1.ValueMember   = "SkinName";
            this.comboBox1.SelectedIndex = 0;

            foreach (DUISkinInfo skinInfo in this.comboBox1.Items)
            {
                if (skinInfo.SkinName == Program.skinName)
                {
                    this.comboBox1.SelectedItem = skinInfo;
                }
            }
        }
示例#8
0
        /// <summary>
        /// 在双缓冲背景图上绘制当前图片
        /// </summary>
        /// <param name="backBufferBitmap">当前双缓冲绘图缓存的背景图片</param>
        /// <param name="g">与背景缓冲图绑定的绘图对象</param>
        /// <param name="offsetPoint">偏移点,用于消除窗口最大化时窗口边框厚度对点计算造成的误差</param>
        public void Render(Image backBufferBitmap, Graphics g, Point offsetPoint)
        {
            Point actualTopLeftPoint = CommonFunctions.GetImagePoint(
                backBufferBitmap, offsetPoint.X, offsetPoint.Y, new Point(_left, _top));
            Point actualBottomRightPoint = CommonFunctions.GetImagePoint(
                backBufferBitmap, offsetPoint.X, offsetPoint.Y, new Point(_right, _bottom));


            Image     image         = DUISkinManager.GetCurrentSkinManager().GetImageSource(this._sourceName);;
            Rectangle imageRectange = new Rectangle(
                actualTopLeftPoint.X,
                actualTopLeftPoint.Y,
                actualBottomRightPoint.X - actualTopLeftPoint.X,
                actualBottomRightPoint.Y - actualTopLeftPoint.Y);

            //在背景换冲图上绘制当前按钮
            g.DrawImage(image, imageRectange, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
        }
        private void LayoutSelectDropDownList_Load(object sender, EventArgs e)
        {
            _newStyleName = _originalStyleName;

            IDictionary <string, IDUIStyle> styleDict
                = DUISkinManager.GetCurrentSkinManager().GetStyleDict(this._dUIStyleControlType);

            if (styleDict != null && styleDict.Count > 0)
            {
                foreach (string styleName in styleDict.Keys)
                {
                    this.lbStyleList.Items.Add(styleName);
                    if (styleName == _newStyleName)
                    {
                        this.lbStyleList.SelectedIndex = this.lbStyleList.Items.Count - 1;
                    }
                }
            }
        }
示例#10
0
        static void Main()
        {
            string appBaseDirectory = CommonFunctions.GetAppBaseDirectory();

            skinName = ConfigurationManager.AppSettings["SkinName"];
            if (string.IsNullOrEmpty(skinName))
            {
                skinName = "Default";
            }

            DUISkinInfo skinInfo = new DUISkinInfo(appBaseDirectory, skinName);

            DUISkinManager.CreateSkinManager(skinInfo, false);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());
            Application.Run(new RoundPanelTestForm());
            //Application.Run(new NotifyTest.NotifyTest());
        }
        private void LayoutSelectDropDownList_Load(object sender, EventArgs e)
        {
            _newLayoutName = _originalLayoutName;

            ICollection <string> layoutList = DUISkinManager.GetCurrentSkinManager().Layouts.Keys;

            if (layoutList != null && layoutList.Count > 0)
            {
                //this.lbLayoutList.DataSource = layoutList;
                //this.lbLayoutList.SelectedItem = _newLayoutName;
                foreach (string layoutName in layoutList)
                {
                    this.lbLayoutList.Items.Add(layoutName);
                    if (layoutName == _newLayoutName)
                    {
                        this.lbLayoutList.SelectedIndex = this.lbLayoutList.Items.Count - 1;
                    }
                }
            }
        }
示例#12
0
        /// <summary>
        /// 在双缓冲背景图上绘制当前按钮
        /// </summary>
        /// <param name="backBufferBitmap">当前双缓冲绘图缓存的背景图片</param>
        /// <param name="g">与背景缓冲图绑定的绘图对象</param>
        /// <param name="offsetPoint">偏移点,用于消除窗口最大化时窗口边框厚度对点计算造成的误差</param>
        public void Render(Image backBufferBitmap, Graphics g, Point offsetPoint)
        {
            Image   buttonImage = null;
            DUIFont textDUIFont = null;
            Color   textColor   = Color.Empty;

            Rectangle buttonRectange;

            //HoldDown标志的优先级高于按钮状态,若HoldDown为true,则按钮绘制为按下状态
            if (this.HoldDown)
            {
                buttonImage = DUISkinManager.GetCurrentSkinManager().GetImageSource(this._downSourceName);
                textDUIFont = DUISkinManager.GetCurrentSkinManager().GetFont(this._downFontName);
            }
            //根据按钮状态采用不同的按钮贴图
            else
            {
                if (this.Status == ButtonStatus.Down)
                {
                    buttonImage = DUISkinManager.GetCurrentSkinManager().GetImageSource(this._downSourceName);
                    textDUIFont = DUISkinManager.GetCurrentSkinManager().GetFont(this._downFontName);
                }
                else if (this.Status == ButtonStatus.Hover)
                {
                    buttonImage = DUISkinManager.GetCurrentSkinManager().GetImageSource(this._hoverSourceName);
                    textDUIFont = DUISkinManager.GetCurrentSkinManager().GetFont(this._hoverFontName);
                }
                else if (this.Status == ButtonStatus.Normal)
                {
                    buttonImage = DUISkinManager.GetCurrentSkinManager().GetImageSource(this._normalSourceName);
                    textDUIFont = DUISkinManager.GetCurrentSkinManager().GetFont(this._normalFontName);
                }
                else
                {
                    ;
                }
            }
            //计算按钮在背景缓冲图上的矩形范围
            buttonRectange = new Rectangle(
                CommonFunctions.GetImagePoint(backBufferBitmap, offsetPoint.X, offsetPoint.Y, this._position).X,
                CommonFunctions.GetImagePoint(backBufferBitmap, offsetPoint.X, offsetPoint.Y, this._position).Y,
                buttonImage.Width,
                buttonImage.Height);
            //在背景换冲图上绘制当前按钮
            g.DrawImage(buttonImage, buttonRectange, 0, 0, buttonImage.Width, buttonImage.Height, GraphicsUnit.Pixel);

            //-------------------------------------------------------------------------------------
            //绘制按钮文字
            if (!string.IsNullOrEmpty(this._text))
            {
                Font textFont = null;
                if (textDUIFont == null ||
                    textDUIFont.Font == null)
                {
                    //配置中没有指定标题字体的,使用系统默认字体
                    textFont = SystemFonts.DefaultFont;
                }
                else
                {
                    textFont = textDUIFont.Font;
                }

                if (textDUIFont == null ||
                    textDUIFont.ForeColor.Equals(Color.Empty))
                {
                    textColor = Color.Red; //红色突出字体颜色加载失败
                }
                else
                {
                    textColor = textDUIFont.ForeColor;
                }

                //------------------------------
                //计算按钮文字绘制位置
                Size textSize           = g.MeasureString(this._text, textFont).ToSize(); //计算文本绘制后的长度
                int  textInnerPositionX = 0;                                              //按钮文字在按钮矩形内部的起始位置横坐标
                int  textInnerPositionY = 0;                                              //按钮文字在按钮矩形内部的起始位置横坐标

                //根据文字对齐方式计算文字在按钮矩形内部的起始位置
                switch (this._textAlignment)
                {
                case ContentAlignment.TopLeft:
                    textInnerPositionX = 0;
                    textInnerPositionY = 0;
                    break;

                case ContentAlignment.TopCenter:
                    textInnerPositionX = (buttonRectange.Width - textSize.Width) / 2;
                    textInnerPositionY = 0;
                    break;

                case ContentAlignment.TopRight:
                    textInnerPositionX = buttonRectange.Width - textSize.Width;
                    textInnerPositionY = 0;
                    break;

                case ContentAlignment.MiddleLeft:
                    textInnerPositionX = 0;
                    textInnerPositionY = (buttonRectange.Height - textSize.Height) / 2;
                    break;

                case ContentAlignment.MiddleCenter:
                    textInnerPositionX = (buttonRectange.Width - textSize.Width) / 2;
                    textInnerPositionY = (buttonRectange.Height - textSize.Height) / 2;
                    break;

                case ContentAlignment.MiddleRight:
                    textInnerPositionX = buttonRectange.Width - textSize.Width;
                    textInnerPositionY = (buttonRectange.Height - textSize.Height) / 2;
                    break;

                case ContentAlignment.BottomLeft:
                    textInnerPositionX = 0;
                    textInnerPositionY = buttonRectange.Height - textSize.Height;
                    break;

                case ContentAlignment.BottomCenter:
                    textInnerPositionX = (buttonRectange.Width - textSize.Width) / 2;
                    textInnerPositionY = buttonRectange.Height - textSize.Height;
                    break;

                case ContentAlignment.BottomRight:
                    textInnerPositionX = buttonRectange.Width - textSize.Width;
                    textInnerPositionY = buttonRectange.Height - textSize.Height;
                    break;
                }

                //计算按钮文字在整个背景上的绘制起始位置,并绘制文字
                int textStartX = buttonRectange.X + textInnerPositionX + this._textOffsetX;
                int textStartY = buttonRectange.Y + textInnerPositionY + this._textOffsetY;
                using (Brush textBrush = new SolidBrush(textColor))
                {
                    g.DrawString(this._text, textFont, textBrush, textStartX, textStartY);
                }
            }
        }
示例#13
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Image   buttonImage = null;
            DUIFont textDUIFont = null;
            Color   textColor   = Color.Empty;

            Rectangle buttonRectange;


            if (this.Status == ButtonStatus.Down)
            {
                if (!string.IsNullOrEmpty(this._backImageSourceNameDown))
                {
                    buttonImage = DUISkinManager.GetCurrentSkinManager().GetImageSource(this._backImageSourceNameDown);
                }
                textDUIFont = DUISkinManager.GetCurrentSkinManager().GetFont(this._textFontNameDown);
            }
            else if (this.Status == ButtonStatus.Hover)
            {
                if (!string.IsNullOrEmpty(this._backImageSourceNameHover))
                {
                    buttonImage = DUISkinManager.GetCurrentSkinManager().GetImageSource(this._backImageSourceNameHover);
                }
                textDUIFont = DUISkinManager.GetCurrentSkinManager().GetFont(this._textFontNameHover);
            }
            else if (this.Status == ButtonStatus.Normal)
            {
                if (!string.IsNullOrEmpty(this._backImageSourceNameNormal))
                {
                    buttonImage = DUISkinManager.GetCurrentSkinManager().GetImageSource(this._backImageSourceNameNormal);
                }
                textDUIFont = DUISkinManager.GetCurrentSkinManager().GetFont(this._textFontNameNormal);
            }
            else
            {
                ;
            }

            //绘制背景颜色
            e.Graphics.FillRectangle(new SolidBrush(this.BackColor), this.ClientRectangle);

            //绘制按钮图片
            if (buttonImage != null)
            {
                e.Graphics.DrawImage(buttonImage,
                                     new Rectangle((ClientRectangle.Width - buttonImage.Width) / 2,
                                                   (ClientRectangle.Height - buttonImage.Height) / 2,
                                                   buttonImage.Width, buttonImage.Height),
                                     0, 0, buttonImage.Width, buttonImage.Height, GraphicsUnit.Pixel);
            }

            //-------------------------------------------------------------------------------------
            //绘制按钮文字
            if (!string.IsNullOrEmpty(this.Text))
            {
                Font textFont = null;
                if (textDUIFont == null ||
                    textDUIFont.Font == null)
                {
                    //配置中没有指定标题字体的,使用系统默认字体
                    textFont = SystemFonts.DefaultFont;
                }
                else
                {
                    textFont = textDUIFont.Font;
                }

                if (textDUIFont == null ||
                    textDUIFont.ForeColor.Equals(Color.Empty))
                {
                    textColor = Color.Red; //红色突出字体颜色加载失败
                }
                else
                {
                    textColor = textDUIFont.ForeColor;
                }

                //------------------------------
                //计算按钮文字绘制位置
                Size textSize           = e.Graphics.MeasureString(this.Text, textFont).ToSize(); //计算文本绘制后的长度
                int  textInnerPositionX = 0;                                                      //按钮文字在按钮矩形内部的起始位置横坐标
                int  textInnerPositionY = 0;                                                      //按钮文字在按钮矩形内部的起始位置横坐标

                //根据文字对齐方式计算文字在按钮矩形内部的起始位置
                switch (this._textAlignment)
                {
                case ContentAlignment.TopLeft:
                    textInnerPositionX = 0;
                    textInnerPositionY = 0;
                    break;

                case ContentAlignment.TopCenter:
                    textInnerPositionX = (this.ClientRectangle.Width - textSize.Width) / 2;
                    textInnerPositionY = 0;
                    break;

                case ContentAlignment.TopRight:
                    textInnerPositionX = this.ClientRectangle.Width - textSize.Width;
                    textInnerPositionY = 0;
                    break;

                case ContentAlignment.MiddleLeft:
                    textInnerPositionX = 0;
                    textInnerPositionY = (this.ClientRectangle.Height - textSize.Height) / 2;
                    break;

                case ContentAlignment.MiddleCenter:
                    textInnerPositionX = (this.ClientRectangle.Width - textSize.Width) / 2;
                    textInnerPositionY = (this.ClientRectangle.Height - textSize.Height) / 2;
                    break;

                case ContentAlignment.MiddleRight:
                    textInnerPositionX = this.ClientRectangle.Width - textSize.Width;
                    textInnerPositionY = (this.ClientRectangle.Height - textSize.Height) / 2;
                    break;

                case ContentAlignment.BottomLeft:
                    textInnerPositionX = 0;
                    textInnerPositionY = this.ClientRectangle.Height - textSize.Height;
                    break;

                case ContentAlignment.BottomCenter:
                    textInnerPositionX = (this.ClientRectangle.Width - textSize.Width) / 2;
                    textInnerPositionY = this.ClientRectangle.Height - textSize.Height;
                    break;

                case ContentAlignment.BottomRight:
                    textInnerPositionX = this.ClientRectangle.Width - textSize.Width;
                    textInnerPositionY = this.ClientRectangle.Height - textSize.Height;
                    break;
                }

                //计算按钮文字在整个背景上的绘制起始位置,并绘制文字
                int textStartX = this.ClientRectangle.X + textInnerPositionX + this._textOffsetX;
                int textStartY = this.ClientRectangle.Y + textInnerPositionY + this._textOffsetY;
                using (Brush textBrush = new SolidBrush(textColor))
                {
                    e.Graphics.DrawString(this.Text, textFont, textBrush, textStartX, textStartY);
                }
            }
        }