Det tar en lite stund och hålla på med dynamiska kontroller som skall laddas, det blir en del PaintEvent som skall köras.
Du kan försöka dig på att frysa formuläret innan du lägger till alla dina egna kontroller.
Du kan testa att sno lite från följande kod, för mer info så ut och sök på google.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Threading;
using System.Text;
using System.Windows.Forms;
namespace BRF.BOSS.Frontend.Winform.UserControls.Container
{
public partial class UCFlow : UserControl
{
#region Declaration
//-- It's used to freez the painting to screen
private int paintFrozen = 0;
private const int WM_SETREDRAW = 0xB;
//-- Declare Win32 API used to freez the painting on screen
[System.Runtime.InteropServices.DllImport("User32")]
private static extern bool SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
#endregion
#region Properties
/// <summary>
/// Private propoerties used to declare when to freez and unfreez painting to screen
/// </summary>
private bool FreezePainting
{
get { return paintFrozen > 0; }
set{
if( value && IsHandleCreated && this.Visible )
{
if( 0 == paintFrozen++ )
{
SendMessage(Handle, WM_SETREDRAW, 0, 0);
}
}
if( !value )
{
if( paintFrozen == 0 )
{
return;
}
if( 0 == --paintFrozen )
{
SendMessage(Handle, WM_SETREDRAW, 1, 0);
Invalidate(true);
}
}
}
}
#endregion
#region Methods
private void Initialize()
{
LoadUserControl();
}
/// <summary>
/// Binds the correct usercontrol to the ucflow container based on the type of the FlowElementBase
/// </summary>
/// <param name="flowElementBase"></param>
private void LoadUserControl()
{
#if debug
//-- If we are in debug mode, we like to know how long time the usercontrol took to load
double timePeriod = 0.0;
DateTime startTime = DateTime.Now;
#endif
//-- Minimze flickering, since it only will show the usercontrol when it has
//-- initialize all child controls
this.FreezePainting = true;
//-- Load usercontrol
UserControl userControl = LoadUserControlFromFlowElement();
panelFlow.Controls.Clear();
userControl.Dock = DockStyle.Fill;
panelFlow.Controls.Add(userControl);
//-- Releas the lock on screen and redraw control to screen
this.FreezePainting = false;
#if debug
//-- If we are in debug mode, we like to know how long time the usercontrol took to load
timePeriod = TimeSpan.FromTicks(DateTime.Now.Ticks - startTime.Ticks).TotalMilliseconds;
System.Diagnostics.Debug.Print(string.Format("UserControl {0} took {0} ms to load", typeof(userControl).Assembly.FullName, timePeriod));
#endif
}
#endregion
#region Constructor
public UCFlow()
{
InitializeComponent();
Initialize();
}
#endregion
}
}
- M
