コード例 #1
0
ファイル: CalendarViewEx.cs プロジェクト: windygu/sycorax
        protected virtual void OnPaintBody(PaintEventArgs pevent)
        {
            Graphics  g    = pevent.Graphics;
            Rectangle rc   = pevent.ClipRectangle;
            DateTime  date = new DateTime(m_iYear, m_iMonth, 1, 0, 0, 0);

            if (date.DayOfWeek != DayOfWeek.Sunday)
            {
                date = date.Subtract(new TimeSpan((int)date.DayOfWeek, 0, 0, 0, 0));
            }
            else
            {
                date = date.Subtract(new TimeSpan(7, 0, 0, 0, 0));
            }

            int iColWidth  = rc.Width / DEF_COLUMNS_COUNT;
            int iRowHeight = (rc.Height - DEF_WEEK_DAY_HEIGHT) / DEF_ROWS_COUNT;

            m_gdi.Draw3DLine(g, new Point(new Size(rc.X + 2, rc.Y + DEF_WEEK_DAY_HEIGHT - 1)),
                             new Point(new Size(rc.Right - 2, rc.Y + DEF_WEEK_DAY_HEIGHT - 1)));

            Rectangle rcHead = new Rectangle(rc.X, rc.Y, iColWidth, DEF_WEEK_DAY_HEIGHT - 2);

            for (int i = 0; i < DEF_COLUMNS_COUNT; i++)
            {
                rcHead.X = rc.X + i * iColWidth;
                string strDayWeek = "" + date.ToString("dddd")[0];

                g.DrawString(strDayWeek, this.Font,
                             (date.DayOfWeek != DayOfWeek.Sunday) ? SystemBrushes.WindowText : Brushes.Red,
                             rcHead, GDIUtils.OneLineNoTrimming);

                AddActiveRect(rcHead, TRectangleAction.WeekDay);

                if (m_iDay != 0) // We have correct day
                {
                    DateTime  dateNew = new DateTime(date.Ticks);
                    Brush     brush;
                    Rectangle rcDay = new Rectangle(rcHead.X, rc.Y + DEF_WEEK_DAY_HEIGHT, rcHead.Width, iRowHeight);

                    for (int j = 0; j < DEF_ROWS_COUNT; j++)
                    {
                        rcDay.Y = rc.Y + DEF_WEEK_DAY_HEIGHT + j * iRowHeight;
                        string strDay = dateNew.ToString("dd");
                        int    index  = -1;

                        if (m_iLastFocused == index && base.Focused == true)
                        {
                            g.FillRectangle(Brushes.Gray, rcDay);
                        }

                        if (dateNew.Day == m_today.Day && dateNew.Month == m_today.Month && dateNew.Year == m_today.Year)
                        {
                            g.DrawRectangle(Pens.Red, rcDay.X, rcDay.Y, rcDay.Width - 1, rcDay.Height - 1);
                        }

                        if (dateNew.Month != m_iMonth)
                        {
                            brush = Brushes.Gray;
                            index = -dateNew.Day;
                        }
                        else if (dateNew.DayOfWeek == DayOfWeek.Sunday)
                        {
                            brush = Brushes.Red;
                            index = dateNew.Day;
                        }
                        else
                        {
                            brush = SystemBrushes.WindowText;
                            index = dateNew.Day;
                        }

                        g.DrawString(strDay, this.Font, brush, rcDay, GDIUtils.OneLineNoTrimming);
                        AddActiveRect(rcDay, TRectangleAction.MonthDay, index);

                        if (m_iLastFocused == index && base.Focused == true)
                        {
                            ControlPaint.DrawFocusRectangle(g, Rectangle.Inflate(rcDay, -1, -1));
                        }

                        dateNew = dateNew.AddDays(7);
                    }
                }
                else // None day selected
                {
                    Rectangle rcNone = new Rectangle(rc.X, rc.Y + DEF_WEEK_DAY_HEIGHT,
                                                     rc.Width, rc.Height - DEF_WEEK_DAY_HEIGHT);

                    if (m_iLastFocused < DEF_TODAY_TAB_INDEX)
                    {
                        ControlPaint.DrawFocusRectangle(g, Rectangle.Inflate(rcNone, -2, -2));
                    }

                    g.DrawString("None", this.Font, SystemBrushes.WindowText, rcNone, GDIUtils.OneLineNoTrimming);
                }

                date = date.AddDays(1);
            }
        }
コード例 #2
0
        void m_Combo_DrawItem(object sender, DrawItemEventArgs e)
        {
            int iconWidth = SystemInformation.SmallIconSize.Width;
            int indent    = ((e.State & DrawItemState.ComboBoxEdit) == 0) ?
                            (iconWidth / 2) : 0;

            if (e.Index != -1)
            {
                string    display;
                ComboItem item      = (ComboItem)m_Combo.Items[e.Index];
                Color     textColor = SystemColors.WindowText;
                Rectangle textRect;
                int       textOffset;
                SizeF     size;

                if ((e.State & DrawItemState.ComboBoxEdit) != 0)
                {
                    // Don't draw the folder location in the edit box when
                    // the control is Editable as the edit control will
                    // take care of that.
                    display = m_Editable ? string.Empty : GetEditString();
                }
                else
                {
                    display = item.Folder.DisplayName;
                }

                size = TextRenderer.MeasureText(display, m_Combo.Font);

                textRect = new Rectangle(
                    e.Bounds.Left + iconWidth + (item.Indent * indent) + 3,
                    e.Bounds.Y, (int)size.Width, e.Bounds.Height);
                textOffset = (int)((e.Bounds.Height - size.Height) / 2);

                // If the text is being drawin in the main combo box edit area,
                // draw the text 1 pixel higher - this is how it looks in Windows.
                if ((e.State & DrawItemState.ComboBoxEdit) != 0)
                {
                    textOffset -= 1;
                }

                if ((e.State & DrawItemState.Selected) != 0)
                {
                    e.Graphics.FillRectangle(SystemBrushes.Highlight, textRect);
                    textColor = SystemColors.HighlightText;
                }
                else
                {
                    e.DrawBackground();
                }

                if ((e.State & DrawItemState.Focus) != 0)
                {
                    ControlPaint.DrawFocusRectangle(e.Graphics, textRect);
                }

                SystemImageList.DrawSmallImage(e.Graphics,
                                               new Point(e.Bounds.Left + (item.Indent * indent),
                                                         e.Bounds.Top),
                                               item.Folder.GetSystemImageListIndex(ShellIconType.SmallIcon,
                                                                                   ShellIconFlags.OverlayIndex),
                                               (e.State & DrawItemState.Selected) != 0);
                TextRenderer.DrawText(e.Graphics, display, m_Combo.Font,
                                      new Point(textRect.Left, textRect.Top + textOffset),
                                      textColor);
            }
        }
コード例 #3
0
        /// <summary>
        /// Raises the Paint event
        /// </summary>
        /// <param name="e">A PaintCellEventArgs that contains the event data</param>
        protected override void OnPaint(PaintCellEventArgs e)
        {
            base.OnPaint(e);

            // don't bother going any further if the Cell is null
            if (e.Cell == null)
            {
                return;
            }

            Rectangle textRect = this.CalcButtonBounds();

            textRect.Inflate(-4, -2);

            if (e.Cell.Image != null)
            {
                Rectangle imageRect = this.CalcImageRect(e.Cell.Image, this.ImageAlignment);

                if (this.GetButtonRendererData(e.Cell).ButtonState == PushButtonStates.Pressed && !ThemeManager.VisualStylesEnabled)
                {
                    imageRect.X += 1;
                    imageRect.Y += 1;
                }

                this.DrawImage(e.Graphics, e.Cell.Image, imageRect, e.Enabled);
            }

            // draw the text
            if (e.Cell.Text != null && e.Cell.Text.Length != 0)
            {
                if (e.Enabled)
                {
                    if (!ThemeManager.VisualStylesEnabled && this.GetButtonRendererData(e.Cell).ButtonState == PushButtonStates.Pressed)
                    {
                        textRect.X += 1;
                        textRect.Y += 1;
                    }

                    // if the cell or the row it is in is selected
                    // our forecolor will be the selection forecolor.
                    // we'll ignore this and reset our forecolor to
                    // that of the cell being rendered
                    if (e.Selected)
                    {
                        this.ForeColor = e.Cell.ForeColor;
                    }

                    e.Graphics.DrawString(e.Cell.Text, this.Font, this.ForeBrush, textRect, this.StringFormat);
                }
                else
                {
                    e.Graphics.DrawString(e.Cell.Text, this.Font, this.GrayTextBrush, textRect, this.StringFormat);
                }
            }

            // draw focus
            if (e.Focused && e.Enabled)
            {
                Rectangle focusRect = this.CalcButtonBounds();

                if (ThemeManager.VisualStylesEnabled)
                {
                    focusRect.Inflate(-3, -3);

                    if (this.GetButtonRendererData(e.Cell).ButtonState != PushButtonStates.Pressed)
                    {
                        ControlPaint.DrawFocusRectangle(e.Graphics, focusRect);
                    }
                }
                else
                {
                    focusRect.Inflate(-4, -4);

                    ControlPaint.DrawFocusRectangle(e.Graphics, focusRect);
                }
            }
        }
コード例 #4
0
        public static void DrawCheckBox(Graphics g, Rectangle rect, string text, Font font,
                                        Color foreColor, Color backColor,
                                        RightToLeft rightToLeft, bool isEnabled,
                                        bool isMouseOver, bool isFocused, bool drawLine, bool isChecked, CheckState checkState,
                                        Appearance appearance)
        {
            Rectangle checkRect = Rectangle.Empty;
            Rectangle textRect  = Rectangle.Empty;

            textRect = new Rectangle(rect.X + 4, rect.Y, rect.Width - 4, rect.Height);
            if (rightToLeft == RightToLeft.No)
            {
                checkRect = new Rectangle(rect.X, rect.Y + (rect.Height - 12) / 2 - 1, 12, 12);
            }
            else
            {
                checkRect = new Rectangle(rect.Right - 15, rect.Y + (rect.Height - 12) / 2 - 1, 12, 12);
            }

            if (appearance == Appearance.Normal)
            {
                if (rightToLeft == RightToLeft.No)
                {
                    textRect.X     += 10;
                    textRect.Width -= 10;
                }
                else
                {
                    textRect.Width -= 16;
                }

                #region PaintLine
                if (drawLine)
                {
                    using (Pen penLight = new Pen(StiColorUtils.Light(SystemColors.Control, 30)),
                           penDark = new Pen(StiColorUtils.Dark(SystemColors.Control, 50)))
                    {
                        int strWidth = (int)g.MeasureString(text, font).Width;

                        int posX = strWidth + 16 + rect.X;
                        int posY = rect.Y + rect.Height / 2;

                        if (posX < rect.Right)
                        {
                            g.DrawLine(penDark, posX, posY, rect.Right, posY);
                            g.DrawLine(penLight, posX, posY + 1, rect.Right, posY + 1);
                        }
                    }
                }
                #endregion

                if (isEnabled)
                {
                    using (var brush = new LinearGradientBrush(checkRect, StiColors.ContentDark, SystemColors.ControlLightLight, 45))
                    {
                        g.FillRectangle(brush, checkRect);
                    }
                }
                else
                {
                    g.FillRectangle(SystemBrushes.Control, checkRect);
                }

                if (isEnabled && (isMouseOver || isFocused))
                {
                    g.DrawRectangle(StiPens.SelectedText, checkRect);
                }
                else
                {
                    g.DrawRectangle(SystemPens.ControlDark, checkRect);
                }

                if (isChecked || checkState == CheckState.Indeterminate)
                {
                    StiControlPaint.DrawCheck(g, checkRect.X + 6, checkRect.Y + 6, isEnabled);
                }

                if (checkState == CheckState.Indeterminate)
                {
                    using (var brush = new SolidBrush(Color.FromArgb(200, SystemColors.Control)))
                    {
                        g.FillRectangle(brush,
                                        checkRect.X + 1, checkRect.Y + 1, checkRect.Width - 2, checkRect.Height - 2);
                    }
                }

                #region Paint focus
                if (isFocused)
                {
                    Rectangle focusRect = textRect;
                    SizeF     sizeText  = g.MeasureString(text, font);
                    focusRect.Width  = (int)sizeText.Width;
                    focusRect.Y      = (focusRect.Height - ((int)sizeText.Height + 2)) / 2;
                    focusRect.Height = (int)sizeText.Height + 2;

                    if (rightToLeft == RightToLeft.Yes)
                    {
                        focusRect.X = textRect.Right - focusRect.Width;
                    }

                    ControlPaint.DrawFocusRectangle(g, focusRect);
                }
                #endregion
            }
            else
            {
                StiButton.DrawButton(g, rect, text, font, foreColor, backColor, null, -1, null, rightToLeft,
                                     false, isEnabled, isMouseOver, isChecked, false, isFocused,
                                     ContentAlignment.BottomCenter, ContentAlignment.MiddleCenter);
            }

            #region Paint string
            if (appearance == Appearance.Normal)
            {
                using (var sf = new StringFormat())
                    using (var foreBrush = new SolidBrush(foreColor))
                    {
                        sf.FormatFlags   = StringFormatFlags.NoWrap;
                        sf.LineAlignment = StringAlignment.Center;
                        sf.Trimming      = StringTrimming.EllipsisCharacter;
                        sf.HotkeyPrefix  = HotkeyPrefix.Show;

                        if (rightToLeft == RightToLeft.Yes)
                        {
                            sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                        }

                        if (isEnabled)
                        {
                            g.DrawString(text, font, foreBrush, textRect, sf);
                        }
                        else
                        {
                            ControlPaint.DrawStringDisabled(g, text, font, backColor,
                                                            textRect, sf);
                        }
                    }
            }
            #endregion
        }
