コード例 #1
0
ファイル: StateItem.cs プロジェクト: MinhHuong/WSN-PN
        protected virtual void customIcon(Graphics graphics)
        {
            Brush      pthGrBrush  = Brushes.Black;
            Pen        pen         = Pens.Black;
            RectangleF EllipseFill = new RectangleF(AbsoluteX - 2, AbsoluteY - 2, 24, 24);

            GraphicsPath path = new GraphicsPath();

            path.AddEllipse(EllipseFill);

            Brush TextColor = Brushes.Black;

            switch (this.CurrentState)
            {
            case ItemState.Free:
                pthGrBrush = new SolidBrush(ColorDefinition.GetColorToFillState());
                break;

            case ItemState.Hover:
                pthGrBrush = new SolidBrush(ColorDefinition.GetColorWhenHover());
                TextColor  = Brushes.White;
                break;

            case ItemState.Selected:
                pthGrBrush = new SolidBrush(ColorDefinition.GetColorWhenSelected());
                break;

            default:
                break;
            } // switch

            graphics.FillEllipse(pthGrBrush, EllipseFill);
            graphics.DrawEllipse(pen, EllipseFill);

            if (initialState)
            {
                EllipseFill = new RectangleF(AbsoluteX + 1, AbsoluteY + 1, 18, 18);
                graphics.DrawEllipse(Pens.Black, EllipseFill);
            }
        }
コード例 #2
0
        //public override void DrawToGraphics(Graphics graphics)
        //{
        //    string label = this.ToLabelString();
        //    if (!string.IsNullOrEmpty(label))
        //    {
        //        Color color = Color.Black;
        //        switch (this.CurrentState)
        //        {
        //            case ItemState.Hover:
        //                color = ColorDefinition.GetColorWhenHover();
        //                break;
        //            case ItemState.Selected:
        //                color = ColorDefinition.GetColorWhenSelected();
        //                break;
        //        }
        //        RectangleF rect;
        //        float width = 0;
        //        float height = this.TitleFont.Size + 5;
        //        float currentWidth = 0;

        //        //Select
        //        label = GetSelectPart().Replace("\r\n", string.Empty);
        //        if (!string.IsNullOrEmpty(label))
        //        {
        //            if (CurrentState == ItemState.Free)
        //            {
        //                color = ColorDefinition.GetColorOfSelect();
        //            }

        //            currentWidth = graphics.MeasureString(label, this.TitleFont).Width;
        //            rect = new RectangleF(X + width, Y, currentWidth, height);
        //            graphics.DrawString(label, this.TitleFont, new SolidBrush(color), rect);
        //            width += currentWidth;
        //        }

        //        //Clock guard
        //        label = GetClockGuardPart().Replace("\r\n", string.Empty);
        //        if (!string.IsNullOrEmpty(label))
        //        {
        //            if (CurrentState == ItemState.Free)
        //            {
        //                color = ColorDefinition.GetColorOfClockGuard();
        //            }

        //            currentWidth = graphics.MeasureString(label, this.TitleFont).Width;
        //            rect = new RectangleF(X + width, Y, currentWidth, height);
        //            graphics.DrawString(label, this.TitleFont, new SolidBrush(color), rect);
        //            width += currentWidth;
        //        }

        //        //Guard
        //        label = GetGuardPart().Replace("\r\n", string.Empty);
        //        if (!string.IsNullOrEmpty(label))
        //        {
        //            if (CurrentState == ItemState.Free)
        //            {
        //                color = ColorDefinition.GetColorOfGuard();
        //            }
        //            currentWidth = graphics.MeasureString(label, this.TitleFont).Width;
        //            rect = new RectangleF(X + width, Y, currentWidth, height);
        //            graphics.DrawString(label, this.TitleFont, new SolidBrush(color), rect);
        //            width += currentWidth;
        //        }

        //        //Event
        //        label = GetEventPart().Replace("\r\n", string.Empty);
        //        if (!string.IsNullOrEmpty(label))
        //        {
        //            if (CurrentState == ItemState.Free)
        //            {
        //                color = ColorDefinition.GetColorOfEvent();
        //            }
        //            currentWidth = graphics.MeasureString(label, this.TitleFont).Width;
        //            rect = new RectangleF(X + width, Y, currentWidth, height);
        //            graphics.DrawString(label, this.TitleFont, new SolidBrush(color), rect);
        //            width += currentWidth;
        //        }

        //        //Program
        //        label = GetProgramPart().Replace("\r\n", string.Empty);
        //        if (!string.IsNullOrEmpty(label))
        //        {
        //            if (CurrentState == ItemState.Free)
        //            {
        //                color = ColorDefinition.GetColorOfProgram();
        //            }
        //            currentWidth = graphics.MeasureString(label, this.TitleFont).Width;
        //            rect = new RectangleF(X + width, Y, currentWidth, height);
        //            graphics.DrawString(label, this.TitleFont, new SolidBrush(color), rect);
        //            width += currentWidth;
        //        }

        //        //Clock Reset
        //        label = GetClockResetPart().Replace("\r\n", string.Empty);
        //        if (!string.IsNullOrEmpty(label))
        //        {
        //            if (CurrentState == ItemState.Free)
        //            {
        //                color = ColorDefinition.GetColorOfClockReset();
        //            }
        //            currentWidth = graphics.MeasureString(label, this.TitleFont).Width;
        //            rect = new RectangleF(X + width, Y, currentWidth, height);
        //            graphics.DrawString(label, this.TitleFont, new SolidBrush(color), rect);
        //            width += currentWidth;
        //        }

        //        if (Math.Abs(this.Width - width) > 15)
        //        {
        //            this.Width = width;
        //        }
        //    }
        //}
        #endregion Draw label multi color

        public override void DrawToGraphics(Graphics graphics)
        {
            string label = this.ToLabelString();

            if (!string.IsNullOrEmpty(label))
            {
                Color color = Color.Black;
                switch (this.CurrentState)
                {
                case ItemState.Hover:
                    color = ColorDefinition.GetColorWhenHover();
                    break;

                case ItemState.Selected:
                    color = ColorDefinition.GetColorWhenSelected();
                    break;

                default:
                    break;
                } // switch

                //Shorten label
                int allowedLength = 50;
                if (label.Length > allowedLength)
                {
                    label = label.Substring(0, allowedLength) + "...";
                }

                float      width  = graphics.MeasureString(label, this.TitleFont).Width;
                float      height = this.TitleFont.Size + 5;
                RectangleF rect   = new RectangleF(X, Y, width, height);

                graphics.DrawString(label, this.TitleFont, new SolidBrush(color), rect);

                if (Math.Abs(this.Width - width) > 15)
                {
                    this.Width = width;
                }
            }
        }
