0

I am creating a Button and setting FlatStyle to System.

Because this mode does not normally support images, to display an image along with the text, the Button's own Text is set to "" and I am painting my own image and text on top by Graphics.FromHwnd and TextRenderer in WndProc, by capturing WM_PAINT and doing my own drawing after calling base.WndProc.

This works great, except for one problem: On Windows 7, highlighted buttons pulse slowly between gray and blue. I find this pulsing causes the button to occasionally flicker.

  1. I already use WS_EX_COMPOSITED.
  2. I have tried DoubleBuffered = true. It does not help.
  3. I have tried BufferedGraphics with WM_PRINTCLIENT, but this does not draw in the Aero style, so there is no pulsing at all.

Any ideas?

LarsTech
  • 80,625
  • 14
  • 153
  • 225
James
  • 1,874
  • 1
  • 16
  • 18
  • Why are you forced to use FlatStyle.System? – LarsTech Sep 26 '17 at 16:06
  • I'm not forced to. It uses system styling, including fading animations. It looks better. – James Sep 26 '17 at 16:08
  • 1
    Well, either way, it always helps to post the code you are using that causes the flicker. Don't make your audience guess. – LarsTech Sep 26 '17 at 16:10
  • One possibly solution in the meantime is to turn double buffering on in the control to see if that helps... it doesn't always, so post code if not. – Kevin Ford Sep 26 '17 at 18:09

1 Answers1

0

"Because this mode does not normally support images"... It turns out one can avoid this conundrum altogether.

On Windows Vista and newer, FlatStyle = System can be made to show images without any special painting. (On Windows XP, fallback to default painting.)

Send BM_SETIMAGE to the FlatStyle = System button to set an image. This will not work with Windows Forms's Button AutoSize implementation. So, measure with BCM_GETIDEALSIZE. Lastly, if the button has only an image and no text, set BS_BITMAP in CreateParams.Style.

James
  • 1,874
  • 1
  • 16
  • 18