コード例 #5
0
        /// <summary>
        /// Raises the Paint event
        /// </summary>
        /// <param name="e">A PaintCellEventArgs that contains the event data</param>
        protected override void OnPaint(I3PaintCellEventArgs e)
        {
            base.OnPaint(e);

            // don't bother going any further if the Cell is null
            if (e.Cell == null)
            {
                return;
            }

            Rectangle textRect = this.CalcButtonBounds();

            textRect.Inflate(-4, -2);

            if (e.Cell.Image != null)
            {
                Rectangle imageRect = this.CalcImageRect(e.Cell.Image, this.ImageAlignment);

                if (this.GetButtonRendererData(e.Cell).ButtonState == I3PushButtonStates.Pressed && !I3ThemeManager.VisualStylesEnabled)
                {
                    imageRect.X += 1;
                    imageRect.Y += 1;
                }

                this.DrawImage(e.Graphics, e.Cell.Image, imageRect, e.Enabled);
            }

            // draw the text
            string text = e.Table.ColumnModel.Columns[e.Column].DataToString(e.Cell.Data);

            if (string.IsNullOrEmpty(text))
            {
                text = e.Table.ColumnModel.Columns[e.Column].Caption;
            }
            if (text != null && text.Length != 0)
            {
                if (e.Enabled)
                {
                    if (!I3ThemeManager.VisualStylesEnabled && this.GetButtonRendererData(e.Cell).ButtonState == I3PushButtonStates.Pressed)
                    {
                        textRect.X += 1;
                        textRect.Y += 1;
                    }

                    // if the cell or the row it is in is selected
                    // our forecolor will be the selection forecolor.
                    // we'll ignore this and reset our forecolor to
                    // that of the cell being rendered
                    if (e.Selected)
                    {
                        this.ForeColor = e.Cell.ForeColor;
                    }

                    e.Graphics.DrawString(text, this.Font, this.ForeBrush, textRect, this.StringFormat);
                }
                else
                {
                    e.Graphics.DrawString(text, this.Font, this.GrayTextBrush, textRect, this.StringFormat);
                }
            }

            //cal needWidth needHeigth
            int maxWidth = e.Table.ColumnModel.Columns[e.Column].CellTextAutoWarp ? e.Table.ColumnModel.Columns[e.Column].Width : 0;

            CalCellNeedSize(e.Graphics, e.Cell, text, this.Font, this.StringFormat, maxWidth, 6 + 6, 0);

            // draw focus
            if (e.Focused && e.Enabled)
            {
                Rectangle focusRect = this.CalcButtonBounds();

                if (I3ThemeManager.VisualStylesEnabled)
                {
                    focusRect.Inflate(-3, -3);

                    if (this.GetButtonRendererData(e.Cell).ButtonState != I3PushButtonStates.Pressed)
                    {
                        ControlPaint.DrawFocusRectangle(e.Graphics, focusRect);
                    }
                }
                else
                {
                    focusRect.Inflate(-4, -4);

                    ControlPaint.DrawFocusRectangle(e.Graphics, focusRect);
                }
            }
        }
コード例 #6
0
        protected virtual void OnPaintForeground(PaintEventArgs e)
        {
            Color borderColor, foreColor;

            if (useCustomForeColor)
            {
                foreColor = ForeColor;

                if (isHovered && !isPressed && Enabled)
                {
                    borderColor = ForeColor;// MetroPaint.BorderColor.CheckBox.Hover(Theme);
                }
                else if (isHovered && isPressed && Enabled)
                {
                    borderColor = MetroPaint.BorderColor.CheckBox.Press(Theme);
                }
                else if (!Enabled)
                {
                    borderColor = MetroPaint.BorderColor.CheckBox.Disabled(Theme);
                }
                else
                {
                    borderColor = MetroPaint.BorderColor.CheckBox.Normal(Theme);
                }
            }
            else
            {
                if (isHovered && !isPressed && Enabled)
                {
                    foreColor   = MetroPaint.ForeColor.CheckBox.Hover(Theme);
                    borderColor = MetroPaint.BorderColor.CheckBox.Hover(Theme);
                }
                else if (isHovered && isPressed && Enabled)
                {
                    foreColor   = MetroPaint.ForeColor.CheckBox.Press(Theme);
                    borderColor = MetroPaint.BorderColor.CheckBox.Press(Theme);
                }
                else if (!Enabled)
                {
                    foreColor   = MetroPaint.ForeColor.CheckBox.Disabled(Theme);
                    borderColor = MetroPaint.BorderColor.CheckBox.Disabled(Theme);
                }
                else
                {
                    foreColor = !useStyleColors?MetroPaint.ForeColor.CheckBox.Normal(Theme) : MetroPaint.GetStyleColor(Style);

                    borderColor = MetroPaint.BorderColor.CheckBox.Normal(Theme);
                }
            }

            Rectangle textRect = new Rectangle(16, 0, Width - 16, Height);
            Rectangle boxRect  = new Rectangle(0, Height / 2 - 6, 12, 12);

            using (Pen p = new Pen(borderColor))
            {
                switch (CheckAlign)
                {
                case ContentAlignment.TopLeft:
                    boxRect = new Rectangle(0, 0, 12, 12);
                    break;

                case ContentAlignment.MiddleLeft:
                    boxRect = new Rectangle(0, Height / 2 - 6, 12, 12);
                    break;

                case ContentAlignment.BottomLeft:
                    boxRect = new Rectangle(0, Height - 13, 12, 12);
                    break;

                case ContentAlignment.TopCenter:
                    boxRect  = new Rectangle(Width / 2 - 6, 0, 12, 12);
                    textRect = new Rectangle(16, boxRect.Top + boxRect.Height - 5, Width - 16 / 2, Height);
                    break;

                case ContentAlignment.BottomCenter:
                    boxRect  = new Rectangle(Width / 2 - 6, Height - 13, 12, 12);
                    textRect = new Rectangle(16, -10, Width - 16 / 2, Height);
                    break;

                case ContentAlignment.MiddleCenter:
                    boxRect = new Rectangle(Width / 2 - 6, Height / 2 - 6, 12, 12);
                    break;

                case ContentAlignment.TopRight:
                    boxRect  = new Rectangle(Width - 13, 0, 12, 12);
                    textRect = new Rectangle(0, 0, Width - 16, Height);
                    break;

                case ContentAlignment.MiddleRight:
                    boxRect  = new Rectangle(Width - 13, Height / 2 - 6, 12, 12);
                    textRect = new Rectangle(0, 0, Width - 16, Height);
                    break;

                case ContentAlignment.BottomRight:
                    boxRect  = new Rectangle(Width - 13, Height - 13, 12, 12);
                    textRect = new Rectangle(0, 0, Width - 16, Height);
                    break;
                }

                e.Graphics.DrawRectangle(p, boxRect);
            }

            if (Checked)
            {
                Color fillColor = CheckState == CheckState.Indeterminate ? borderColor : MetroPaint.GetStyleColor(Style);

                using (SolidBrush b = new SolidBrush(fillColor))
                {
                    Rectangle boxCheck = new Rectangle(boxRect.Left + 2, boxRect.Top + 2, 9, 9);
                    e.Graphics.FillRectangle(b, boxCheck);
                }
            }


            TextRenderer.DrawText(e.Graphics, Text, MetroFonts.CheckBox(metroCheckBoxSize, metroCheckBoxWeight), textRect, foreColor, MetroPaint.GetTextFormatFlags(TextAlign));

            OnCustomPaintForeground(new MetroPaintEventArgs(Color.Empty, foreColor, e.Graphics));

            if (displayFocusRectangle && isFocused)
            {
                ControlPaint.DrawFocusRectangle(e.Graphics, ClientRectangle);
            }
        }
コード例 #7
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Color backColor, borderColor, foreColor;

            if (useCustomBackground)
            {
                backColor = BackColor;
            }
            else
            {
                backColor = MetroPaint.BackColor.Form(Theme);
            }

            if (useCustomForeColor)
            {
                foreColor = ForeColor;

                if (isHovered && !isPressed && Enabled)
                {
                    borderColor = MetroPaint.BorderColor.CheckBox.Hover(Theme);
                }
                else if (isHovered && isPressed && Enabled)
                {
                    borderColor = MetroPaint.BorderColor.CheckBox.Press(Theme);
                }
                else if (!Enabled)
                {
                    borderColor = MetroPaint.BorderColor.CheckBox.Disabled(Theme);
                }
                else
                {
                    borderColor = MetroPaint.BorderColor.CheckBox.Normal(Theme);
                }
            }
            else
            {
                if (isHovered && !isPressed && Enabled)
                {
                    foreColor   = MetroPaint.ForeColor.CheckBox.Hover(Theme);
                    borderColor = MetroPaint.BorderColor.CheckBox.Hover(Theme);
                }
                else if (isHovered && isPressed && Enabled)
                {
                    foreColor   = MetroPaint.ForeColor.CheckBox.Press(Theme);
                    borderColor = MetroPaint.BorderColor.CheckBox.Press(Theme);
                }
                else if (!Enabled)
                {
                    foreColor   = MetroPaint.ForeColor.CheckBox.Disabled(Theme);
                    borderColor = MetroPaint.BorderColor.CheckBox.Disabled(Theme);
                }
                else
                {
                    foreColor = !useStyleColors?MetroPaint.ForeColor.CheckBox.Normal(Theme) : MetroPaint.GetStyleColor(Style);

                    borderColor = MetroPaint.BorderColor.CheckBox.Normal(Theme);
                }
            }

            e.Graphics.Clear(backColor);

            e.Graphics.SmoothingMode = SmoothingMode.HighQuality;

            using (Pen p = new Pen(borderColor))
            {
                Rectangle boxRect = new Rectangle(0, Height / 2 - 6, 12, 12);
                e.Graphics.DrawEllipse(p, boxRect);
            }

            if (Checked)
            {
                Color fillColor = MetroPaint.GetStyleColor(Style);

                using (SolidBrush b = new SolidBrush(fillColor))
                {
                    Rectangle boxRect = new Rectangle(3, Height / 2 - 3, 6, 6);
                    e.Graphics.FillEllipse(b, boxRect);
                }
            }

            e.Graphics.SmoothingMode = SmoothingMode.Default;

            Rectangle textRect = new Rectangle(16, 0, Width - 16, Height);

            TextRenderer.DrawText(e.Graphics, Text, MetroFonts.Link(metroLinkSize, metroLinkWeight), textRect, foreColor, backColor, MetroPaint.GetTextFormatFlags(TextAlign));

            if (false && isFocused)
            {
                ControlPaint.DrawFocusRectangle(e.Graphics, ClientRectangle);
            }
        }
コード例 #8
0
        void ForwardListView_DrawItem(object sender, DrawListViewItemEventArgs e)

        {
            if (this.View == View.Tile)

            {
                int checkBoxAreaWidth = CHECKBOX_PADDING + CHECKBOX_SIZE + CHECKBOX_PADDING;

                System.Drawing.Rectangle bounds = new System.Drawing.Rectangle(e.Bounds.X + checkBoxAreaWidth, e.Bounds.Top, e.Bounds.Width - checkBoxAreaWidth, e.Bounds.Height);



                // update information

                DestinationBase fc = (DestinationBase)e.Item.Tag;

                string display = Escape(fc.Display);

                string address = Escape(fc.AddressDisplay);

                string additional = Escape(fc.AdditionalDisplayInfo);

                string tooltip = String.Format("{0}\r\n{1}{2}", fc.Display, fc.AddressDisplay, (!String.IsNullOrEmpty(fc.AdditionalDisplayInfo) ? String.Format("\r\n{0}", fc.AdditionalDisplayInfo) : null));

                e.Item.ToolTipText = tooltip;

                // NOTE: dont set the .Text or .SubItem properties here - it causes an erratic exception



                bool drawEnabled = ShouldDrawEnabled(fc);

                bool selected = this.SelectedIndices.Contains(e.ItemIndex);



                // draw the background for selected states

                if (drawEnabled && selected)

                {
                    e.Graphics.FillRectangle(System.Drawing.Brushes.LightGray, e.Bounds);
                }

                else

                {
                    e.DrawBackground();
                }



                // draw the focus rectangle

                if (selected)
                {
                    ControlPaint.DrawFocusRectangle(e.Graphics, e.Bounds);
                }



                // draw icon

                int newX = bounds.X;

                DestinationBase db = e.Item.Tag as DestinationBase;

                if (db != null)

                {
                    System.Drawing.Image img = db.GetIcon();



                    // size

                    if (img.Width > IMAGE_SIZE)

                    {
                        System.Drawing.Image resized = new System.Drawing.Bitmap(IMAGE_SIZE, IMAGE_SIZE);

                        System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(resized);

                        using (g)

                        {
                            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                            g.DrawImage(img, 0, 0, IMAGE_SIZE, IMAGE_SIZE);
                        }

                        img = resized;
                    }



                    if (img != null)

                    {
                        int x = bounds.X;

                        int y = bounds.Top;

                        if (drawEnabled)
                        {
                            e.Graphics.DrawImage(img, new System.Drawing.Rectangle(x, y, img.Width, img.Height));
                        }

                        else
                        {
                            ControlPaint.DrawImageDisabled(e.Graphics, img, x, y, System.Drawing.Color.Transparent);
                        }

                        newX += IMAGE_SIZE + this.Margin.Right;
                    }
                }



                // offset the text vertically a bit so it lines up with the icon better

                System.Drawing.RectangleF rect = new System.Drawing.RectangleF(newX, bounds.Top, bounds.Right - newX, e.Item.Font.Height);

                rect.Offset(0, 4);



                // draw main text

                System.Drawing.Color textColor = (drawEnabled ? e.Item.ForeColor : System.Drawing.Color.FromArgb(System.Drawing.SystemColors.GrayText.ToArgb()));

                System.Drawing.StringFormat sf = new System.Drawing.StringFormat();

                sf.Trimming = System.Drawing.StringTrimming.EllipsisCharacter;

                sf.FormatFlags = System.Drawing.StringFormatFlags.NoClip;

                System.Drawing.SolidBrush textBrush = new System.Drawing.SolidBrush(textColor);

                using (textBrush)

                {
                    e.Graphics.DrawString(display,

                                          e.Item.Font,

                                          textBrush,

                                          rect,

                                          sf);
                }



                // draw additional information text

                System.Drawing.Color subColor = System.Drawing.Color.FromArgb(System.Drawing.SystemColors.GrayText.ToArgb());

                System.Drawing.SolidBrush subBrush = new System.Drawing.SolidBrush(subColor);

                using (subBrush)

                {
                    // draw address display (line 2)

                    rect.Offset(0, e.Item.Font.Height);

                    e.Graphics.DrawString(address,

                                          e.Item.Font,

                                          subBrush,

                                          rect,

                                          sf);



                    // draw additional display (line 3)

                    rect.Offset(0, e.Item.Font.Height);

                    e.Graphics.DrawString(additional,

                                          e.Item.Font,

                                          subBrush,

                                          rect,

                                          sf);
                }



                // draw checkbox

                System.Windows.Forms.VisualStyles.CheckBoxState state = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal;

                if (fc.Enabled)
                {
                    state = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal;
                }

                else
                {
                    state = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal;
                }

                CheckBoxRenderer.DrawCheckBox(e.Graphics, new System.Drawing.Point(e.Bounds.Left + CHECKBOX_PADDING, e.Bounds.Top + CHECKBOX_PADDING), state);
            }

            else

            {
                e.DrawDefault = true;
            }
        }
