如何使用Microsoft Visual C#Express Edition創建標籤數組?有辦法用圖形(drag'n'drop)編輯器來做到這一點,或者我必須手動將它添加到自動生成的代碼?Array of Labels
回答
您必須手動添加它。但是不要將它添加到自動生成的代碼中,因爲它可以被Visual Studio設計器覆蓋。
我會將它添加到窗體的Load事件處理程序中。代碼可能如下所示:
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。你的任務對我來說似乎有點不尋常。您想做什麼?也許有更好的方法來完成你的任務。
由於被覆蓋......我做的圖靈機模擬器。這些標籤將代表磁帶的一部分 – dpetek 2009-06-07 18:27:07
您可以使用GUI編輯器將標籤添加到表單中,然後將這些標籤添加到表單加載中的數組中。
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;
}
這將至少使設置的位置更容易。如果您是動態創建標籤(或者真的是任何控件),您也可以考慮使用FlowLayoutPanel。
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]);
}
}
}
如果你想設置在C#標籤的邊境
也許你應該檢查 http://msdn.microsoft.com/en-us/library/system.windows.forms.label.aspx
標籤有屬性稱爲邊界。請檢查一下。由於
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 ..
您正在爲Label []聲明行使用錯誤的括號。這段代碼不會編譯。 – 2014-01-06 22:39:49
- 1. Array of Array to Json
- 2. C#Array of Classes
- 3. 'Array of arrays'in matlab?
- 4. Array of STD_LOGIC_VECTOR
- 5. Array of Objects - Swift
- 6. Persist Array of Swift
- 7. Java Array of countries
- 8. Array of CvScalars
- 9. android java array of paint
- 10. Java Array of Linked Lists
- 11. PL/pgSQL Array of Rows
- 12. 在python'List of lists'格式中遍歷'JSON Array of Array''
- 13. Array of Objects過濾器angular2
- 14. KnockoutJS - Observable Array of Observable objects
- 15. make(array of)actionlistener(s)change value
- 16. Javascript Promises - get Array of non rejected
- 17. Dynamic Array of Static Arrays的問題
- 18. JUnit Mockito when ... then from array of objects
- 19. Sorting a Array of Objects throws long [] error
- 20. Java:如何檢查「Array of Array」是否爲空/空?
- 21. 如何在$ .when完成處理程序時使_each處理'array'和'array of array'
- 22. Nasm錯誤; undefined labels
- 23. spplot上的country-labels()
- 24. Array of Array,根據索引處數組的內容刪除一個索引?
- 25. 如何讓ggplot標籤同時使用labels = abs和labels =逗號?
- 26. NameError:未定義名稱'labels'
- 27. scala foreach of 2-D List/Array in chisel with types issue
- 28. 在Array of Objects中查找最接近的日期/時間
- 29. ArrayBuffer of Array + =未按預期方式工作
- 30. 隨機設置UIButton的Image by Array of Images
生成的代碼永遠不會改變什麼:你的修改會由設計師 – 2009-06-07 18:29:58