Beispiel #1
0
        public override void Draw(Graphics graphics)
        {
            if (graphics == null)
            {
                return;
            }

            var box = new Rectangle()
            {
                Location = Corner, Size = Size
            };

            graphics.FillRectangle(FillBrush, box);

            if (IsSelected)
            {
                var g = new GraphicsWithSelection()
                {
                    MyGraphics = graphics
                };
                g.DrawSelectionBox(Corner, Size);
            }
            else
            {
                graphics.DrawRectangle(LinePen, box);
            }

            var minimumSize = graphics.MeasureString("...", TextFont);

            if (Size.Width < minimumSize.Width - Padding * 2 ||
                Size.Height < minimumSize.Height - Padding * 2)
            {
                return;
            }

            var formatter = new StringFormat
            {
                LineAlignment = StringAlignment.Center,
                Alignment     = StringAlignment.Center,
                Trimming      = StringTrimming.EllipsisCharacter
            };

            var textRectangle = new RectangleF(Corner.X + Padding, Corner.Y + Padding, Size.Width - Padding * 2, Size.Height - Padding * 2);

            graphics.DrawString(Label, TextFont, TextBrush, textRectangle, formatter);
        }
Beispiel #2
0
        public override void Draw(Graphics graphics)
        {
            if (graphics == null || IntrinsicState?.Image == null)
            {
                return;
            }

            graphics.DrawImage(IntrinsicState.Image,
                               new Rectangle(ExtrinsicState.Location.X, ExtrinsicState.Location.Y, ExtrinsicState.Size.Width,
                                             ExtrinsicState.Size.Height),
                               0, 0, IntrinsicState.Image.Width, IntrinsicState.Image.Height,
                               GraphicsUnit.Pixel);

            if (ExtrinsicState.IsSelected)
            {
                var g = new GraphicsWithSelection()
                {
                    MyGraphics = graphics
                };
                g.DrawSelectionBox(ExtrinsicState.Location, ExtrinsicState.Size);
            }
        }