[英]Width of C# Label before it is shown?
我需要知道AutoSize = true;
標簽將具有哪個寬度AutoSize = true;
在顯示表單之前,我可以相對於標簽放置其他控件。 實際上我只能訪問父控件的表單。
(無需Designer即可完全工作。這意味着只需代碼。)
(在Graphics中測量字符串不可靠,所以我不能使用它。)
Label label = new Label();
label.AutoSize = true;
label.Location = new Point(x, y);
label.Text = "hello world";
myParent.Controls.Add(label);
// more control generation follows, THEN form is shown
好的,您無法在將標簽寬度添加到其父控件之前獲得標簽寬度。 只需將位置放在Controls.Add之后
Label label = new Label();
label.AutoSize = true;
label.Text = "hello world";
myParent.Controls.Add(label);
label.Left = cntControl1.Left - label.Width;
label.Top = cntControl1.Top;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.