Form - control ghosting RRS feed

  • Question

  • Hey

    I have set my form to DoubleBuffer & also added MyForm.SuspendLayout but i still get thisghosted look before all of the controls are fully loaded. How can i resolve this? its looks ugly when loading


    Im a self taught VB.Net guy who writes code for Autodesk Inventor. I may not know the terminology but i try so please be patient. Im not a kid so please dont treat me like one :)

    Thursday, June 11, 2020 1:32 AM

All replies

  • Hi

    I don't get that any time.

    It *may* be connected with processor busy type of thing - do you do any Sub or Function calls in the Load or Shown event handlers, or, any longish calculations during the Load?

    Suggestion: comment out anything not connected with Control property setting in the Load/Shgown event handlers and try to run to see if that works OK.

    Regards Les, Livingston, Scotland

    Thursday, June 11, 2020 12:03 PM
  • This can happen when an operation is busy and provides no time for the user interface to paint. One way around this is to wrap the code stealing time into a Task. To see an example that in this case loads data from a database see the following code sample were in form shown (better to use than form load) DataOperations.ReadCustomers has a Task.


    Code which is called from Form shown.

    The above happens to use async methods in the .NET Framework while the following does not, its a do nothing method but if you put code after the green box then that will run async and note the IsCancellationRequest which allows the user to cancel


    If you try any of this and run into a cross thread issue I have this extension method. Example where args is from another thread.

    Private Sub FileOperations_OnMonitor(ByVal args As MonitorArgs)
    		lb.SelectedIndex = lb.Items.Count - 1
    	End Sub)
    End Sub

    Other than that there is the old way of using a BackGroundWorker component.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    Thursday, June 11, 2020 1:39 PM
  • Hey Karen

    Thanks for the detailed reply. I have moved the code in the FormLoad to FormShown. Havent tested it yet. I did try adding the async method but couldnt place the await properly in my code. I am getting data from a remote server (already in the shown event) but by using a BLL DAL data method like this-

    Dim ed_bll As TryApp.BLL.GetServerData = New TryApp.BLL.GetServerData
    Dim GetServerData As List(Of TryApp.BLL.GetServerData_details) = ed_bll.SelectGetServerData(Key)

    I am however using a background worker later in my project to collect a bunch of data from a datatable so i will look at implementing your method to use a more up to date method


    Im a self taught VB.Net guy who writes code for Autodesk Inventor. I may not know the terminology but i try so please be patient. Im not a kid so please dont treat me like one :)

    Thursday, June 11, 2020 5:25 PM
  • Hi,

    Have you solved this problem?

    I think the answer given by Karen can provide you with a solution. 

    If you have resolved the issue then please mark the post or posts that helped you as The Answer using the Mark as Answer link at the bottom of the post. Marking answers will help other community members find solutions in the future.

    Best Regards,

    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 16, 2020 5:17 AM