コード例 #9
0
        /// <summary>
        /// Performs custom painting for a list item.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            base.OnDrawItem(e);

            if ((e.Index >= 0) && (e.Index < Items.Count))
            {
                // get noteworthy states
                bool comboBoxEdit  = (e.State & DrawItemState.ComboBoxEdit) == DrawItemState.ComboBoxEdit;
                bool selected      = (e.State & DrawItemState.Selected) == DrawItemState.Selected;
                bool noAccelerator = (e.State & DrawItemState.NoAccelerator) == DrawItemState.NoAccelerator;
                bool disabled      = (e.State & DrawItemState.Disabled) == DrawItemState.Disabled;
                bool focus         = (e.State & DrawItemState.Focus) == DrawItemState.Focus;

                // determine grouping
                string groupText;
                bool   isGroupStart = IsGroupStart(e.Index, out groupText) && !comboBoxEdit;


                bool hasGroup = (groupText != String.Empty) && !comboBoxEdit;

                // the item text will appear in a different colour, depending on its state
                Color textColor;
                if (disabled)
                {
                    textColor = SystemColors.GrayText;
                }
                else if (!comboBoxEdit && selected)
                {
                    textColor = SystemColors.HighlightText;
                }
                else
                {
                    textColor = ForeColor;
                }

                // items will be indented if they belong to a group
                Rectangle itemBounds =
                    Rectangle.FromLTRB(
                        e.Bounds.X + (hasGroup ? 12 : 0),
                        e.Bounds.Y + (isGroupStart ? (e.Bounds.Height / 2) : 0),
                        e.Bounds.Right,
                        e.Bounds.Bottom
                        );
                Rectangle groupBounds = new Rectangle(
                    e.Bounds.X,
                    e.Bounds.Y,
                    e.Bounds.Width,
                    e.Bounds.Height / 2
                    );

                if (isGroupStart && selected)
                {
                    // ensure that the group header is never highlighted
                    e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds);
                    e.Graphics.FillRectangle(new SolidBrush(BackColor), groupBounds);
                }
                else if (disabled)
                {
                    // disabled appearance
                    e.Graphics.FillRectangle(Brushes.WhiteSmoke, e.Bounds);
                }
                else if (!comboBoxEdit)
                {
                    // use the default background-painting logic
                    e.DrawBackground();
                }

                /*
                 * var backgroundColor = new SolidBrush(BackColor);
                 *
                 * if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                 * {
                 *  if (e.Index < 1)
                 *  {
                 *      backgroundColor = new SolidBrush(Color.White);
                 *  }
                 *  else
                 *  {
                 *      backgroundColor = new SolidBrush(Color.SandyBrown);
                 *  }
                 *
                 * }
                 * else
                 * {
                 *  backgroundColor = new SolidBrush(BackColor);
                 * }
                 */


                // render group header text
                if (isGroupStart)
                {
                    TextRenderer.DrawText(
                        e.Graphics,
                        groupText,
                        _groupFont,
                        groupBounds,
                        GroupColor,
                        _textFormatFlags
                        );
                }

                if (!Focused)
                {
                    itemBounds.Inflate(2, 0);
                }

                if (e.Index < 1)
                {
                    var txt = new Font(new FontFamily("Lato"), 9.25f);
                    var clr = Color.Gray;

                    e.Graphics.FillRectangle(new SolidBrush(BackColor), itemBounds);
                    TextRenderer.DrawText(
                        e.Graphics,
                        GetItemText(Items[e.Index]),
                        txt,
                        itemBounds,
                        clr,
                        _textFormatFlags
                        );
                }
                else
                {
                    // render item text
                    TextRenderer.DrawText(
                        e.Graphics,
                        GetItemText(Items[e.Index]),
                        Font,
                        itemBounds,
                        textColor,
                        _textFormatFlags
                        );

                    int vertScrollBarWidth = (Items.Count > MaxDropDownItems) ? SystemInformation.VerticalScrollBarWidth : 0;

                    int newWidth = (int)e.Graphics.MeasureString(GetItemText(Items[e.Index]), Font).Width + vertScrollBarWidth;
                    newWidth += 20;
                    if (newWidth > DropDownWidth)
                    {
                        DropDownWidth = newWidth;
                    }
                }


                // paint the focus rectangle if required
                if (focus && !noAccelerator)
                {
                    if (isGroupStart && selected)
                    {
                        // don't draw the focus rectangle around the group header
                        ControlPaint.DrawFocusRectangle(e.Graphics, Rectangle.FromLTRB(groupBounds.X, itemBounds.Y, itemBounds.Right, itemBounds.Bottom));
                    }
                    else
                    {
                        // use default focus rectangle painting logic
                        e.DrawFocusRectangle();
                    }
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Raises the Paint event
        /// </summary>
        /// <param name="e">A PaintCellEventArgs that contains the event data</param>
        protected override void OnPaint(PaintCellEventArgs e)
        {
            base.OnPaint(e);

            // don't bother if the Cell is null or doesn't have an image
            if (e.Cell == null || e.Cell.Image == null)
            {
                return;
            }

            // work out the size and location of the image
            Rectangle imageRect = this.CalcImageRect(e.Cell.Image, e.Cell.ImageSizeMode, this.LineAlignment, this.Alignment);

            // draw the image
            bool scaled = (this.DrawText || e.Cell.ImageSizeMode != ImageSizeMode.Normal);

            this.DrawImage(e.Graphics, e.Cell.Image, imageRect, scaled, e.Table.Enabled);

            int textWidth = 0;

            // check if we need to draw any text
            if (this.DrawText)
            {
                if (e.Cell.Text != null && e.Cell.Text.Length != 0)
                {
                    if (e.Cell.WidthNotSet)
                    {
                        SizeF size = e.Graphics.MeasureString(e.Cell.Text, this.Font);
                        textWidth = (int)Math.Ceiling(size.Width);
                    }

                    // rectangle the text will be drawn in
                    Rectangle textRect = this.ClientRectangle;

                    // take the imageRect into account so we don't
                    // draw over it
                    textRect.X     += imageRect.Width;
                    textRect.Width -= imageRect.Width;

                    // check that we will be able to see the text
                    if (textRect.Width > 0)
                    {
                        // draw the text
                        if (e.Enabled)
                        {
                            e.Graphics.DrawString(e.Cell.Text, this.Font, this.ForeBrush, textRect, this.StringFormat);
                        }
                        else
                        {
                            e.Graphics.DrawString(e.Cell.Text, this.Font, this.GrayTextBrush, textRect, this.StringFormat);
                        }
                    }
                }
            }

            if (e.Cell.WidthNotSet)
            {
                SizeF size = e.Graphics.MeasureString(e.Cell.Text, this.Font);
                e.Cell.ContentWidth = textWidth + e.Cell.Image.Width;
            }

            if ((e.Focused && e.Enabled)
                // only if we want to show selection rectangle
                && (e.Table.ShowSelectionRectangle))
            {
                ControlPaint.DrawFocusRectangle(e.Graphics, this.ClientRectangle);
            }
        }
コード例 #11
0
        private bool HandleCustomDraw(ref Message msg)
        {
            // TODO this needs to be cleaned
            if (Config.Tweaks.AlternateRowColors && (ShellBrowser.ViewMode == FVM.DETAILS))
            {
                NMLVCUSTOMDRAW structure  = (NMLVCUSTOMDRAW)Marshal.PtrToStructure(msg.LParam, typeof(NMLVCUSTOMDRAW));
                int            dwItemSpec = 0;
                if ((ulong)structure.nmcd.dwItemSpec < Int32.MaxValue)
                {
                    dwItemSpec = (int)structure.nmcd.dwItemSpec;
                }
                switch (structure.nmcd.dwDrawStage)
                {
                case CDDS.SUBITEM | CDDS.ITEMPREPAINT:
                    iListViewItemState = (int)PInvoke.SendMessage(
                        ListViewController.Handle, LVM.GETITEMSTATE, structure.nmcd.dwItemSpec,
                        (IntPtr)(LVIS.FOCUSED | LVIS.SELECTED | LVIS.DROPHILITED));

                    if (!QTUtility.IsXP)
                    {
                        int num4 = lstColumnFMT[structure.iSubItem];
                        structure.clrTextBk = QTUtility2.MakeCOLORREF(Config.Tweaks.AltRowBackgroundColor);
                        structure.clrText   = QTUtility2.MakeCOLORREF(Config.Tweaks.AltRowForegroundColor);
                        Marshal.StructureToPtr(structure, msg.LParam, false);
                        bool drawingHotItem = (dwItemSpec == GetHotItem());
                        bool fullRowSel     = !Config.Tweaks.ToggleFullRowSelect;

                        msg.Result = (IntPtr)(CDRF.NEWFONT);
                        if (structure.iSubItem == 0 && !drawingHotItem)
                        {
                            if (iListViewItemState == 0 && (num4 & 0x600) != 0)
                            {
                                msg.Result = (IntPtr)(CDRF.NEWFONT | CDRF.NOTIFYPOSTPAINT);
                            }
                            else if (iListViewItemState == LVIS.FOCUSED && !fullRowSel)
                            {
                                msg.Result = (IntPtr)(CDRF.NEWFONT | CDRF.NOTIFYPOSTPAINT);
                            }
                        }

                        if (structure.iSubItem > 0 && (!fullRowSel || !drawingHotItem))
                        {
                            if (!fullRowSel || (iListViewItemState & (LVIS.SELECTED | LVIS.DROPHILITED)) == 0)
                            {
                                using (Graphics graphics = Graphics.FromHdc(structure.nmcd.hdc)) {
                                    if (sbAlternate == null || sbAlternate.Color != Config.Tweaks.AltRowBackgroundColor)
                                    {
                                        sbAlternate = new SolidBrush(Config.Tweaks.AltRowBackgroundColor);
                                    }
                                    graphics.FillRectangle(sbAlternate, structure.nmcd.rc.ToRectangle());
                                }
                            }
                        }
                    }
                    else
                    {
                        msg.Result = (IntPtr)(CDRF.NOTIFYPOSTPAINT);
                    }
                    return(true);

                case CDDS.SUBITEM | CDDS.ITEMPOSTPAINT: {
                    RECT rc = structure.nmcd.rc;
                    if (QTUtility.IsXP)
                    {
                        rc = PInvoke.ListView_GetItemRect(ListViewController.Handle, dwItemSpec, structure.iSubItem, 2);
                    }
                    else
                    {
                        rc.left += 0x10;
                    }
                    bool flag3 = false;
                    bool flag4 = false;
                    bool flag5 = Config.Tweaks.DetailsGridLines;
                    bool flag6 = Config.Tweaks.ToggleFullRowSelect ^ !QTUtility.IsXP;
                    bool flag7 = false;
                    if (QTUtility.IsXP && QTUtility.fSingleClick)
                    {
                        flag7 = (dwItemSpec == GetHotItem());
                    }
                    LVITEM lvitem = new LVITEM();
                    lvitem.pszText    = Marshal.AllocHGlobal(520);
                    lvitem.cchTextMax = 260;
                    lvitem.iSubItem   = structure.iSubItem;
                    lvitem.iItem      = dwItemSpec;
                    lvitem.mask       = 1;
                    IntPtr ptr3 = Marshal.AllocHGlobal(Marshal.SizeOf(lvitem));
                    Marshal.StructureToPtr(lvitem, ptr3, false);
                    PInvoke.SendMessage(ListViewController.Handle, LVM.GETITEM, IntPtr.Zero, ptr3);
                    if (sbAlternate == null)
                    {
                        sbAlternate = new SolidBrush(Config.Tweaks.AltRowBackgroundColor);
                    }
                    using (Graphics graphics2 = Graphics.FromHdc(structure.nmcd.hdc)) {
                        Rectangle rect = rc.ToRectangle();
                        if (flag5)
                        {
                            rect = new Rectangle(rc.left + 1, rc.top, rc.Width - 1, rc.Height - 1);
                        }
                        graphics2.FillRectangle(sbAlternate, rect);
                        if (QTUtility.IsXP && ((structure.iSubItem == 0) || flag6))
                        {
                            flag4 = (iListViewItemState & 8) == 8;
                            if ((iListViewItemState != 0) && (((iListViewItemState == 1) && fListViewHasFocus) || (iListViewItemState != 1)))
                            {
                                int width;
                                if (flag6)
                                {
                                    width = rc.Width;
                                }
                                else
                                {
                                    width = 8 + ((int)PInvoke.SendMessage(ListViewController.Handle, LVM.GETSTRINGWIDTH, IntPtr.Zero, lvitem.pszText));
                                    if (width > rc.Width)
                                    {
                                        width = rc.Width;
                                    }
                                }
                                Rectangle rectangle2 = new Rectangle(rc.left, rc.top, width, flag5 ? (rc.Height - 1) : rc.Height);
                                if (((iListViewItemState & 2) == 2) || flag4)
                                {
                                    if (flag4)
                                    {
                                        graphics2.FillRectangle(SystemBrushes.Highlight, rectangle2);
                                    }
                                    else if (QTUtility.fSingleClick && flag7)
                                    {
                                        graphics2.FillRectangle(fListViewHasFocus ? SystemBrushes.HotTrack : SystemBrushes.Control, rectangle2);
                                    }
                                    else
                                    {
                                        graphics2.FillRectangle(fListViewHasFocus ? SystemBrushes.Highlight : SystemBrushes.Control, rectangle2);
                                    }
                                    flag3 = true;
                                }
                                if ((fListViewHasFocus && ((iListViewItemState & 1) == 1)) && !flag6)
                                {
                                    ControlPaint.DrawFocusRectangle(graphics2, rectangle2);
                                }
                            }
                        }
                        if (!QTUtility.IsXP && ((iListViewItemState & 1) == 1))
                        {
                            int num6 = rc.Width;
                            if (!flag6)
                            {
                                num6 = 4 + ((int)PInvoke.SendMessage(ListViewController.Handle, LVM.GETSTRINGWIDTH, IntPtr.Zero, lvitem.pszText));
                                if (num6 > rc.Width)
                                {
                                    num6 = rc.Width;
                                }
                            }
                            Rectangle rectangle = new Rectangle(rc.left + 1, rc.top + 1, num6, flag5 ? (rc.Height - 2) : (rc.Height - 1));
                            ControlPaint.DrawFocusRectangle(graphics2, rectangle);
                        }
                    }
                    IntPtr zero    = IntPtr.Zero;
                    IntPtr hgdiobj = IntPtr.Zero;
                    if (QTUtility.IsXP && QTUtility.fSingleClick)
                    {
                        LOGFONT logfont;
                        zero = PInvoke.GetCurrentObject(structure.nmcd.hdc, 6);
                        PInvoke.GetObject(zero, Marshal.SizeOf(typeof(LOGFONT)), out logfont);
                        if ((structure.iSubItem == 0) || flag6)
                        {
                            logfont.lfUnderline = ((QTUtility.iIconUnderLineVal == 3) || flag7) ? ((byte)1) : ((byte)0);
                        }
                        else
                        {
                            logfont.lfUnderline = 0;
                        }
                        hgdiobj = PInvoke.CreateFontIndirect(ref logfont);
                        PInvoke.SelectObject(structure.nmcd.hdc, hgdiobj);
                    }
                    PInvoke.SetBkMode(structure.nmcd.hdc, 1);
                    int dwDTFormat = 0x8824;
                    if (QTUtility.IsRTL ? ((lstColumnFMT[structure.iSubItem] & 1) == 0) : ((lstColumnFMT[structure.iSubItem] & 1) == 1))
                    {
                        if (QTUtility.IsRTL)
                        {
                            dwDTFormat &= -3;
                        }
                        else
                        {
                            dwDTFormat |= 2;
                        }
                        rc.right -= 6;
                    }
                    else if (structure.iSubItem == 0)
                    {
                        rc.left  += 2;
                        rc.right -= 2;
                    }
                    else
                    {
                        rc.left += 6;
                    }
                    if (flag3)
                    {
                        PInvoke.SetTextColor(structure.nmcd.hdc, QTUtility2.MakeCOLORREF((fListViewHasFocus || flag4) ? SystemColors.HighlightText : SystemColors.WindowText));
                    }
                    else
                    {
                        PInvoke.SetTextColor(structure.nmcd.hdc, QTUtility2.MakeCOLORREF(Config.Tweaks.AltRowForegroundColor));
                    }
                    PInvoke.DrawTextExW(structure.nmcd.hdc, lvitem.pszText, -1, ref rc, dwDTFormat, IntPtr.Zero);
                    Marshal.FreeHGlobal(lvitem.pszText);
                    Marshal.FreeHGlobal(ptr3);
                    msg.Result = IntPtr.Zero;
                    if (zero != IntPtr.Zero)
                    {
                        PInvoke.SelectObject(structure.nmcd.hdc, zero);
                    }
                    if (hgdiobj != IntPtr.Zero)
                    {
                        PInvoke.DeleteObject(hgdiobj);
                    }
                    return(true);
                }

                case CDDS.ITEMPREPAINT:
                    if ((dwItemSpec % 2) == 0)
                    {
                        msg.Result = (IntPtr)0x20;
                        return(true);
                    }
                    msg.Result = IntPtr.Zero;
                    return(false);

                case CDDS.PREPAINT: {
                    HDITEM hditem = new HDITEM();
                    hditem.mask = 4;
                    IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(hditem));
                    Marshal.StructureToPtr(hditem, ptr, false);
                    IntPtr hWnd = PInvoke.SendMessage(ListViewController.Handle, LVM.GETHEADER, IntPtr.Zero, IntPtr.Zero);
                    int    num2 = (int)PInvoke.SendMessage(hWnd, 0x1200, IntPtr.Zero, IntPtr.Zero);
                    if (lstColumnFMT == null)
                    {
                        lstColumnFMT = new List <int>();
                    }
                    else
                    {
                        lstColumnFMT.Clear();
                    }
                    for (int i = 0; i < num2; i++)
                    {
                        PInvoke.SendMessage(hWnd, 0x120b, (IntPtr)i, ptr);
                        hditem = (HDITEM)Marshal.PtrToStructure(ptr, typeof(HDITEM));
                        lstColumnFMT.Add(hditem.fmt);
                    }
                    Marshal.FreeHGlobal(ptr);
                    fListViewHasFocus = ListViewController.Handle == PInvoke.GetFocus();
                    msg.Result        = (IntPtr)0x20;
                    return(true);
                }
                }
            }
            return(false);
        }