コード例 #3
0
        public override void DrawToGraphics(Graphics graphics)
        {
            Brush      pthGrBrush  = Brushes.Black;
            Pen        pen         = Pens.Black;
            RectangleF EllipseFill = new RectangleF(AbsoluteX - 2, AbsoluteY - 2, 24, 24);

            GraphicsPath path = new GraphicsPath();

            path.AddEllipse(EllipseFill);

            Brush TextColor = Brushes.Black;

            switch (this.CurrentState)
            {
            case ItemState.Free:
                pthGrBrush = new SolidBrush(ColorDefinition.GetColorToFillState());
                break;

            case ItemState.Hover:
                pthGrBrush = new SolidBrush(ColorDefinition.GetColorWhenHover());
                TextColor  = Brushes.White;
                break;

            case ItemState.Selected:
                pthGrBrush = new SolidBrush(ColorDefinition.GetColorWhenSelected());
                break;

            default:
                break;
            } // switch

            graphics.FillEllipse(pthGrBrush, EllipseFill);
            graphics.DrawEllipse(pen, EllipseFill);

            if (initialState)
            {
                EllipseFill = new RectangleF(AbsoluteX + 1, AbsoluteY + 1, 18, 18);
                graphics.DrawEllipse(Pens.Black, EllipseFill);
            }

            this.labelItems.labels.Clear();
            this.labelItems.colors.Clear();

            Color color = Color.Black;

            switch (this.CurrentState)
            {
            case ItemState.Hover:
                color = ColorDefinition.GetColorWhenHover();
                break;

            case ItemState.Selected:
                color = ColorDefinition.GetColorWhenSelected();
                break;

            default:
                break;
            } // switch

            if (this.CurrentState == ItemState.Free)
            {
                color = ColorDefinition.GetColorOfName();
            }
            this.labelItems.labels.Add(Name);
            this.labelItems.colors.Add(color);
            this.labelItems.DrawToGraphics(graphics);

            base.DrawToGraphics(graphics);
        }