0
我在VisulaStudio中有標籤問題。 我使用的VisualStudio版本是2012.標籤列表不顯示在圖片框中
問題是,我需要顯示一個網格並標出這些行。我編寫的代碼與類似問題here的解決方案完全相同。它不會給我任何編譯器錯誤,但標籤仍然不會顯示在pictureBox中。
private void aResize()
{
Size clientSize = this.ClientSize;
int hToDraw, wToDraw;
hToDraw = clientSize.Height - 2 * marginOfTab;
wToDraw = clientSize.Width - 2 * marginOfTab;
tabControl1.Size = new Size(wToDraw, hToDraw);
piB1.Size = new Size(wToDraw, hToDraw);
piB1.Image = new Bitmap(piB1.Size.Width, piB1.Size.Height);
using (Graphics g = Graphics.FromImage(piB1.Image))
{
g.FillRectangle(new SolidBrush(Color.LightGray), 0, 0, W, H);
Pen gridPen = new Pen(Color.White, 1f);
int hDrawingStep = hToDraw/10 -1;
int wDrawingStep = wToDraw/10 -1;
for (int local = 1; local < 11; local++)
{
g.DrawLine(gridPen, 0, hDrawingStep*local, wToDraw, hDrawingStep*local); //horizontal axix
g.DrawLine(gridPen, wDrawingStep*local, 0, wDrawingStep*local , hToDraw); //vertical axis
Label localLabel = new Label();
localLabel.Name = "la" + local;
localLabel.Visible = true;
localLabel.Text = (local*100).ToString();
localLabel.Location = new Point((int)local*hDrawingStep, (int)10);
labelList.Add(localLabel);
}
}
}
所有未在上面的代碼中聲明的變量都在前面聲明。我不想粘貼太多。感謝您的任何建議。
什麼'labelList'?你只需將標籤添加到'labelList'中,那麼它們怎麼會顯示在你的pictureBox上呢? –
@King Kong labelList是一個'List
對於那些將來閱讀這個問題的人來說@King Kong的答案完美無缺,但是我的代碼還有另一個失敗。您還需要指定標籤的.Size參數。 – Lukasz