title: Add static method to current custom class
body: <p>I have custom progress bar (is a progress bar with text)</p>
  <p>Custom progressbar code:</p>
  <pre><code>public enum ProgressBarDisplayText
      {
          Percentage,
          CustomText
      }
  
      public class CustomProgressBar : ProgressBar
      {
  
  
          [DllImportAttribute(&quot;uxtheme.dll&quot;)]
          private static extern int SetWindowTheme(IntPtr hWnd, string appname, string idlist);
  
          protected override void OnHandleCreated(EventArgs e)
          {
              SetWindowTheme(this.Handle, &quot;&quot;, &quot;&quot;);
              base.OnHandleCreated(e);
          }
  
          //Property to set to decide whether to print a % or Text
          public ProgressBarDisplayText DisplayStyle { get; set; }
  
          //Property to hold the custom text
          public String CustomText { get; set; }
  
          public CustomProgressBar()
          {
              // Modify the ControlStyles flags
              //http://msdn.microsoft.com/en-us/library/system.windows.forms.controlstyles.aspx
              SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
              SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
          }
  
          protected override void OnPaint(PaintEventArgs e)
          {
              Rectangle rect = ClientRectangle;
              Graphics g = e.Graphics;
  
              ProgressBarRenderer.DrawHorizontalBar(g, rect);
              rect.Inflate(-3, -3);
              if (Value &gt; 0)
              {
                  // As we doing this ourselves we need to draw the chunks on the progress bar
                  Rectangle clip = new Rectangle(rect.X, rect.Y, (int)Math.Round(((float)Value / Maximum) * rect.Width), rect.Height);
                  ProgressBarRenderer.DrawHorizontalChunks(g, clip);
              }
  
              // Set the Display text (Either a % amount or our custom text
              int percent = (int)(((double)this.Value / (double)this.Maximum) * 100);
              string text = DisplayStyle == ProgressBarDisplayText.Percentage ? percent.ToString() + '%' : CustomText;
  
              //string text = DisplayStyle == ProgressBarDisplayText.Percentage ? Value.ToString() + '%' : CustomText;
  
  
              using (Font f = new Font(FontFamily.GenericSerif, 10, FontStyle.Bold))
              {
  
                  SizeF len = g.MeasureString(text, f);
                  // Calculate the location of the text (the middle of progress bar)
                  // Point location = new Point(Convert.ToInt32((rect.Width / 2) - (len.Width / 2)), Convert.ToInt32((rect.Height / 2) - (len.Height / 2)));
                  Point location = new Point(Convert.ToInt32((Width / 2) - len.Width / 2), Convert.ToInt32((Height / 2) - len.Height / 2));
                  // The commented-out code will centre the text into the highlighted area only. This will centre the text regardless of the highlighted area.
                  // Draw the custom text
                  g.DrawString(text, f, Brushes.Black, location);
              }
  
          }
      }
  </code></pre>
  <p>Now I want to change color of progress bar so I saw this <a href="https://stackoverflow.com/a/9753302/13084319">solution</a></p>
  <p>So I try to add to my code</p>
  <pre><code>  [DllImport(&quot;user32.dll&quot;, CharSet = CharSet.Auto, SetLastError = false)]
    static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr w, IntPtr l);
      public static void SetState(this ProgressBar pBar, int state)
      {
          SendMessage(pBar.Handle, 1040, (IntPtr)state, IntPtr.Zero);
      }
  </code></pre>
  <p>But as you can see this code is for an extension method, but my current <code>CustomProgressBar</code> inherits <code>ProgressBar</code> and it does not permit to use static classes. So it throw me:</p>
  <blockquote>
  <p>Extension method must be defined in a non-generic static class</p>
  </blockquote>
  <p>how can I add this method to my current class? Regards</p>