Exemplo n.º 1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle rect = GeometryHelper.ApplyPadding(ClientRectangle, Padding);

            if (IsPressed)
            {
                rect = GeometryHelper.ApplyPadding(rect, PressExpansion);
            }

            StringFormat format = new StringFormat()
            {
                Alignment     = StringAlignment.Center,
                LineAlignment = StringAlignment.Center
            };

            using (Pen borderPen = new Pen(IsPressed ? PressedBorderColor : BorderColor, BorderWidth))
                e.Graphics.DrawRectangle(borderPen, rect);

            using (Brush fgBrush = new SolidBrush(IsPressed ? PressedForeColor : ForeColor))
                e.Graphics.DrawString(Text, Font, fgBrush, rect, format);

            base.OnPaint(e);
        }
Exemplo n.º 2
0
 protected override void OnPaintBackground(PaintEventArgs e)
 {
     base.OnPaintBackground(e);
     using (Brush brush = new SolidBrush(IsPressed ? PressedBackColor : BackColor))
         e.Graphics.FillRectangle(brush, IsPressed ? GeometryHelper.ApplyPadding(ClientRectangle, PressExpansion) : ClientRectangle);
 }
Exemplo n.º 3
0
        protected virtual RectangleF GetScrollThumbRectangle()
        {
            int   areaLength  = GeometryHelper.GetDimension(ClientRectangle, Orientation) - 2 * GeometryHelper.GetDimension(ButtonSize, Orientation);
            float thumbLength = areaLength * areaLength / (float)ScrollDistance;
            float offset      = ScrollValue / (float)ScrollDistance * (areaLength - thumbLength) + GeometryHelper.GetDimension(ButtonSize, Orientation);

            switch (Orientation)
            {
            case Orientation.Horizontal:
                return(new RectangleF(
                           ClientRectangle.Left + offset,
                           ClientRectangle.Top,
                           thumbLength,
                           Thickness
                           ));

            case Orientation.Vertical:
                return(new RectangleF(
                           ClientRectangle.Left,
                           ClientRectangle.Top + offset,
                           Thickness,
                           thumbLength
                           ));
            }
            throw new NotSupportedException();
        }
Exemplo n.º 4
0
        protected virtual void DrawItem(Item item, Graphics g, Rectangle bounds)
        {
            bool isSelected = (item == SelectedItem);

            if (!isSelected)
            {
                bounds = GeometryHelper.ApplyPadding(bounds, SelectionExpansion);
            }

            using (Brush bgBrush = new SolidBrush(isSelected ? SelectedItemBackColor : BackColor))
                g.FillRectangle(bgBrush, bounds);
            using (Pen borderPen = new Pen(isSelected ? SelectedItemBorderColor : ItemBorderColor, ItemBorderWidth))
                g.DrawRectangle(borderPen, bounds);

            const int margin = 5;

            bounds = GeometryHelper.ApplyPadding(bounds, new Padding(margin));

            StringFormat format = new StringFormat()
            {
                Alignment     = StringAlignment.Near,
                LineAlignment = StringAlignment.Center
            };

            int xOffset = 0;
            int yOffset = 0;

            if (ShowImages)
            {
                Size imageSize = new Size(bounds.Height, bounds.Height);
                if (item.Image != null)
                {
                    g.DrawImage(item.Image, new Rectangle(bounds.Location, imageSize));
                }
                xOffset += imageSize.Width + margin;
            }

            if (ShowTitles)
            {
                float      height   = ShowDetails ? 0.25f * bounds.Height : bounds.Height;
                RectangleF textRect = new RectangleF(bounds.Left + xOffset, bounds.Top + yOffset, bounds.Width - xOffset, height);

                using (Brush brush = new SolidBrush(ForeColor))
                    g.DrawString(item.Title, TitleFont, brush, textRect, format);

                yOffset += (int)height + margin;
            }

            if (ShowDetails)
            {
                RectangleF textRect = new RectangleF(
                    bounds.Left + xOffset,
                    bounds.Top + yOffset,
                    bounds.Width - xOffset,
                    bounds.Height - yOffset
                    );
                format.LineAlignment = StringAlignment.Near;
                using (Brush brush = new SolidBrush(ForeColor))
                    g.DrawString(item.Details, Font, brush, textRect, format);
            }
        }
Exemplo n.º 5
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (isDragging)
            {
                int pixelDistance = GeometryHelper.GetDimension(e.Location, Orientation) - GeometryHelper.GetDimension(lastDraggingPoint, Orientation);
                int areaLength    = GeometryHelper.GetDimension(ClientSize, Orientation) - 2 * GeometryHelper.GetDimension(ButtonSize, Orientation);
                int scrollDelta   = (int)(pixelDistance / (float)areaLength * ScrollDistance);

                ScrollValue       = Math.Min(Math.Max(ScrollValue + scrollDelta, MinimumValue), MaximumValue);
                lastDraggingPoint = e.Location;
            }
            base.OnMouseMove(e);
        }