Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I change the ProfessionalColorTable?

Override ProfessionalColorTable and change only the colors you care about.

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
     Dim t As MyColorTable = New MyColorTable
    ToolStrip1.Renderer = New ToolStripProfessionalRenderer(t)
  End Sub
  Class MyColorTable
    Inherits ProfessionalColorTable
    Public Overrides ReadOnly Property ButtonPressedGradientBegin() As Color
    Get
      Return Color.FromArgb(147, 210, 254)
    End Get
    End Property
    Public Overrides ReadOnly Property ButtonPressedGradientMiddle() As System.Drawing.Color
    Get
      Return Color.FromArgb(83, 132, 252)
    End Get
    End Property
    Public Overrides ReadOnly Property ButtonPressedGradientEnd() As System.Drawing.Color
    Get
      Return Color.FromArgb(18, 55, 250)
    End Get
    End Property
    Public Overrides ReadOnly Property ButtonSelectedGradientBegin() As Color
    Get
      Return Color.FromArgb(204, 227, 255)
    End Get
    End Property
    Public Overrides ReadOnly Property ButtonSelectedGradientMiddle() As System.Drawing.Color
    Get
      Return Color.FromArgb(160, 199, 255)
    End Get
    End Property
    Public Overrides ReadOnly Property ButtonSelectedGradientEnd() As System.Drawing.Color
    Get
      Return Color.FromArgb(116, 171, 255)
    End Get
    End Property
  End Class

Below is an example of Custom Professional Colors w/ built in ProfessionalRenderer and setting Renderer at runtime.

 class Form2 : Form
 {
  public Form2()
  {
   // new toolstrip
   ToolStrip ts = new ToolStrip();
   ts.Items.Add("Apples");
   ts.Items.Add("Oranges");
   ts.Items.Add("Pears");
   ts.Items.Add("Change Colors", null, new EventHandler(ChangeColors_Click));

   // new menustrip, with new window
   MenuStrip ms = new MenuStrip();
   ms.Dock = DockStyle.Top;

   // add top level items
   ms.Items.Add("File");
   ms.Items.Add("Edit");
   ms.Items.Add("View");
   ms.Items.Add("Window");

   // Add toolstrip to controls collection
   this.Controls.Add(ts);

   // Add menustrip to controls collection last - Z order!
   this.Controls.Add(ms);
  }

  void ChangeColors_Click(object sender, EventArgs e)
  {
   ToolStripManager.Renderer = new ToolStripProfessionalRenderer(new CustomProfessionalColors());
  }
 }

 class CustomProfessionalColors : ProfessionalColorTable
 {
  public override Color ToolStripGradientBegin
  { get { return Color.BlueViolet; } }

  public override Color ToolStripGradientMiddle
  { get { return Color.CadetBlue; } }

  public override Color ToolStripGradientEnd
  { get { return Color.CornflowerBlue; } }

  public override Color MenuStripGradientBegin
  { get { return Color.BlueViolet; } }

  public override Color MenuStripGradientEnd
  { get { return Color.CornflowerBlue; } }
 }