Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

first tab key press is refreshing form

$
0
0
 

I'm having a weird repaint problem on one of my dialog forms.  The form is borderless and shown in a "lightbox" style, centered on parent form, with a partial-tranparency around the border. 

EDIT: this ONLY happens if the form has one or more Labels on it.  Remove the labels, and the flashing goes away! 

The issue is the first and only the first time the TAB key is pressed in this form, it repaints.  I can pick controls and change focus all I want using the mouse, but as soon as TAB key is pressed, the form flashes as a result of a repaint.  It oly does htis once.  Subsequent presses of the TAB key will do nothig.

Here is the paint code:

            // draw the blacked-out lightbox area
            using (Brush brush = new SolidBrush(Color.FromArgb(100, Color.Black)))
            {
                e.Graphics.FillRectangle(brush, e.ClipRectangle);
            }
            // draw the background image
            int w = BackgroundImage.Width;
            int h = BackgroundImage.Height;
            int x = (this.Width - w) / 2;
            int y = (this.Height - h) / 2;
            e.Graphics.DrawImage(BackgroundImage,
                                 new Rectangle(x, y, w, h),
                                 new Rectangle(0, 0, w, h),
                                 GraphicsUnit.Pixel);     

If I enable doubl-buffer or composite style, the problem goes away, but I can use neither as I then lose the transparecy effect and the margins around the popup will be solid black.

Anybody have any idea how to avoid this reflresh?  I've tried lots of various styles (userpaint, redraw in paint only, etc.) and no luck.  The parent form does have WS_EX_COMPOSITED enabled, not that it should matter.

Oh I forgot to add, after this first Tab and repaint, the semi-transparent margin border is rendered darker, which makes sense as it is drawing over itself.

Thanks in advance for any thoughts on this.

- Ryan




Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>