简体   繁体   中英

Panel is flickering when switching from one winform to another

I render my image on the panel.

using Microsoft.DirectX.Direct3D;

Device device;

this.device = new Device(0, DeviceType.Hardware, this.panel2,
                CreateFlags.HardwareVertexProcessing, presentationParameters);

As a result, the panel is flickering when I try to switch the winform from one to another.

I know it is hard to describe the scenario. Hence I hereby upload a video clip (.swf) to my google drive, you guys may download it and open it with window media player to watch the video.

Below is the shared link: https://drive.google.com/file/d/0B6wTfkJvzke_aVJwanVkaU1iSVU/edit?usp=sharing

Inside the video, I am running my application at debug mode, then I click on the 'chrome browser' tab in task bar to access the 'chrome browser', when the minimized 'chrome browser' pop out, the panel will be flickered. Then when I minimize the 'chrome browser' again, the panel flickered again.

The problem occur when there is some other winform being placed above the panel on screen.

Any comment on the above matter? Help is needed.

I ran into the same flicker issues when using DirectX with Panel . It turned out that the OS draw events were colliding my own. To fix this, you need to disable OS drawing on your Panel by creating a custom panel. Something as simple as this should suffice.

class Direct3DPanel : Panel
{
    public Direct3DPanel()
    {
        this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
    }
}

The SetStyle method call tells the OS that only you should draw in Direct3DPanel . Note that once you do this, you will be responsible for all drawing. You may need to handle the Paint event and call your draw logic depending on your current architecture.

You can get more information about the different ControlStyles here http://msdn.microsoft.com/en-us/library/system.windows.forms.controlstyles(v=vs.110).aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM