Shortcut array

How to create tag array with Microsoft Visual C # Express Edition? Is there a way to do this with a graphical editor (drag'n'drop), or do I need to manually add it to the automatically generated code?

+4
source share
4 answers

You need to manually add it. But do not add it to the automatically generated code, as it can be overwritten by the designer of Visual Studio.

I would add it to the Load event handler for the form. The code might look like this:

Label[] labels = new Label[10]; labels[0] = new Label(); labels[0].Text = "blablabla"; labels[0].Location = new System.Drawing.Point(100, 100); ... labels[9] = new Label(); ... 

PS. Your task is a little unusual for me. What do you want to do? There may be better ways to accomplish your task.

+13
source

You can add labels to the form using a graphical editor, and then add them to the array in the upload form.

 Label[] _Labels = new Label[3]; private void MyForm_Load(object sender, EventArgs e) { _Labels[0] = this.Label1; _Labels[1] = this.Label2; _Labels[2] = this.Label3; } 

This will make it easier to set up your location. You might also consider using FlowLayoutPanel if you are dynamically creating labels (or any control really).

+6
source
 Label[ , ] _arr = new Label[4 , 4]; private void Form1_Load(object sender, EventArgs e) { for(int i=0;i<4;i++){ for(int j=0;j<4;j++){ _arr[i ,j] = new Label(); _arr[i ,j].Text = ""+i+","+j; _arr[i ,j].Size = new Size(50,50); _arr[i ,j].Location = new Point(j*50,i*50); //you can set other property here like Border or else this.Controls.Add(_arr[i ,j]); } } } 

if you want to install Border of Label in C #, perhaps you should check out http://msdn.microsoft.com/en-us/library/system.windows.forms.label.aspx

The shortcut has the Border property. Please check this out. Thanks

0
source
 int i=0; ControlNum=10; Label[] lblExample= new Label[]; for(i=0;i<ControlNum;i++) { lblExample[i] = new Label(); lblExample[i].ID="lblName"+i; //lblName0,lblName1,lblName2.... Form1.Controls.Add(lblExample[i]); } 

xD ...

Joshit0 ..

0
source

Source: https://habr.com/ru/post/1285871/


All Articles