Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
538 views
in Technique[技术] by (71.8m points)

c# - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...