Gavin
Gavin

Reputation: 6394

Alt key causes form to redraw

I've come across a problem that I'm hoping one of you fine thinkers can overcome...

For some reason, once I have loaded up my Windows Form, if the user presses the Alt key, the form redraws causing a flash.

This only happens the first time, so any subsequent presses of the Alt key do nothing.

I don't have any menu strips or events that handle the key press, so I can only assume it's either a setting I haven't set, or one that I have unknowingly set.

FYI, the form does the following in the constructor

DoubleBuffered = true;
SetStyle(ControlStyles.OptimizedDoubleBuffer | 
         ControlStyles.AllPaintingInWmPaint, true);

This is because I have a number of Panels and Labels that also do the same to implement transparency.

Fingers crossed, one of you will know why ;)

Upvotes: 4

Views: 1809

Answers (1)

Hans Passant
Hans Passant

Reputation: 942428

Paste this code into your form:

    protected override void WndProc(ref Message m) {
        // Suppress the WM_UPDATEUISTATE message
        if (m.Msg == 0x128) return;
        base.WndProc(ref m);
    }

It worked well to suppress the paint when I tried it. The focus cue handling in Windows is fairly bizarre, do test thoroughly to ensure this doesn't have unexpected side-effects.

Upvotes: 10

Related Questions