コード例 #12
0
ファイル: MetroTile.cs プロジェクト: matBatista/uninfe
        protected virtual void OnPaintForeground(PaintEventArgs e)
        {
            Color foreColor;

            if (isHovered && !isPressed && Enabled)
            {
                foreColor = MetroPaint.ForeColor.Tile.Hover(Theme);
            }
            else if (isHovered && isPressed && Enabled)
            {
                foreColor = MetroPaint.ForeColor.Tile.Press(Theme);
            }
            else if (!Enabled)
            {
                foreColor = MetroPaint.ForeColor.Tile.Disabled(Theme);
            }
            else
            {
                foreColor = MetroPaint.ForeColor.Tile.Normal(Theme);
            }

            if (useCustomForeColor)
            {
                foreColor = ForeColor;
            }

            if (isPressed)
            {
            }

            e.Graphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            e.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;

            if (useTileImage)
            {
                if (tileImage != null)
                {
                    Rectangle imageRectangle;
                    switch (tileImageAlign)
                    {
                    case ContentAlignment.BottomLeft:
                        imageRectangle = new Rectangle(new Point(5, Height - TileImage.Height), new System.Drawing.Size(TileImage.Width, TileImage.Height));
                        break;

                    case ContentAlignment.BottomCenter:
                        imageRectangle = new Rectangle(new Point(Width / 2 - TileImage.Width / 2, Height - TileImage.Height), new System.Drawing.Size(TileImage.Width, TileImage.Height));
                        break;

                    case ContentAlignment.BottomRight:
                        imageRectangle = new Rectangle(new Point(Width - TileImage.Width, Height - TileImage.Height), new System.Drawing.Size(TileImage.Width, TileImage.Height));
                        break;

                    case ContentAlignment.MiddleLeft:
                        imageRectangle = new Rectangle(new Point(5, Height / 2 - TileImage.Height / 2), new System.Drawing.Size(TileImage.Width, TileImage.Height));
                        break;

                    case ContentAlignment.MiddleCenter:
                        imageRectangle = new Rectangle(new Point(Width / 2 - TileImage.Width / 2, Height / 2 - TileImage.Height / 2), new System.Drawing.Size(TileImage.Width, TileImage.Height));
                        break;

                    case ContentAlignment.MiddleRight:
                        imageRectangle = new Rectangle(new Point(Width - TileImage.Width, Height / 2 - TileImage.Height / 2), new System.Drawing.Size(TileImage.Width, TileImage.Height));
                        break;

                    case ContentAlignment.TopLeft:
                        imageRectangle = new Rectangle(new Point(5, 5), new System.Drawing.Size(TileImage.Width, TileImage.Height));
                        break;

                    case ContentAlignment.TopCenter:
                        imageRectangle = new Rectangle(new Point(Width / 2 - TileImage.Width / 2, 0), new System.Drawing.Size(TileImage.Width, TileImage.Height));
                        break;

                    case ContentAlignment.TopRight:
                        imageRectangle = new Rectangle(new Point(Width - TileImage.Width, 0), new System.Drawing.Size(TileImage.Width, TileImage.Height));
                        break;

                    default:
                        imageRectangle = new Rectangle(new Point(5, 5), new System.Drawing.Size(TileImage.Width, TileImage.Height));
                        break;
                    }

                    e.Graphics.DrawImage(TileImage, imageRectangle);
                }
            }

            if (TileCount > 0 && paintTileCount)
            {
                Size countSize = TextRenderer.MeasureText(TileCount.ToString(), MetroFonts.TileCount);

                e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                TextRenderer.DrawText(e.Graphics, TileCount.ToString(), MetroFonts.TileCount, new Point(Width - countSize.Width, 0), foreColor);
                e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
            }

            Size textSize = TextRenderer.MeasureText(Text, MetroFonts.Tile(tileTextFontSize, tileTextFontWeight));

            TextFormatFlags flags         = MetroPaint.GetTextFormatFlags(TextAlign) | TextFormatFlags.LeftAndRightPadding | TextFormatFlags.EndEllipsis;
            Rectangle       textRectangle = ClientRectangle;

            if (isPressed)
            {
                textRectangle.Inflate(-2, -2);
            }

            TextRenderer.DrawText(e.Graphics, Text, MetroFonts.Tile(tileTextFontSize, tileTextFontWeight), textRectangle, foreColor, flags);

            if (false && isFocused)
            {
                ControlPaint.DrawFocusRectangle(e.Graphics, ClientRectangle);
            }
        }
コード例 #13
0
        /// <summary>
        /// Primary function for painting the button. This method should be overridden instead of OnPaint.
        /// </summary>
        /// <param name="graphics">The graphics.</param>
        /// <param name="bounds">The bounds.</param>
        protected virtual void PaintButton(Graphics graphics, Rectangle bounds)
        {
            System.Diagnostics.Debug.WriteLine($"PaintButton: desMode:{this.IsDesignMode()};vsEnabled:{Application.RenderWithVisualStyles};vsOnOS:{VisualStyleInformation.IsSupportedByOS};btnState:{ButtonState};enabled:{Enabled};imgCt:{(ImageList != null ? ImageList.Images.Count : 0)}");

            if (InitializeRenderer())
            {
                if (OnGlass)
                {
                    rnd.DrawGlassBackground(graphics, bounds, bounds);
                }
                else
                {
                    rnd.DrawParentBackground(graphics, bounds, this);
                    rnd.DrawBackground(graphics, bounds);
                }
            }
            else
            {
                if (ImageList != null && ImageList.Images.Count > 0)
                {
                    int idx = (int)ButtonState - 1;
                    if (ImageList.Images.Count == 1)
                    {
                        idx = 0;
                    }
                    else if (ImageList.Images.Count == 2)
                    {
                        idx = ButtonState == PushButtonState.Disabled ? 1 : 0;
                    }
                    else if (ImageList.Images.Count == 3)
                    {
                        idx = ButtonState == PushButtonState.Normal ? 0 : idx - 1;
                    }
                    bool forceDisabled = !Enabled && ImageList.Images.Count == 1;
                    if (OnGlass)
                    {
                        VisualStyleRendererExtension.DrawGlassImage(null, graphics, bounds, ImageList.Images[idx], forceDisabled);
                    }
                    else
                    {
                        if (!Application.RenderWithVisualStyles && VisualStyleInformation.IsSupportedByOS)
                        {
                            System.Drawing.Drawing2D.GraphicsContainer g = graphics.BeginContainer();
                            Rectangle translateRect = bounds;
                            graphics.TranslateTransform(-bounds.Left, -bounds.Top);
                            PaintEventArgs pe = new PaintEventArgs(graphics, translateRect);
                            InvokePaintBackground(Parent, pe);
                            InvokePaint(Parent, pe);
                            graphics.ResetTransform();
                            graphics.EndContainer(g);
                        }
                        else
                        {
                            graphics.Clear(Parent.BackColor);
                        }
                        if (forceDisabled)
                        {
                            ControlPaint.DrawImageDisabled(graphics, ImageList.Images[idx], 0, 0, Color.Transparent);
                        }
                        else
                        {
                            //base.ImageList.Draw(graphics, bounds.X, bounds.Y, bounds.Width, bounds.Height, idx);
                            //VisualStyleRendererExtender.DrawGlassImage(null, graphics, bounds, base.ImageList.Images[idx], forceDisabled); // Not 7
                            graphics.DrawImage(ImageList.Images[idx], bounds, bounds, GraphicsUnit.Pixel);                             // Works on XP, not 7, with Parent.BackColor
                        }
                    }
                }

                /*else if (this.ImageList != null && this.ImageList.Images.Count > 1)
                 * {
                 *      int idx = (int)ButtonState - 1;
                 *      if (this.ImageList.Images.Count == 2)
                 *              idx = ButtonState == PushButtonState.Disabled ? 1 : 0;
                 *      if (this.ImageList.Images.Count == 3)
                 *              idx = ButtonState == PushButtonState.Normal ? 0 : idx - 1;
                 *      if (rnd != null && !this.IsDesignMode() && DesktopWindowManager.IsCompositionEnabled())
                 *              rnd.DrawGlassIcon(graphics, bounds, this.ImageList, idx);
                 *      else
                 *              this.ImageList.Draw(graphics, bounds.X, bounds.Y, bounds.Width, bounds.Height, idx);
                 * }*/
                // No image so draw standard button
                else
                {
                    ButtonRenderer.DrawParentBackground(graphics, bounds, this);
                    ButtonRenderer.DrawButton(graphics, bounds, ButtonState);
                }
            }

            if (Focused)
            {
                ControlPaint.DrawFocusRectangle(graphics, bounds);
            }
        }
