0
對於任何能夠幫助我的人,我都會非常感激!將圖形添加到運行時創建的組件
我有一個非常小的應用程序,它在運行時用LOOP創建了幾個面板。目前要創建的面板的數量來自輸入到文本框中的值,但最終將由從數據庫中讀取的整數確定。
每個面板都有一個標籤,它創建在同一個循環中
我的問題是,我想畫120行中的各個面板,因爲它創建(在for循環每次迭代),而我這樣做有嵌套WHILE循環
我可以得到的一切工作很好,面板正在創建標籤標題,但出於某種原因,我無法繪製線條
這是所有測試的一種方法,任何人都可以幫助我嗎?
我目前擁有的代碼如下:
public void CreatePanels()
{
int PanelPosX = 50;
int PanelPosY = 500;
int LabelPosX = 10;
int LabelPosY = 10;
for (int i = 0; i < (Convert.ToInt32(textBox2.Text)); i++)
{
Panel pnlOverview = new Panel();
pnlOverview.Name = "InspectorPanel" + i.ToString();
pnlOverview.Text = "Inspector Panel " + i.ToString();
pnlOverview.Location = new Point(PanelPosX, PanelPosY);
pnlOverview.Size = new Size(974, 136);
pnlOverview.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
Controls.Add(pnlOverview);
PanelPosY += 170;
Label lblInspectorName = new Label();
lblInspectorName.Name = "InspectorName" + i.ToString();
lblInspectorName.Text = " Inspector " + i.ToString();
lblInspectorName.Width = 100;
lblInspectorName.Height = 13;
lblInspectorName.Location = new Point(LabelPosX, LabelPosY);
lblInspectorName.Size = new Size(974, 136);
pnlOverview.Controls.Add(lblInspectorName);
// Draw the Overview Chart
int x = 10;
int y = 0;
Pen OVTable = new Pen(Color.Black, 0);
while (y < 120)
{
Graphics mp = pnlOverview.CreateGraphics();
mp.DrawLine(OVTable, x, 40, x, 100);
y++;
x += 8;
}
}
return;
}
感謝 伊萬