'Hiding dashed outline around trackbar control when selected

In C# winforms, is there a way to not show the dashed focus outline border that shows around a trackbar control when it is being used?

Details: This outline looks kinda tacky to me, so I'm just shooting for aesthetics to not show it.

Thanks,

Adam



Solution 1:[1]

ShowFocusCues didn't work for me, but this did:

   internal class NoFocusTrackBar : System.Windows.Forms.TrackBar
   {
      [System.Runtime.InteropServices.DllImport("user32.dll")]
      public extern static int SendMessage(IntPtr hWnd, uint msg, int wParam, int lParam);

      private static int MakeParam(int loWord, int hiWord)
      {
         return (hiWord << 16) | (loWord & 0xffff);
      }

      protected override void OnGotFocus(EventArgs e)
      {
         base.OnGotFocus(e);
         SendMessage(this.Handle, 0x0128, MakeParam(1, 0x1), 0);
      }
   }

See documentation on WM_UPDATEUISTATE for how this works (basically sending a message to turn the dumb thing off the trackbar gets the focus).

Solution 2:[2]

I know it's an old question but this is simpler if anyone interested:

public class TrackBarWithoutFocus : TrackBar
{
    private const int WM_SETFOCUS = 0x0007;

    protected override void WndProc(ref Message m)
    {
        if (m.Msg == WM_SETFOCUS)
        {
            return;
        }

        base.WndProc(ref m);
    }
}

Solution 3:[3]

private void trackBar1_MouseLeave(object sender, EventArgs e)
    {
        button2.Select();
    }

really old but i made a button with visible set to false and selected that one when leaving trackbar area

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Steven Brown
Solution 2 yclkvnc
Solution 3 pena