コード例 #14
0
        public static void DrawButton(Graphics g, Rectangle rect, string text, Font font,
                                      Color foreColor, Color backColor,
                                      ImageList imageList, int imageIndex, Image image, RightToLeft rightToLeft, bool wordWrap,
                                      bool isEnabled, bool isMouseOver, bool isPressed,
                                      bool isDefault, bool isFocused, ContentAlignment imageAlign, ContentAlignment textAlign)
        {
            Rectangle btRect = new Rectangle(rect.X, rect.Y, rect.Width - 1, rect.Height - 1);

            Color controlStart = StiColorUtils.Light(backColor, 30);
            Color controlEnd   = StiColorUtils.Dark(backColor, 10);

            Color controlStartLight = StiColorUtils.Light(controlStart, 20);
            Color controlEndLight   = StiColorUtils.Light(controlEnd, 20);

            Color controlStartDark = StiColorUtils.Dark(controlStart, 20);
            Color controlEndDark   = StiColorUtils.Dark(controlEnd, 20);

            Color clBorderStart = StiColorUtils.Dark(controlStart, 20);
            Color clBorderEnd   = StiColorUtils.Dark(controlEnd, 20);

            Color clStart = controlStart;
            Color clEnd   = controlEnd;

            if (isMouseOver)
            {
                clStart = controlStartLight;
                clEnd   = controlEndLight;
            }

            if (isPressed)
            {
                clStart = controlStartDark;
                clEnd   = controlEndDark;
            }

            var grRect2 = new Rectangle(btRect.X + 1, btRect.Y + 1, btRect.Width - 1, btRect.Height - 1);

            using (var brush = new LinearGradientBrush(grRect2, clBorderStart, clBorderEnd, 90f))
            {
                g.FillRectangle(brush, grRect2);
            }

            var grRect = new Rectangle(btRect.X + 1, btRect.Y + 1, btRect.Width - 2, btRect.Height - 2);

            using (var brush = new LinearGradientBrush(grRect, clStart, clEnd, 90f))
            {
                g.FillRectangle(brush, grRect);
            }


            var oldSmoothingMode = g.SmoothingMode;

            g.SmoothingMode = SmoothingMode.AntiAlias;

            #region Paint border
            using (var pen = new Pen(StiColorUtils.Dark(SystemColors.ControlDark, 30)))
            {
                DrawRoundedRectangle(g, pen, btRect, new Size(4, 4));
                if (isDefault)
                {
                    g.DrawRectangle(pen, new Rectangle(btRect.X + 1, btRect.Y + 1, btRect.Width - 2, btRect.Height - 2));
                }
            }
            #endregion

            g.SmoothingMode = oldSmoothingMode;

            if (isFocused)
            {
                var focusRect = new Rectangle(rect.X + 4, rect.Y + 4, rect.Width - 7, rect.Height - 7);
                ControlPaint.DrawFocusRectangle(g, focusRect, SystemColors.ControlDark, SystemColors.Control);
            }

            Rectangle imageRect;
            Rectangle textRect;

            CalcRectangles(out textRect, out imageRect,
                           new Rectangle(rect.X + 4, rect.Y + 4, rect.Width - 8, rect.Height - 8),
                           g, isEnabled, imageList, imageIndex, image, text,
                           wordWrap, rightToLeft, foreColor, backColor,
                           font, imageAlign, textAlign, isPressed);

            try
            {
                DrawImage(g, isEnabled, imageRect, imageList, imageIndex, image);
            }
            catch
            {
            }

            DrawText(g, text, wordWrap, rightToLeft, isEnabled, foreColor, textRect, font,
                     textAlign, imageAlign);
        }
コード例 #15
0
        private void treeListBox_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
        {
            /* 0 stands for SB_HORZ */
            int leftEdge = GetScrollPos(treeListBox.Handle, 0);

            if (leftEdge != this.leftEdge)
            {
                this.leftEdge = leftEdge;
                RedoColumnLayout();
            }

            int position = 0;

            Graphics g        = e.Graphics;
            ListBox  treeView = treeListBox;

            if (e.Index < 0 || e.Index >= treeView.Items.Count)
            {
                return;
            }

            StringFormat sf = new StringFormat(StringFormatFlags.NoWrap);

            sf.Trimming = StringTrimming.EllipsisCharacter;

            TreeNodeBase node = (TreeNodeBase)Items[e.Index];

            int crossover = (treeListBox.ItemHeight - 1) * (1 + node.depth);

            g.FillRectangle(new SolidBrush(Color.White), position, e.Bounds.Top, crossover, e.Bounds.Height);

            Rectangle itemRect = new Rectangle(crossover, e.Bounds.Top, e.Bounds.Right - crossover, e.Bounds.Height);

            g.FillRectangle(new SolidBrush(e.BackColor), itemRect);

            if (e.State == DrawItemState.Focus)
            {
                ControlPaint.DrawFocusRectangle(g, itemRect, e.ForeColor, e.BackColor);
            }

            Pen grayPen = new Pen(Color.LightGray);

            g.DrawLine(grayPen, 0, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - 1);

            Font fontToUse = treeOwner.GetFont(TokenObject, node);


            Color color = treeOwner.GetColor(TokenObject, node, (e.State & DrawItemState.Selected) != DrawItemState.Selected);

            Brush brush = new SolidBrush(color);

            Region oldClip = g.Clip;

            foreach (DiffColumn c in columns)
            {
                ColumnInformation current = c.ColumnInformation;
                Rectangle         rect    = new Rectangle(position, e.Bounds.Top, c.Width, e.Bounds.Height);
                g.Clip = new Region(rect);

                string res = treeOwner.GetInfo(TokenObject, node, current).ToString();

                if (current.ColumnType == ColumnInformation.ColumnTypes.Tree)
                {
                    rect.Offset((1 + node.depth) * (treeListBox.ItemHeight - 1), 0);
                    rect.Width -= (1 + node.depth) * (treeListBox.ItemHeight - 1);

                    if (node.HasKids)
                    {
                        Pen p  = new Pen(Color.Gray);
                        int y0 = e.Bounds.Top;
                        int x0 = position + node.depth * (treeListBox.ItemHeight - 1);
                        g.DrawRectangle(p, x0 + 3, y0 + 3, (treeListBox.ItemHeight - 9), (treeListBox.ItemHeight - 9));
                        g.DrawLine(p, x0 + 5, y0 + (treeListBox.ItemHeight - 3) / 2, x0 + (treeListBox.ItemHeight - 8), y0 + (treeListBox.ItemHeight - 3) / 2);
                        if (!node.IsExpanded)
                        {
                            g.DrawLine(p, x0 + (treeListBox.ItemHeight - 3) / 2, y0 + 5, x0 + (treeListBox.ItemHeight - 3) / 2, y0 + (treeListBox.ItemHeight - 8));
                        }
                    }
                }

                if (res != null)
                {
                    int characters, lines;

                    SizeF layoutArea = new SizeF(rect.Width, rect.Height);
                    SizeF stringSize = g.MeasureString(res, fontToUse, layoutArea, sf, out characters, out lines);

                    g.DrawString(res.Substring(0, characters) + (characters < res.Length ? "..." : ""), fontToUse, brush, rect.Location, sf);
                    g.DrawLine(grayPen, rect.Right - 1, e.Bounds.Top, rect.Right - 1, e.Bounds.Bottom - 1);
                }

                position += c.Width;
            }
            g.Clip = oldClip;
        }
コード例 #16
0
        protected virtual void OnPaintForeground(PaintEventArgs e)
        {
            Color borderColor, foreColor;

            if (isHovered && !isPressed && Enabled)
            {
                borderColor = MetroPaint.BorderColor.Button.Hover(Theme);
                foreColor   = MetroPaint.ForeColor.Button.Hover(Theme);
            }
            else if (isHovered && isPressed && Enabled)
            {
                borderColor = MetroPaint.BorderColor.Button.Press(Theme);
                foreColor   = MetroPaint.ForeColor.Button.Press(Theme);
            }
            else if (!Enabled)
            {
                borderColor = MetroPaint.BorderColor.Button.Disabled(Theme);
                foreColor   = MetroPaint.ForeColor.Button.Disabled(Theme);
            }
            else
            {
                borderColor = MetroPaint.BorderColor.Button.Normal(Theme);
                if (useCustomForeColor)
                {
                    foreColor = ForeColor;
                }
                else if (useStyleColors)
                {
                    foreColor = MetroPaint.GetStyleColor(Style);
                }
                else
                {
                    foreColor = MetroPaint.ForeColor.Button.Normal(Theme);
                }
            }

            using (Pen p = new Pen(borderColor))
            {
                Rectangle borderRect = new Rectangle(0, 0, Width - 1, Height - 1);
                e.Graphics.DrawRectangle(p, borderRect);
            }

            if (Highlight && !isHovered && !isPressed && Enabled)
            {
                using (Pen p = MetroPaint.GetStylePen(Style))
                {
                    Rectangle borderRect = new Rectangle(0, 0, Width - 1, Height - 1);
                    e.Graphics.DrawRectangle(p, borderRect);
                    borderRect = new Rectangle(1, 1, Width - 3, Height - 3);
                    e.Graphics.DrawRectangle(p, borderRect);
                }
            }

            TextRenderer.DrawText(e.Graphics, Text, MetroFonts.Button(metroButtonSize, metroButtonWeight), ClientRectangle, foreColor, MetroPaint.GetTextFormatFlags(TextAlign));

            OnCustomPaintForeground(new MetroPaintEventArgs(Color.Empty, foreColor, e.Graphics));

            if (displayFocusRectangle && isFocused)
            {
                ControlPaint.DrawFocusRectangle(e.Graphics, ClientRectangle);
            }
        }
コード例 #17
0
        /// <summary>
        /// Raises the Paint event
        /// </summary>
        /// <param name="e">A PaintCellEventArgs that contains the event data</param>
        protected override void OnPaint(PaintCellEventArgs e)
        {
            base.OnPaint(e);

            // don't bother if the Cell is null
            if (e.Cell == null)
            {
                return;
            }

            // get the Cells value
            decimal decimalVal = decimal.MinValue;

            if (e.Cell.Data != null &&
                (e.Cell.Data is uint || e.Cell.Data is UInt16 || e.Cell.Data is UInt32 || e.Cell.Data is UInt64 ||
                 e.Cell.Data is int || e.Cell.Data is Int16 || e.Cell.Data is Int32 || e.Cell.Data is Int64 ||
                 e.Cell.Data is double || e.Cell.Data is float || e.Cell.Data is decimal))
            {
                decimalVal = Convert.ToDecimal(e.Cell.Data);
            }

            // draw the value
            if (decimalVal != decimal.MinValue)
            {
                Rectangle textRect = this.ClientRectangle;

                if (this.ShowUpDownButtons)
                {
                    textRect.Width -= this.CalcButtonBounds().Width - 1;

                    if (this.UpDownAlign == LeftRightAlignment.Left)
                    {
                        textRect.X = this.ClientRectangle.Right - textRect.Width;
                    }
                }

                string text = decimalVal.ToString(this.Format, this.FormatProvider);

                if (e.Cell.WidthNotSet)
                {
                    SizeF size = e.Graphics.MeasureString(text, this.Font);
                    e.Cell.ContentWidth = (int)Math.Ceiling(size.Width);
                }

                if (e.Enabled)
                {
                    e.Graphics.DrawString(text, this.Font, this.ForeBrush, textRect, this.StringFormat);
                }
                else
                {
                    e.Graphics.DrawString(text, this.Font, this.GrayTextBrush, textRect, this.StringFormat);
                }
            }

            if ((e.Focused && e.Enabled)
                // only if we want to show selection rectangle
                && (e.Table.ShowSelectionRectangle))
            {
                Rectangle focusRect = this.ClientRectangle;

                if (this.ShowUpDownButtons)
                {
                    focusRect.Width -= this.CalcButtonBounds().Width;

                    if (this.UpDownAlign == LeftRightAlignment.Left)
                    {
                        focusRect.X = this.ClientRectangle.Right - focusRect.Width;
                    }
                }

                ControlPaint.DrawFocusRectangle(e.Graphics, focusRect);
            }
        }
コード例 #18
0
        private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
        {
            if (e.Bounds.IsEmpty)
            {
                return;
            }

            using (SolidBrush brush = new SolidBrush(Color.White))
            {
                e.Graphics.FillRectangle(brush, e.Bounds);
            }

            Point     ckboxPoint = new Point(e.Node.Bounds.X - 16, e.Node.Bounds.Y + ((e.Node.Bounds.Height - 13) / 2));
            Rectangle expandRct  = new Rectangle(ckboxPoint.X - 13, e.Bounds.Y + ((e.Bounds.Height - 9) / 2), 9, 9);

            CheckBoxState ckboxState = CheckBoxState.UncheckedNormal;

            if (e.Node.Nodes.Count > 0)
            {
                if (e.Node.Tag != null)
                {
                    ckboxState = CheckBoxState.MixedNormal;
                }
                else
                {
                    int nodosMarcados = e.Node.Nodes.OfType <TreeNode>().Where(node => node.Checked).Count();
                    if (nodosMarcados == e.Node.Nodes.Count)
                    {
                        ckboxState = CheckBoxState.CheckedNormal;
                    }
                }
            }
            else
            {
                if (e.Node.Checked)
                {
                    ckboxState = CheckBoxState.CheckedNormal;
                }
            }

            if (e.Node.Nodes.Count > 0)
            {
                // dibuja glyph para expandir/colapsar
                if (e.Node.IsExpanded)
                {
                    e.Graphics.DrawImage(Properties.Resources.collapseBtn, expandRct);
                }
                else
                {
                    e.Graphics.DrawImage(Properties.Resources.expandBtn, expandRct);
                }
            }

            // dibuja glyph checkbox
            CheckBoxRenderer.DrawCheckBox(e.Graphics, ckboxPoint, ckboxState);

            if (e.Node.IsSelected)
            {
                e.Graphics.FillRectangle(Brushes.White, e.Node.Bounds);
            }

            // dibuja texto
            Rectangle rctText = new Rectangle
                                (
                e.Node.Bounds.X,
                e.Node.Bounds.Y,
                e.Bounds.Width - e.Node.Bounds.X,
                e.Node.Bounds.Height
                                );

            using (SolidBrush brush = new SolidBrush((e.State & TreeNodeStates.Selected) > 0 ? Color.Black : Color.Black))
            {
                e.Graphics.DrawString(e.Node.Text, this.treeViewResultados.Font, brush, rctText, new StringFormat {
                    LineAlignment = StringAlignment.Center
                });
            }

            if ((e.State & TreeNodeStates.Focused) > 0)
            {
                ControlPaint.DrawFocusRectangle(e.Graphics, e.Node.Bounds);
            }
        }
