Pawulon

I have putted 36 Labels on Form, unfortunately it dosen't display properly I can see how those labels are drawn. I'm using Double Buffere. Here is a code that shows my problem:

Code Snippet

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace Testowa
{

class Form1:Form
{

public Form1()
{

// here I turn on Double Buffering

this.DoubleBuffered = true;

// here I make Labels

int x = 0, y;
for ( x=0 ; x<6 ; x++ )
for (y = 0; y < 6; y++)
{
Label l = new Label();
l.Top = 40 * y;
l.Left = 40 * x;
l.Width = 40;
l.Height = 40;
l.Text = String.Format("({0} ; {1})", x, y);
l.Visible = true;
this.Controls.Add(l);
}

}


static void Main(string[] args)

{

Application.Run(new Form1());

}

}

}

I would like to gek know how to improve it.



Re: Windows Forms General Problem with displaying many Controls.

nobugz

Make it fly like this:

public partial class Form1 : Form {
public Form1() {
InitializeComponent();
this.Paint += Form1_Paint;
}
private void Form1_Paint(object sender, PaintEventArgs e) {
for (int x = 0; x < 6; x++)
for (int y = 0; y < 6; y++) {
string txt = String.Format("({0} ; {1})", x, y);
e.Graphics.DrawString(txt, this.Font, Brushes.Black, 40 * x, 40 * y);
}
}
}





Re: Windows Forms General Problem with displaying many Controls.

Pawulon

Unfortunately it dosen't solve my problem because code I send only demonstrate it. If I would need only to display controls noboguz solution will work but what if I would like to add some events to those controls.



Re: Windows Forms General Problem with displaying many Controls.

nobugz

What kind of events Labels don't have a lot of interesting events other than Click. Form has Click too.





Re: Windows Forms General Problem with displaying many Controls.

Pawulon

I agree that there aren't many events for Label but I don't want to display only Labels. I used them as an example of my problem.





Re: Windows Forms General Problem with displaying many Controls.

nobugz

You should have given a better example. Stop wasting our time please.