Frage

Ich versuche, einige gehäutige Formen (nur den Grenze und die Bildunterschrift) mit einem anderen Ansatz zu kreieren, als Sie normalerweise sehen, aber ich habe einige Probleme mit der Flackerne, während ich die Größe der Form der Form habe.

Ich weiß nicht, wie ich das Problem sonst erklären soll. Hier ist ein Video, das ich erstellt habe, um das Problem zu demonstrieren:http://www.screencast.com/t/aiqk9szmz

Hier finden Sie auch eine VS2008 -Testlösung mit dem gesamten Code, der das Formular anschließt:http://stuff.nazgulled.net/misc/testform.zip

Ich hoffe, jemand kann mir helfen, das Flackern loszuwerden ...

War es hilfreich?

Lösung

(Dies ist eine Vista-spezifische Lösung; sie funktioniert nur, wenn das Desktop-Komposition aktiviert ist.)

Es sieht so aus, als ob Windows den Inhalt von geendelten Formularen initialisiert, indem die Pixel an der ursprünglichen Rand des Formulars in die neuen Bereiche kopiert werden. In Ihrem Fall sind die neuen Bereiche schwarz initialisiert, wahrscheinlich weil die Form ursprünglich schwarze Pixel an ihrer Grenze hatte.

Um das Flackern loszuwerden, behalten Sie einfach die Pixellinie in der rechten Seite und in Bottommost in der Form immer auf Transparenzkey ein. Dies hält die neuen Bereiche transparent, bis Sie die Chance haben, sie neu zu streichen. Erstellen Sie das Formular 1 Pixel breiter und größer als nötig und malen Sie die zusätzlichen Pixel transparent.

Beispiel: Transparentform.zip

Andere Tipps

That's what I use in my base form's constructor:

this.SetStyle( ControlStyles.AllPaintingInWmPaint, true );
this.SetStyle( ControlStyles.UserPaint, true );
this.SetStyle( ControlStyles.OptimizedDoubleBuffer, true );
this.SetStyle( ControlStyles.ResizeRedraw, true );

I think the key is the use of "AllPaintingInWmPaint".

If you want to make your form have a irregular shape you will have to turn to regions (if you can easily define your form's region using geometric shapes like Circle and Rectangle). Create a System.Drawing.Graphics.Region object and add shapes to it. I think the property on the form is called Region - assign to it your region that you created.

Your other option is to use layered windows. Somebody has done all the work for you. Layered windows do not work on versions of Windows older than 2000, but they have the added benefit of being semi-transparent.

Your final option is to use WPF and set AllowsTransparency="True" WindowStyle="None". That will remove the chrome (Google "chromeless window WPF" for like a million examples).

Finally if you are brave and patient you could always capture the desktop behind your window and paint it before anything else. You will need to resort to some fancy hackery if your window moves: I don't really recommend this approach - but you need to know all your options.

You'll have to give up on using the Form.TransparencyKey property if you want to avoid the ugly uninitialized black video overlay flicker. It doesn't do anything useful in your sample program.

Tried enabling DoubleBuffering ?

Oh, and by the way, using SLIMcode's code won't work unless you put all your paint logic in override OnPaint(). If this doesn't sound familiar you probably don't know that you can forcefully ask for a repaint by calling Invalidate() on your form. It's a mission to refactor your code into a single Paint method - but it results in cleaner code in the end.

To get rid of the flicker while resizing the win form, suspend the layout while resizing. Override the forms resizebegin/resizeend methods as below.

protected override void OnResizeBegin(EventArgs e) {
    SuspendLayout();
    base.OnResizeBegin(e);
}
protected override void OnResizeEnd(EventArgs e) {
    ResumeLayout();
    base.OnResizeEnd(e);
}

This will leave the controls intact (as they where before resizing) and force a redraw when the resize operation is completed.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top