コード例 #19
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);

            if (!showSplit)
            {
                return;
            }

            Graphics  g      = pevent.Graphics;
            Rectangle bounds = ClientRectangle;

            // draw the button background as according to the current state.
            if (State != PushButtonState.Pressed && IsDefault && !Application.RenderWithVisualStyles)
            {
                Rectangle backgroundBounds = bounds;
                backgroundBounds.Inflate(-1, -1);
                ButtonRenderer.DrawButton(g, backgroundBounds, State);

                // button renderer doesnt draw the black frame when themes are off
                g.DrawRectangle(SystemPens.WindowFrame, 0, 0, bounds.Width - 1, bounds.Height - 1);
            }
            else
            {
                ButtonRenderer.DrawButton(g, bounds, State);
            }

            PaintThemedButtonBackground(pevent, bounds);

            // calculate the current dropdown rectangle.
            dropDownRectangle = new Rectangle(bounds.Right - SplitSectionWidth, 0, SplitSectionWidth, bounds.Height);

            int       internalBorder = BorderSize;
            Rectangle focusRect      = new Rectangle(
                internalBorder - 1,
                internalBorder - 1,
                bounds.Width - dropDownRectangle.Width - internalBorder,
                bounds.Height - (internalBorder * 2) + 2);

            bool drawSplitLine = (State == PushButtonState.Hot || State == PushButtonState.Pressed || !Application.RenderWithVisualStyles);

            if (RightToLeft == RightToLeft.Yes)
            {
                dropDownRectangle.X = bounds.Left + 1;
                focusRect.X         = dropDownRectangle.Right;

                if (drawSplitLine)
                {
                    // draw two lines at the edge of the dropdown button
                    g.DrawLine(SystemPens.ButtonShadow, bounds.Left + SplitSectionWidth, BorderSize, bounds.Left + SplitSectionWidth, bounds.Bottom - BorderSize);
                    g.DrawLine(SystemPens.ButtonFace, bounds.Left + SplitSectionWidth + 1, BorderSize, bounds.Left + SplitSectionWidth + 1, bounds.Bottom - BorderSize);
                }
            }
            else
            {
                if (drawSplitLine)
                {
                    // draw two lines at the edge of the dropdown button
                    g.DrawLine(SystemPens.ButtonShadow, bounds.Right - SplitSectionWidth, BorderSize, bounds.Right - SplitSectionWidth, bounds.Bottom - BorderSize);
                    g.DrawLine(SystemPens.ButtonFace, bounds.Right - SplitSectionWidth - 1, BorderSize, bounds.Right - SplitSectionWidth - 1, bounds.Bottom - BorderSize);
                }
            }

            // Draw an arrow in the correct location
            PaintArrow(g, dropDownRectangle);

            //paint the image and text in the "button" part of the splitButton
            PaintTextandImage(g, new Rectangle(0, 0, ClientRectangle.Width - SplitSectionWidth, ClientRectangle.Height));

            // draw the focus rectangle.
            if (State != PushButtonState.Pressed && Focused && ShowFocusCues)
            {
                ControlPaint.DrawFocusRectangle(g, focusRect);
            }
        }
コード例 #20
0
        private void LB_DrawItem(object sender,
                                 DrawItemEventArgs e)
        {
            bool selected = (e.State & DrawItemState.Selected) ==
                            DrawItemState.Selected;

            if (e.Index == -1)
            {
                return;
            }

            const int Offset = 24;

            var    li = (ListItem)LB.Items[e.Index];
            string text = li.Text;
            Brush  bg, fg;

            if (selected)
            {
                bg = SystemBrushes.Highlight;
                fg = SystemBrushes.HighlightText;
                //fg=Brushes.Black;
            }
            else
            {
                bg = SystemBrushes.Window;
                fg = SystemBrushes.WindowText;
                //bg=Brushes.White;
                //fg=Brushes.Black;
            }

            if (!selected)
            {
                e.Graphics.FillRectangle(bg, 0, e.Bounds.Top, e.Bounds.Width,
                                         LB.ItemHeight);
                //e.Graphics.FillRectangle (SystemBrushes.Highlight,0,e.Bounds.Top,27 ,LB.ItemHeight);
            }
            else
            {
                e.Graphics.FillRectangle(SystemBrushes.Window, Offset, e.Bounds.Top,
                                         e.Bounds.Width - Offset, LB.ItemHeight);
                e.Graphics.FillRectangle(SystemBrushes.Highlight, new Rectangle(Offset
                                                                                + 1, e.Bounds.Top + 1,
                                                                                e.Bounds.Width - Offset
                                                                                - 2, LB.ItemHeight - 2));


                //e.Graphics.FillRectangle (SystemBrushes.Highlight,27,e.Bounds.Top,e.Bounds.Width-27 ,LB.ItemHeight);
                //e.Graphics.FillRectangle (new SolidBrush(Color.FromArgb (182,189,210)),new Rectangle (1+27,e.Bounds.Top+1,e.Bounds.Width-2- ,LB.ItemHeight-2));


                ControlPaint.DrawFocusRectangle(e.Graphics, new Rectangle(Offset,
                                                                          e.Bounds.Top, e.Bounds.Width - Offset,
                                                                          LB.ItemHeight));
            }


            e.Graphics.DrawString(text, e.Font, fg, Offset + 2, e.Bounds.Top + 1);


            if (Images != null)
            {
                e.Graphics.DrawImage(Images.Images[li.Type], 6, e.Bounds.Top + 0);
            }
        }
コード例 #21
0
 public static void DrawFocusRectangle(Graphics graphics, Rectangle rectangle, int offset = 2)
 {
     ControlPaint.DrawFocusRectangle(graphics, new Rectangle(
                                         rectangle.X + offset, rectangle.Y + offset,
                                         rectangle.Width - 2 * offset, rectangle.Height - 2 * offset));
 }
コード例 #22
0
ファイル: MemoryControl.cs プロジェクト: mmyydd/reko
            /// <summary>
            /// Paints a line of the memory control, starting with the address.
            /// </summary>
            /// <remarks>
            /// The strategy is to find any items present at the current address, and try
            /// to paint as many adjacent items as possible.
            /// </remarks>
            /// <param name="g"></param>
            /// <param name="rc"></param>
            /// <param name="rdr"></param>
            private Address PaintLine(Graphics g, Rectangle rc, ImageReader rdr, Point ptAddr, bool render)
            {
                StringBuilder sbCode = new StringBuilder(" ");

                // Draw the address part.

                rc.X = 0;
                string s  = string.Format("{0}", rdr.Address);
                int    cx = (int)g.MeasureString(s + "X", ctrl.Font, rc.Width, StringFormat.GenericTypographic).Width;

                if (!render && new Rectangle(rc.X, rc.Y, cx, rc.Height).Contains(ctrl.ptDown))
                {
                    return(rdr.Address);
                }
                else
                {
                    g.FillRectangle(SystemBrushes.Window, rc.X, rc.Y, cx, rc.Height);
                    g.DrawString(s, ctrl.Font, SystemBrushes.ControlText, rc.X, rc.Y, StringFormat.GenericTypographic);
                }
                cx -= cellSize.Width / 2;
                rc  = new Rectangle(cx, rc.Top, rc.Width - cx, rc.Height);

                uint  rowBytesLeft   = ctrl.cbRow;
                ulong linearSelected = ctrl.addrSelected != null?ctrl.addrSelected.ToLinear() : ~0UL;

                ulong linearAnchor = ctrl.addrAnchor != null?ctrl.addrAnchor.ToLinear() : ~0UL;

                ulong linearBeginSelection = Math.Min(linearSelected, linearAnchor);
                ulong linearEndSelection   = Math.Max(linearSelected, linearAnchor);

                do
                {
                    Address addr   = rdr.Address;
                    ulong   linear = addr.ToLinear();

                    ImageMapItem item;
                    if (!ctrl.ImageMap.TryFindItem(addr, out item))
                    {
                        break;
                    }
                    ulong cbIn     = (linear - item.Address.ToLinear()); // # of bytes 'inside' the block we are.
                    uint  cbToDraw = 16;                                 // item.Size - cbIn;

                    // See if the chunk goes off the edge of the line. If so, clip it.
                    if (cbToDraw > rowBytesLeft)
                    {
                        cbToDraw = rowBytesLeft;
                    }

                    // Now paint the bytes in this span.

                    for (int i = 0; i < cbToDraw; ++i)
                    {
                        Address addrByte = rdr.Address;
                        ctrl.ImageMap.TryFindItem(addrByte, out item);
                        bool isSelected = linearBeginSelection <= addrByte.ToLinear() && addrByte.ToLinear() <= linearEndSelection;
                        bool isCursor   = addrByte.ToLinear() == linearSelected;
                        if (rdr.IsValid)
                        {
                            byte b = rdr.ReadByte();
                            s = string.Format("{0:X2}", b);
                            char ch = (char)b;
                            sbCode.Append(Char.IsControl(ch) ? '.' : ch);
                        }
                        else
                        {
                            s = "??";
                            sbCode.Append(' ');
                        }

                        cx = cellSize.Width * 3;
                        Rectangle rcByte = new Rectangle(
                            rc.Left,
                            rc.Top,
                            cx,
                            rc.Height);

                        if (!render && rcByte.Contains(ptAddr))
                        {
                            return(addrByte);
                        }

                        var theme = GetBrushTheme(item, isSelected);
                        g.FillRectangle(theme.Background, rc.Left, rc.Top, cx, rc.Height);
                        if (!isSelected && theme.StartMarker != null && addrByte.ToLinear() == item.Address.ToLinear())
                        {
                            var pts = new Point[]
                            {
                                rc.Location,
                                rc.Location,
                                rc.Location,
                            };
                            pts[1].Offset(4, 0);
                            pts[2].Offset(0, 4);
                            g.FillClosedCurve(theme.StartMarker, pts);
                        }
                        g.DrawString(s, ctrl.Font, theme.Foreground, rc.Left + cellSize.Width / 2, rc.Top, StringFormat.GenericTypographic);
                        if (isCursor)
                        {
                            ControlPaint.DrawFocusRectangle(g, rc);
                        }
                        rc = new Rectangle(rc.X + cx, rc.Y, rc.Width - cx, rc.Height);
                    }
                    rowBytesLeft -= cbToDraw;
                } while (rowBytesLeft > 0);

                if (render)
                {
                    g.FillRectangle(SystemBrushes.Window, rc);
                    g.DrawString(sbCode.ToString(), ctrl.Font, SystemBrushes.WindowText, rc.X + cellSize.Width, rc.Top, StringFormat.GenericTypographic);
                }
                return(null);
            }
コード例 #23
0
        private Size MeasureAndDraw(Graphics g, bool enableDrawing, PushButtonState state, bool drawFocusCues, bool drawKeyboardCues)
        {
            if (enableDrawing)
            {
                g.PixelOffsetMode   = PixelOffsetMode.Half;
                g.CompositingMode   = CompositingMode.SourceOver;
                g.InterpolationMode = InterpolationMode.Bilinear;
            }

            int marginX       = UI.ScaleWidth(9);
            int marginYTop    = UI.ScaleHeight(8);
            int marginYBottom = UI.ScaleHeight(9);
            int paddingX      = UI.ScaleWidth(8);
            int paddingY      = UI.ScaleHeight(3);
            int offsetX       = 0;
            int offsetY       = 0;

            bool drawAsDefault = (state == PushButtonState.Default);

            if (enableDrawing)
            {
                using (Brush backBrush = new SolidBrush(this.BackColor))
                {
                    CompositingMode oldCM = g.CompositingMode;
                    g.CompositingMode = CompositingMode.SourceCopy;
                    g.FillRectangle(backBrush, ClientRectangle);
                    g.CompositingMode = oldCM;
                }

                Rectangle ourRect = new Rectangle(0, 0, ClientSize.Width, ClientSize.Height);

                if (state == PushButtonState.Pressed)
                {
                    offsetX = 1;
                    offsetY = 1;
                }

                UI.DrawCommandButton(g, state, ourRect, BackColor, this);
            }

            Rectangle actionImageRect;

            Brush textBrush = new SolidBrush(SystemColors.WindowText);

            if (this.actionImage == null)
            {
                actionImageRect = new Rectangle(offsetX, offsetY + marginYTop, 0, 0);
            }
            else
            {
                actionImageRect = new Rectangle(offsetX + marginX, offsetY + marginYTop,
                                                UI.ScaleWidth(this.actionImage.Width), UI.ScaleHeight(this.actionImage.Height));

                Rectangle srcRect = new Rectangle(0, 0, this.actionImage.Width, this.actionImage.Height);

                if (enableDrawing)
                {
                    Image drawMe = Enabled ? this.actionImage : this.actionImageDisabled;

                    if (Enabled)
                    {
                        actionImageRect.Y += 3;
                        actionImageRect.X += 1;
                        g.DrawImage(this.actionImageDisabled, actionImageRect, srcRect, GraphicsUnit.Pixel);
                        actionImageRect.X -= 1;
                        actionImageRect.Y -= 3;
                    }

                    actionImageRect.Y += 2;
                    g.DrawImage(drawMe, actionImageRect, srcRect, GraphicsUnit.Pixel);
                    actionImageRect.Y -= 2;
                }
            }

            int actionTextX     = actionImageRect.Right + paddingX;
            int actionTextY     = actionImageRect.Top;
            int actionTextWidth = ClientSize.Width - actionTextX - marginX + offsetX;

            StringFormat stringFormat = (StringFormat)StringFormat.GenericTypographic.Clone();

            stringFormat.HotkeyPrefix = drawKeyboardCues ? HotkeyPrefix.Show : HotkeyPrefix.Hide;

            SizeF actionTextSize = g.MeasureString(this.actionText, this.actionTextFont, actionTextWidth, stringFormat);

            Rectangle actionTextRect = new Rectangle(actionTextX, actionTextY,
                                                     actionTextWidth, (int)Math.Ceiling(actionTextSize.Height));

            if (enableDrawing)
            {
                if (state == PushButtonState.Disabled)
                {
                    ControlPaint.DrawStringDisabled(g, this.actionText, this.actionTextFont, this.BackColor, actionTextRect, stringFormat);
                }
                else
                {
                    g.DrawString(this.actionText, this.actionTextFont, textBrush, actionTextRect, stringFormat);
                }
            }

            int descriptionTextX     = actionTextX;
            int descriptionTextY     = actionTextRect.Bottom + paddingY;
            int descriptionTextWidth = actionTextWidth;

            SizeF descriptionTextSize = g.MeasureString(this.explanationText, this.explanationTextFont,
                                                        descriptionTextWidth, stringFormat);

            Rectangle descriptionTextRect = new Rectangle(descriptionTextX, descriptionTextY,
                                                          descriptionTextWidth, (int)Math.Ceiling(descriptionTextSize.Height));

            if (enableDrawing)
            {
                if (state == PushButtonState.Disabled)
                {
                    ControlPaint.DrawStringDisabled(g, this.explanationText, this.explanationTextFont, this.BackColor, descriptionTextRect, stringFormat);
                }
                else
                {
                    g.DrawString(this.explanationText, this.explanationTextFont, textBrush, descriptionTextRect, stringFormat);
                }
            }

            if (enableDrawing)
            {
                if (drawFocusCues)
                {
                    ControlPaint.DrawFocusRectangle(g, new Rectangle(3, 3, ClientSize.Width - 5, ClientSize.Height - 5));
                }
            }

            if (textBrush != null)
            {
                textBrush.Dispose();
            }

            stringFormat.Dispose();
            Size layoutSize = new Size(ClientSize.Width, descriptionTextRect.Bottom + marginYBottom);

            return(layoutSize);
        }
