title: Using large number of UserControl in WindowsForms
body: <p>I'm used to working with HTML apps in which there is no problem of creating a list of components (like phonebook contact).</p>
  
  <p><a href="https://i.stack.imgur.com/RPf9z.png" rel="nofollow noreferrer">Example of my app</a></p>
  
  <p>Now I have used this method in Windows Forms. One panel is populated with large number of custom UserControls (UC). Only 30 UserControls takes more than 5s to render. While the list of data from database is returnd in &lt;1s.</p>
  
  <p>This UC has only labels, PictureBox and Click event. It's called like this. This data is used to populate child controls.</p>
  
  <pre><code>new UserControl(MyModel data);
  </code></pre>
  
  <p>Is there a beter way of doing this? I would like to have user friendly GUI and not using Grid layout. It's not user friendly and very limited in terms of how data can be showed to user.</p>
  
  <pre><code>foreach (var data in myDbResult)
  {
      var uc = new MyUserControl(data);
      uc.Dock = DockStyle.Top;
      resultFlowPanel.Controls.Add(uc);
  }
  
  ...
  
  public MyUserControl(MyModel data)
  {
      this.data = data;
      InitializeComponent();
      label1.Text = data.name;
      label2.Text = data.address;
      // get some more data from database
      using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["AlarmDbCon"].ConnectionString))
      {
          payer = db.Query&lt;Models.g_UserPayer&gt;("SELECT TOP(1) * FROM g_UserPayer WHERE ID_User=@UserID", new
          {
              UserID = guard.ID_User
          }).FirstOrDefault();
      }
      label3.Text = payer.email;
      PictureBox.Image = payer.image;
  }
  </code></pre>