Search code examples
c#winformsdevexpressmdiparent

Devexpress Winforms - Forms are fractured while transition one form to another


I am using Devexpress winform for my project. There are three forms simply. The first is MainForm that used MdiParent, the second is FormArticles that used listing articles about law into GridControl. And the last is FormArticleView that used viewing selected article into pdfViewer control. I managed to use documentManager and SplashScreenManager while loading Mdi Child forms and articles into one of Mdi Child form FormArticles. Here is my code:

   public prjLibrary()
    {
        InitializeComponent();
        var frm = new FormArticles{ MdiParent = this, Dock = DockStyle.Fill };
        frm.Show();
    }

While transition one form to another, the forms is fractured and after load it is fixed. Here is my screenshot: enter image description here And here is fixed view: enter image description here How can I fix fractured view while transition of forms?


Solution

  • This is because when the form from the first screenshot is getting focused, the controls have to be rendered in their Paint-event. This seems to take some time but you can see the fractured text is shown in rectangles where I think the underlying controls (radio buttons, text boxes, labels) are placed. So they are not rendered yet and not ready to go while any other call is blocking the thread. I think the problem is that you create a new form in your mainForm's constructor.

    Anyway, it is a good practice to perform heavy tasks (which seem to block the painting of your controls) in a background thread having the UI waiting for the response. If this is too hard to do, try to do it after the UI is shown to the user. This could be the OnLoad- or even OnShown-event.

    Note that I don't want to encourage you to write any business code into the UI layer but that seems not to be the question here.