コード例 #24
0
        /// <summary>
        /// Draws certain tab.
        /// </summary>
        /// <param name="g">The <see cref="T:System.Drawing.Graphics"/> object used to draw tab control.</param>
        /// <param name="index">Index of the tab being drawn.</param>
        /// <param name="state">State of the tab item.</param>
        /// <param name="tabRect">The <see cref="T:System.Drawing.Rectangle"/> object specifying tab bounds.</param>
        /// <param name="textFmt">The <see cref="T:System.Drawing.StringFormat"/> object specifying text formatting
        /// in the tab.</param>
        private void DrawTabItem(Graphics g, int index, TabItemState state, Rectangle tabRect, StringFormat textFmt)
        {
            //if scroller is visible and the tab is fully placed under it we don't need to draw such tab
            if (fUpDown.X <= 0 || tabRect.X < fUpDown.X)
            {
                /* We will draw our tab on the bitmap and then will transfer image on the control
                 * graphic context.*/

                using (Bitmap bmp = new Bitmap(tabRect.Width, tabRect.Height))
                {
                    Rectangle drawRect = new Rectangle(0, 0, tabRect.Width, tabRect.Height);
                    using (Graphics bitmapContext = Graphics.FromImage(bmp))
                    {
                        TabRenderer.DrawTabItem(bitmapContext, drawRect, state);
                        if (state == TabItemState.Selected && tabRect.X == 0)
                        {
                            int corrY = bmp.Height - 1;
                            bmp.SetPixel(0, corrY, bmp.GetPixel(0, corrY - 1));
                        }

                        /* Important moment. If tab alignment is bottom we should flip image to display tab
                         * correctly.*/

                        if (this.Alignment == TabAlignment.Bottom)
                        {
                            bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
                        }

                        Rectangle focusRect = Rectangle.Inflate(drawRect, -3, -3);
                        //focus rect
                        TabPage pg = this.TabPages[index];
                        //tab page whose tab we're drawing
                        //trying to get tab image if any
                        Image pagePict = GetImageByIndexOrKey(pg.ImageIndex, pg.ImageKey);
                        if (pagePict != null)
                        {
                            //If tab image is present we should draw it.
                            Point imgLoc = state == TabItemState.Selected ? new Point(8, 2) : new Point(6, 2);
                            if (this.Alignment == TabAlignment.Bottom)
                            {
                                imgLoc.Y = drawRect.Bottom - 2 - pagePict.Height;
                            }
                            bitmapContext.DrawImageUnscaled(pagePict, imgLoc);
                            //Correcting rectangle for drawing text.
                            drawRect.X     += imgLoc.X + pagePict.Width;
                            drawRect.Width -= imgLoc.X + pagePict.Width;
                        }
                        //drawing tab text
                        using (Brush b = new SolidBrush(SystemColors.ControlText))
                            bitmapContext.DrawString(pg.Text, this.Font, b, (RectangleF)drawRect, textFmt);
                        //and finally drawing focus rect(if needed)
                        if (this.Focused && state == TabItemState.Selected)
                        {
                            ControlPaint.DrawFocusRectangle(bitmapContext, focusRect);
                        }
                    }
                    //If the tab has part under scroller we shouldn't draw that part.
                    int shift = state == TabItemState.Selected ? 2 : 0;
                    if (fUpDown.X > 0 && fUpDown.X >= tabRect.X - shift && fUpDown.X < tabRect.Right + shift)
                    {
                        tabRect.Width -= tabRect.Right - fUpDown.X + shift;
                    }
                    g.DrawImageUnscaledAndClipped(bmp, tabRect);
                }
            }
        }
コード例 #25
0
ファイル: WizardPage.cs プロジェクト: KarlRichard/nHydrate
        /// <summary>
        /// Provides custom drawing to the wizard page.
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            // raise paint event
            base.OnPaint(e);

            // check if custom style
            if (this.style == WizardPageStyle.Custom)
            {
                // filter out
                return;
            }

            // init graphic resources
            var headerRect      = this.ClientRectangle;
            var glyphRect       = Rectangle.Empty;
            var titleRect       = Rectangle.Empty;
            var descriptionRect = Rectangle.Empty;

            // determine text format
            var textFormat = StringFormat.GenericDefault;

            textFormat.LineAlignment = StringAlignment.Near;
            textFormat.Alignment     = StringAlignment.Near;
            textFormat.Trimming      = StringTrimming.EllipsisCharacter;

            switch (this.style)
            {
            case WizardPageStyle.Standard:
                // adjust height for header
                headerRect.Height = this.HeaderHeight;
                // draw header border
                ControlPaint.DrawBorder3D(e.Graphics, headerRect, Border3DStyle.Etched, Border3DSide.Bottom);
                // adjust header rect not to overwrite the border
                headerRect.Height -= SystemInformation.Border3DSize.Height;
                // fill header with window color
                e.Graphics.FillRectangle(SystemBrushes.Window, headerRect);

                // determine header image regtangle
                var headerPadding = (int)Math.Floor((double)(this.HeaderHeight - this.HeaderGlyphSize) / 2);
                glyphRect.Location = new Point(this.Width - this.HeaderGlyphSize - headerPadding, headerPadding);
                glyphRect.Size     = new Size(this.HeaderGlyphSize, this.HeaderGlyphSize);

                // determine the header content
                Image headerImage     = null;
                var   headerFont      = this.Font;
                var   headerTitleFont = this.Font;
                if (this.Parent != null && this.Parent is Wizard)
                {
                    // get content from parent wizard, if exists
                    var parentWizard = (Wizard)this.Parent;
                    headerImage     = parentWizard.HeaderImage;
                    headerFont      = parentWizard.HeaderFont;
                    headerTitleFont = parentWizard.HeaderTitleFont;
                }

                // check if we have an image
                if (headerImage == null)
                {
                    // display a focus rect as a place holder
                    ControlPaint.DrawFocusRectangle(e.Graphics, glyphRect);
                }
                else
                {
                    // draw header image
                    e.Graphics.DrawImage(headerImage, glyphRect);
                }

                // determine title height
                var headerTitleHeight = (int)Math.Ceiling(e.Graphics.MeasureString(this.title, headerTitleFont, 0, textFormat).Height);

                // calculate text sizes
                titleRect.Location = new Point(HEADER_TEXT_PADDING,
                                               HEADER_TEXT_PADDING);
                titleRect.Size = new Size(glyphRect.Left - HEADER_TEXT_PADDING,
                                          headerTitleHeight);
                descriptionRect.Location = titleRect.Location;
                descriptionRect.Y       += headerTitleHeight + HEADER_TEXT_PADDING / 2;
                descriptionRect.Size     = new Size(titleRect.Width,
                                                    this.HeaderHeight - descriptionRect.Y);

                // draw tilte text (single line, truncated with ellipsis)
                e.Graphics.DrawString(this.title,
                                      headerTitleFont,
                                      SystemBrushes.WindowText,
                                      titleRect,
                                      textFormat);
                // draw description text (multiple lines if needed)
                e.Graphics.DrawString(this.description,
                                      headerFont,
                                      SystemBrushes.WindowText,
                                      descriptionRect,
                                      textFormat);
                break;

            case WizardPageStyle.Welcome:
            case WizardPageStyle.Finish:
                // fill whole page with window color
                e.Graphics.FillRectangle(SystemBrushes.Window, headerRect);

                // determine welcome image regtangle
                glyphRect.Location = Point.Empty;
                glyphRect.Size     = new Size(WELCOME_GLYPH_WIDTH, this.Height);

                // determine the icon that should appear on the welcome page
                Image welcomeImage     = null;
                var   welcomeFont      = this.Font;
                var   welcomeTitleFont = this.Font;
                if (this.Parent != null && this.Parent is Wizard)
                {
                    // get content from parent wizard, if exists
                    var parentWizard = (Wizard)this.Parent;
                    welcomeImage     = parentWizard.WelcomeImage;
                    welcomeFont      = parentWizard.WelcomeFont;
                    welcomeTitleFont = parentWizard.WelcomeTitleFont;
                }

                // check if we have an image
                if (welcomeImage == null)
                {
                    // display a focus rect as a place holder
                    ControlPaint.DrawFocusRectangle(e.Graphics, glyphRect);
                }
                else
                {
                    // draw welcome page image
                    e.Graphics.DrawImage(welcomeImage, glyphRect);
                }

                // calculate text sizes
                titleRect.Location = new Point(WELCOME_GLYPH_WIDTH + HEADER_TEXT_PADDING,
                                               HEADER_TEXT_PADDING);
                titleRect.Width = this.Width - titleRect.Left - HEADER_TEXT_PADDING;
                // determine title height
                var welcomeTitleHeight = (int)Math.Ceiling(e.Graphics.MeasureString(this.title, welcomeTitleFont, titleRect.Width, textFormat).Height);
                descriptionRect.Location = titleRect.Location;
                descriptionRect.Y       += welcomeTitleHeight + HEADER_TEXT_PADDING;
                descriptionRect.Size     = new Size(this.Width - descriptionRect.Left - HEADER_TEXT_PADDING,
                                                    this.Height - descriptionRect.Y);

                // draw tilte text (multiple lines if needed)
                e.Graphics.DrawString(this.title,
                                      welcomeTitleFont,
                                      SystemBrushes.WindowText,
                                      titleRect,
                                      textFormat);
                // draw description text (multiple lines if needed)
                e.Graphics.DrawString(this.description,
                                      welcomeFont,
                                      SystemBrushes.WindowText,
                                      descriptionRect,
                                      textFormat);
                break;
            }
        }
コード例 #26
0
        protected virtual void OnPaintForeground(PaintEventArgs e)
        {
            Color borderColor, foreColor;

            if (isHovered && !isPressed && Enabled)
            {
                foreColor   = MetroPaint.ForeColor.CheckBox.Hover(Theme);
                borderColor = MetroPaint.BorderColor.CheckBox.Hover(Theme);
            }
            else if (isHovered && isPressed && Enabled)
            {
                foreColor   = MetroPaint.ForeColor.CheckBox.Press(Theme);
                borderColor = MetroPaint.BorderColor.CheckBox.Press(Theme);
            }
            else if (!Enabled)
            {
                foreColor   = MetroPaint.ForeColor.CheckBox.Disabled(Theme);
                borderColor = MetroPaint.BorderColor.CheckBox.Disabled(Theme);
            }
            else
            {
                foreColor = !useStyleColors
                                ? MetroPaint.ForeColor.CheckBox.Normal(Theme)
                                : MetroPaint.GetStyleColor(Style);

                borderColor = MetroPaint.BorderColor.CheckBox.Normal(Theme);
            }

            using (var p = new Pen(borderColor))
            {
                var boxRect = new Rectangle((DisplayStatus ? 30 : 0), 0,
                                            ClientRectangle.Width - (DisplayStatus ? 31 : 1), ClientRectangle.Height - 1);
                e.Graphics.DrawRectangle(p, boxRect);
            }

            Color fillColor = Checked ? MetroPaint.GetStyleColor(Style) : MetroPaint.BorderColor.CheckBox.Normal(Theme);

            using (var b = new SolidBrush(fillColor))
            {
                var boxRect = new Rectangle(DisplayStatus ? 32 : 2, 2, ClientRectangle.Width - (DisplayStatus ? 34 : 4),
                                            ClientRectangle.Height - 4);
                e.Graphics.FillRectangle(b, boxRect);
            }

            Color backColor = BackColor;

            if (!useCustomBackColor)
            {
                backColor = MetroPaint.BackColor.Form(Theme);
            }

            using (var b = new SolidBrush(backColor))
            {
                int left = Checked ? Width - 11 : (DisplayStatus ? 30 : 0);

                var boxRect = new Rectangle(left, 0, 11, ClientRectangle.Height);
                e.Graphics.FillRectangle(b, boxRect);
            }
            using (var b = new SolidBrush(MetroPaint.BorderColor.CheckBox.Hover(Theme)))
            {
                int left = Checked ? Width - 10 : (DisplayStatus ? 30 : 0);

                var boxRect = new Rectangle(left, 0, 10, ClientRectangle.Height);
                e.Graphics.FillRectangle(b, boxRect);
            }

            if (DisplayStatus)
            {
                var textRect = new Rectangle(0, 0, 30, ClientRectangle.Height);
                TextRenderer.DrawText(e.Graphics, Text, MetroFonts.Link(metroLinkSize, metroLinkWeight), textRect,
                                      foreColor, MetroPaint.GetTextFormatFlags(TextAlign));
            }

            if (displayFocusRectangle && isFocused)
            {
                ControlPaint.DrawFocusRectangle(e.Graphics, ClientRectangle);
            }
        }
コード例 #27
0
ファイル: PianoBox.cs プロジェクト: lin20121221/MidiSlicer
        /// <summary>
        /// Called when the control is painted
        /// </summary>
        /// <param name="args">The <see cref="PaintEventArgs"/> to use</param>
        protected override void OnPaint(PaintEventArgs args)
        {
            base.OnPaint(args);
            var g    = args.Graphics;
            var rect = new Rectangle(0, 0, Width - 1, Height - 1);

            using (var brush = new SolidBrush(_whiteKeyColor))
                g.FillRectangle(brush, args.ClipRectangle);
            // there are 7 white keys per octave
            var whiteKeyCount = 7 * _octaves;
            int key;

            // first we must paint the highlighted portions
            // TODO: Only paint if it's inside the ClipRectangle
            using (var selBrush = new SolidBrush(_noteHighlightColor))
            {
                if (Orientation.Horizontal == _orientation)
                {
                    var wkw = Width / whiteKeyCount;
                    var bkw = unchecked ((int)Math.Max(3, wkw * .666666));
                    key = 0;
                    var ox = 0;
                    for (var i = 1; i < whiteKeyCount; ++i)
                    {
                        var x = i * wkw;
                        var k = i % 7;
                        if (3 != k && 0 != k)
                        {
                            if (_keys[key])
                            {
                                g.FillRectangle(selBrush, ox + 1, 1, wkw - 1, Height - 2);
                            }
                            ++key;
                            if (_keys[key])
                            {
                                g.FillRectangle(selBrush, x - (bkw / 2) + 1, 1, bkw - 1, unchecked ((int)(Height * .666666)));
                            }
                            ++key;
                            if (_keys[key])
                            {
                                g.FillRectangle(selBrush, x, 1, wkw - 1, Height - 2);
                            }
                        }
                        else
                        {
                            if (_keys[key])
                            {
                                g.FillRectangle(selBrush, ox + 1, 1, wkw - 1, Height - 2);
                            }
                            ++key;
                            if (_keys[key])
                            {
                                g.FillRectangle(selBrush, x, 1, wkw - 1, Height - 2);
                            }
                        }
                        ox = x;
                    }
                    if (_keys[_keys.Length - 1])
                    {
                        g.FillRectangle(selBrush, ox, 1, Width - ox - 1, Height - 2);
                    }
                }
                else   // vertical
                {
                    var wkh = Height / whiteKeyCount;
                    var bkh = unchecked ((int)Math.Max(3, wkh * .666666));
                    key = _keys.Length - 1;
                    var oy = 0;
                    for (var i = 1; i < whiteKeyCount; ++i)
                    {
                        var y = i * wkh;
                        var k = i % 7;
                        if (4 != k && 0 != k)
                        {
                            if (_keys[key])
                            {
                                g.FillRectangle(selBrush, 1, oy + 1, Width - 2, wkh - 1);
                            }
                            --key;
                            if (_keys[key])
                            {
                                g.FillRectangle(selBrush, 1, y - (bkh / 2) + 1, unchecked ((int)(Width * .666666)) - 1, bkh - 2);
                            }
                            --key;
                            if (_keys[key])
                            {
                                g.FillRectangle(selBrush, 1, y, Width - 2, wkh - 1);
                            }
                        }
                        else
                        {
                            if (_keys[key])
                            {
                                g.FillRectangle(selBrush, 1, oy + 1, Width - 2, wkh - 1);
                            }
                            --key;
                            if (_keys[key])
                            {
                                g.FillRectangle(selBrush, 1, y, Width - 2, wkh - 1);
                            }
                        }
                        oy = y;
                    }
                    if (_keys[0])
                    {
                        g.FillRectangle(selBrush, 1, oy, Width - 2, Height - oy - 1);
                    }
                }
                // Now paint the black keys and the borders between keys
                using (var brush = new SolidBrush(_blackKeyColor))
                {
                    using (var pen = new Pen(_borderColor))
                    {
                        g.DrawRectangle(pen, rect);
                        if (Focused)
                        {
                            var rect2 = rect;
                            rect2.Inflate(-2, -2);
                            ControlPaint.DrawFocusRectangle(g, rect2);
                        }
                        if (Orientation.Horizontal == _orientation)
                        {
                            var wkw = Width / whiteKeyCount;
                            var bkw = unchecked ((int)Math.Max(3, wkw * .666666));
                            key = 0;
                            for (var i = 1; i < whiteKeyCount; ++i)
                            {
                                var x = i * wkw;
                                var k = i % 7;
                                if (3 != k && 0 != k)
                                {
                                    g.DrawRectangle(pen, x - (bkw / 2), 0, bkw, unchecked ((int)(Height * .666666)) + 1);
                                    ++key;
                                    if (!_keys[key])
                                    {
                                        g.FillRectangle(brush, x - (bkw / 2) + 1, 1, bkw - 1, unchecked ((int)(Height * .666666)));
                                    }
                                    g.DrawLine(pen, x, 1 + unchecked ((int)(Height * .666666)), x, Height - 2);
                                    ++key;
                                }
                                else
                                {
                                    g.DrawLine(pen, x, 1, x, Height - 2);
                                    ++key;
                                }
                            }
                        }
                        else // vertical
                        {
                            var wkh = Height / whiteKeyCount;
                            var bkh = unchecked ((int)Math.Max(3, wkh * .666666));
                            key = _keys.Length - 1;
                            for (var i = 1; i < whiteKeyCount; ++i)
                            {
                                var y = i * wkh;
                                var k = i % 7;
                                if (4 != k && 0 != k)
                                {
                                    g.DrawRectangle(pen, 0, y - (bkh / 2), unchecked ((int)(Width * .666666)), bkh - 1);
                                    --key;
                                    if (!_keys[key])
                                    {
                                        g.FillRectangle(brush, 1, y - (bkh / 2) + 1, unchecked ((int)(Width * .666666)) - 1, bkh - 2);
                                    }
                                    g.DrawLine(pen, 1 + unchecked ((int)(Width * .666666)), y, Width - 2, y);
                                    --key;
                                }
                                else
                                {
                                    g.DrawLine(pen, 1, y, Width - 2, y);
                                    --key;
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #28
0
    /// <summary>
    /// Paints the drop-down, including all items within the scrolled region
    /// and, if appropriate, the scrollbar.
    /// </summary>
    /// <param name="e"></param>
    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);

        if (_scrollBarVisible)
        {
            Rectangle upper = new Rectangle(_scrollBar.DisplayRectangle.Left, _scrollBar.DisplayRectangle.Top, _scrollBar.DisplayRectangle.Width, _scrollBar.Thumb.Top - _scrollBar.DisplayRectangle.Top);
            Rectangle lower = new Rectangle(_scrollBar.DisplayRectangle.Left, _scrollBar.Thumb.Bottom, _scrollBar.DisplayRectangle.Width, _scrollBar.DisplayRectangle.Bottom - _scrollBar.Thumb.Bottom);

            if (_sourceControl.DrawWithVisualStyles && ScrollBarRenderer.IsSupported)
            {
                ScrollBarRenderer.DrawUpperVerticalTrack(e.Graphics, upper, GetScrollBarState(upper));
                ScrollBarRenderer.DrawLowerVerticalTrack(e.Graphics, lower, GetScrollBarState(lower));
                ScrollBarRenderer.DrawArrowButton(e.Graphics, _scrollBar.UpArrow, GetScrollBarStateUp());
                ScrollBarRenderer.DrawArrowButton(e.Graphics, _scrollBar.DownArrow, GetScrollBarStateDown());
                ScrollBarRenderer.DrawVerticalThumb(e.Graphics, _scrollBar.Thumb, GetScrollBarThumbState());
                ScrollBarRenderer.DrawVerticalThumbGrip(e.Graphics, _scrollBar.Thumb, GetScrollBarThumbState());
            }
            else
            {
                Rectangle bounds = _scrollBar.DisplayRectangle;
                bounds.Offset(1, 0);
                Rectangle up = _scrollBar.UpArrow;
                up.Offset(1, 0);
                Rectangle down = _scrollBar.DownArrow;
                down.Offset(1, 0);
                Rectangle thumb = _scrollBar.Thumb;
                thumb.Offset(1, 0);

                using (HatchBrush brush = new HatchBrush(HatchStyle.Percent50, SystemColors.ControlLightLight, SystemColors.Control)) {
                    e.Graphics.FillRectangle(brush, bounds);
                }

                ControlPaint.DrawScrollButton(e.Graphics, up, ScrollButton.Up, GetButtonState(_scrollBar.UpArrow));
                ControlPaint.DrawScrollButton(e.Graphics, down, ScrollButton.Down, GetButtonState(_scrollBar.DownArrow));
                ControlPaint.DrawButton(e.Graphics, thumb, ButtonState.Normal);
            }
        }

        for (int i = _scrollOffset; i < (_scrollOffset + _numItemsDisplayed); i++)
        {
            bool     highlighted = ((_highlightedItemIndex == i) && !_sourceControl.ShowCheckBoxes);
            NodeInfo item        = _visibleItems[i];

            // background
            if (highlighted)
            {
                e.Graphics.FillRectangle(SystemBrushes.Highlight, item.DisplayRectangle);
            }

            // image and glyphs
            if (item.Image != null)
            {
                Rectangle imgBounds = new Rectangle(item.DisplayRectangle.Location, item.Image.Size);
                e.Graphics.DrawImage(item.Image, imgBounds);

                if (_sourceControl.ShowCheckBoxes)
                {
                    CheckBoxState state   = GetCheckBoxState(item.Node.CheckState, item.CheckRectangle);
                    Size          chkSize = CheckBoxRenderer.GetGlyphSize(e.Graphics, state);
                    CheckBoxRenderer.DrawCheckBox(e.Graphics, Point.Add(item.CheckRectangle.Location, new Size((item.CheckRectangle.Width - chkSize.Width) / 2, (item.CheckRectangle.Height - chkSize.Height) / 2)), state);
                }
            }

            Rectangle textBounds = new Rectangle(item.DisplayRectangle.X + item.Image.Width + 2, item.DisplayRectangle.Y, item.DisplayRectangle.Width - item.Image.Width - 4, _itemHeight);

            using (Font font = new Font(Font, _visibleItems[i].Node.FontStyle)) {
                TextRenderer.DrawText(e.Graphics, item.Node.Text, font, textBounds, highlighted ? SystemColors.HighlightText : ForeColor, TEXT_FORMAT_FLAGS);
            }

            if (highlighted && _sourceControl.Focused && _sourceControl.ShowsFocusCues)
            {
                ControlPaint.DrawFocusRectangle(e.Graphics, item.DisplayRectangle);
            }
        }
    }
コード例 #29
0
        /// <summary>
        /// Paints control adornments.
        /// </summary>
        /// <param name="e">The <see cref="PaintEventArgs"/> instance containing the event data.</param>
        protected virtual void PaintAdornments(PaintEventArgs e)
        {
            Point point;

            point = this.ValueToPoint(this.Value);

            // divider
            if (this.ShowValueDivider)
            {
                Point  start;
                Point  end;
                IntPtr hdc;

                if (this.Orientation == Orientation.Horizontal)
                {
                    start = new Point(point.X, this.BarBounds.Top);
                    end   = new Point(point.X, this.BarBounds.Bottom);
                }
                else
                {
                    start = new Point(this.BarBounds.Left, point.Y);
                    end   = new Point(this.BarBounds.Right, point.Y);
                }

                // draw a XOR'd line using Win32 API as this functionality isn't part of .NET
                hdc = e.Graphics.GetHdc();
                NativeMethods.SetROP2(hdc, NativeMethods.R2_NOT);
                NativeMethods.MoveToEx(hdc, start.X, start.Y, IntPtr.Zero);
                NativeMethods.LineTo(hdc, end.X, end.Y);
                e.Graphics.ReleaseHdc(hdc);
            }

            // drag nub
            if (this.NubStyle != ColorSliderNubStyle.None && this.SelectionGlyph != null)
            {
                int x;
                int y;

                if (this.Orientation == Orientation.Horizontal)
                {
                    x = point.X - this.NubSize.Width / 2;
                    if (this.NubStyle == ColorSliderNubStyle.BottomRight)
                    {
                        y = this.BarBounds.Bottom;
                    }
                    else
                    {
                        y = this.BarBounds.Top - this.NubSize.Height;
                    }
                }
                else
                {
                    y = point.Y - this.NubSize.Height / 2;
                    if (this.NubStyle == ColorSliderNubStyle.BottomRight)
                    {
                        x = this.BarBounds.Right;
                    }
                    else
                    {
                        x = this.BarBounds.Left - this.NubSize.Width;
                    }
                }

                e.Graphics.DrawImage(this.SelectionGlyph, x, y);
            }

            // focus
            if (this.Focused)
            {
                ControlPaint.DrawFocusRectangle(e.Graphics, Rectangle.Inflate(this.BarBounds, -2, -2));
            }
        }
コード例 #30
0
ファイル: ListControl.cs プロジェクト: SheffieldUni/growl-uos
        void ListControl_DrawItem(object sender, DrawItemEventArgs e)

        {
            if (e.Index < 0)
            {
                return;
            }



            if (this.listbox.Items != null && this.listbox.Items.Count > 0)

            {
                if (e.Index != ListBox.NoMatches)

                {
                    object obj = this.listbox.Items[e.Index];



                    // handle background

                    if ((e.State & DrawItemState.Selected) != 0)

                    {
                        e.Graphics.FillRectangle(Brushes.LightGray, e.Bounds);

                        ControlPaint.DrawFocusRectangle(e.Graphics, e.Bounds);
                    }

                    else

                    {
                        e.DrawBackground();
                    }



                    int newX = e.Bounds.X;

                    ListControlItem item = obj as ListControlItem;

                    if (item != null)

                    {
                        Image icon = item.RegisteredObject.GetIcon();

                        using (icon)

                        {
                            if (icon != null)

                            {
                                e.Graphics.DrawImage(icon, e.Bounds.X + 1, e.Bounds.Y + 1, IMAGE_SIZE, IMAGE_SIZE);

                                newX = e.Bounds.Left + IMAGE_SIZE + this.Margin.Right;
                            }
                        }
                    }



                    // check if this is the 'default' value of the list

                    bool isDefault = false;

                    if (this.isDefaultComparer != null)

                    {
                        isDefault = this.isDefaultComparer(obj);
                    }



                    // handle text

                    bool disposeFont = false;

                    string text = obj.ToString();

                    Font font = e.Font;

                    if (isDefault)

                    {
                        text = text + " [default]";

                        font = new Font(e.Font, FontStyle.Bold);

                        disposeFont = true;
                    }

                    Rectangle rect = new Rectangle(newX, e.Bounds.Y, e.Bounds.Right - newX, e.Bounds.Height);

                    TextFormatFlags flags = TextFormatFlags.EndEllipsis | TextFormatFlags.NoClipping;

                    TextRenderer.DrawText(e.Graphics, text, font, rect, this.foreColor, flags);

                    if (disposeFont)

                    {
                        font.Dispose();

                        font = null;
                    }



                    //Utility.WriteLine("drawitem - " + text);
                }
            }
        }