ColorToBrush() public static method

public static ColorToBrush ( Color c ) : Brush
c Color
return System.Drawing.Brush
Beispiel #1
0
        void OnDrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index == -1)
            {
                return;
            }

            LogData data = Items[e.Index] as LogData; // Get the current item and cast it to MyListBoxItem

            if (data != null)
            {
                e.Graphics.FillRectangle(textBg, e.Bounds);

                var brush = ColorSettings.ColorToBrush(data.FontColor);

                try
                {
                    // 文本太长时, 这里会造成崩溃
                    e.Graphics.DrawString( // Draw the appropriate text in the ListBox
                        data.Text,         // The message linked to the item
                        Font,              // Take the font from the listbox
                        brush,             // Set the color
                        e.Bounds           // Y pixel coordinate.  Multiply the index by the ItemHeight defined in the listbox.
                        );
                }
                catch
                {
                }
            }
            else
            {
                // The item isn't a MyListBoxItem, do something about it
            }
        }
        void PaintTabControl()
        {
            tabMain.DrawMode  = TabDrawMode.OwnerDrawFixed;
            tabMain.DrawItem += (sender, e) =>
            {
                var model = SafeGetModel(tabMain.TabPages[e.Index]);

                Rectangle myTabRect = tabMain.GetTabRect(e.Index);

                Brush textBrush = null;
                Brush bgBrush   = null;

                if (model.Running)
                {
                    bgBrush   = ColorSettings.ColorToBrush(Color.Green);
                    textBrush = ColorSettings.ColorToBrush(Color.White);
                }
                else if (model.SelfExit)
                {
                    bgBrush   = ColorSettings.ColorToBrush(Color.Red);
                    textBrush = ColorSettings.ColorToBrush(Color.White);
                }


                if (e.Index == tabMain.SelectedIndex)
                {
                    textBrush = ColorSettings.ColorToBrush(Color.White);
                    bgBrush   = ColorSettings.ColorToBrush(Color.Black);
                }
                else if (textBrush == null)
                {
                    textBrush = ColorSettings.ColorToBrush(Color.Black);
                }

                if (bgBrush != null)
                {
                    e.Graphics.FillRectangle(bgBrush, myTabRect);
                }


                //先添加TabPage属性
                e.Graphics.DrawString(tabMain.TabPages[e.Index].Text, this.Font, textBrush, myTabRect.X + 2, myTabRect.Y + 2);
            };
        }