[.net] [C# , Compact Framework 1.1] Component creation / updating visual problem.

Started by
6 comments, last by kentylarsson 18 years, 4 months ago
Hi! I have a standard form, however some (lots of) buttons are created using code inside the constructor. During the creation of these buttons the form is updated, resulting in it being visible (even though it's pretty fast) that each control is added to the form (row by row, each for from left to right). Is there any way to avoid this? ::::: EXAMPLE CODE BEGIN

public FormClassName()
{
  // This is the constructor of "public class FromClassName : System.Windows.Forms.Form"

  //
  // Required for Windows Form Designer support
  //
  InitializeComponent();

  //
  // TODO: Add any constructor code after InitializeComponent call
  //

  // BEGIN: I would like everything inside the for-loops to turn up "at once"
  for (int j = 0 ; j < 8 ; j++)
    for (int i = 0 ; i < 8 ; i++)
    {
      Button b = new System.Windows.Forms.Button();
      b.Parent = this;
      b.Bounds = new Rectangle(0,0,20,20);
      b.Location = new System.Drawing.Point(i * b.Width, j * b.Height);
      this.Controls.Add(b);
    }
  //   END: I would like everything inside the for-loops to turn up "at once"
}
::::: EXAMPLE CODE END Is this possible? And if I am not making myself clear don't hesitate to tell me so. [Edited by - kentylarsson on November 29, 2005 8:20:51 PM]
This is a stolen signature, if you want it back some money needs to be exchanged!
Advertisement
Not sure if it will help but you might want to investigate the SuspendLayout and ResumeLayout functions ie

this.SuspendLayout();
//create and add controls to this using your for loops
this.ResumeLayout(false);
Probably not the smoothest method but you could create an array of Buttons or an ArrayList and then use Controls.AddRange to add it to the controls list after your done creating them all.

Liyon
Thanks for you answer! Unfortunately I need to stick with Compact Framework 1.1, which makes those two methods unavailable. Otherwise it would have worked.

Anyone else who has any idea?

[edit] LiyonDR: No it's not available using the CF 1.1 either. :(

[edit2]

I found out about Control.CopyTo() and used it instead without any improvement.

[Edited by - kentylarsson on November 30, 2005 1:57:56 AM]
This is a stolen signature, if you want it back some money needs to be exchanged!
public FormClassName()
{
// This is the constructor of "public class FromClassName : System.Windows.Forms.Form"

//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//

// BEGIN: I would like everything inside the for-loops to turn up "at once"
for (int j = 0 ; j <
sorry about that previous post - not sure what happened there.

try setting b.Visible = false before this.Controls.Add(b)

then add this code at the end:

foreach( Control ctl in this.Controls )
{
ctl.Visible = true;
}


this way all controls are added to the form invisible then shown together at the end, hope this helps.
Quote:Original post by kentylarsson
Thanks for you answer! Unfortunately I need to stick with Compact Framework 1.1, which makes those two methods unavailable. Otherwise it would have worked.

Anyone else who has any idea?

[edit] LiyonDR: No it's not available using the CF 1.1 either. :(

[edit2]

I found out about Control.CopyTo() and used it instead without any improvement.


Perhaps you should learn to RTFM, because SuspendLayout and ResumeLayout are part of the .NET framework 1.1. I've seen it many times in the Auto generated code, and I check the MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscontrolclasssuspendlayouttopic.asp

That link, will indeed tell you that SuspendLayout/ResumeLayout are part of the .NET 1.1 framework.

Toolmaker

Quote:Original post by Toolmaker
Quote:Original post by kentylarsson
Thanks for you answer! Unfortunately I need to stick with Compact Framework 1.1, which makes those two methods unavailable. Otherwise it would have worked.

Anyone else who has any idea?

[edit] LiyonDR: No it's not available using the CF 1.1 either. :(

[edit2]

I found out about Control.CopyTo() and used it instead without any improvement.


Perhaps you should learn to RTFM, because SuspendLayout and ResumeLayout are part of the .NET framework 1.1. I've seen it many times in the Auto generated code, and I check the MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscontrolclasssuspendlayouttopic.asp

That link, will indeed tell you that SuspendLayout/ResumeLayout are part of the .NET 1.1 framework.

Toolmaker


Thanks for your hilarious answer Toolmaker! You managed to be both unhelpful, unfriendly and most of all incompetent. And all at the same time!

If you tell someone else to RTFM you should at least be able to read it yourself, and be able to correctly read the topic you're replying to.

1. The question was about .NET Compact Framework 1.1, it even said so in your quote of my post.
2. SuspendLayout and ResumeLayout are not part of .NET Compact Framework 1.1. The methods which are availible in CF 1.1 are marked so under the method name in the list. Look in MSDN for confirmation: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWindowsFormsControlMethodsTopic.asp

Anonymous Poster
I'll try your suggestion later today, I hope that it will solve my problem but I am doubtful. Thanks for you answer!
This is a stolen signature, if you want it back some money needs to be exchanged!

This topic is closed to new replies.

Advertisement