我試圖在文本框中放置一個標籤。不過,我在標籤在文本框中正確定位時遇到了一些麻煩。我可以在文本框中顯示它,但那是我出現問題的地方。當我嘗試放置標籤時,它看起來不能正常工作。我有下面的代碼片段到TextBox的構造函數中添加標籤:TextBox ClientRectangle,DisplayRectangle或Bounds爲什麼不返回顯示大小?
Label lblClear = new Label();
lblClear.Text = "X";
lblClear.Font = this.Font;
lblClear.Location = new Point(this.DisplayRectangle.X + (this.DisplayRectangle.Width - 15), this.Bounds.Y);
lblClear.Size = new Size(15, 15);
this.Controls.Add(lblClear);
然而,這並沒有把它所有的方式到文本框的右邊,因爲我期待,而是在中間某個地方的文本框。爲什麼ClientRectangle,DisplayRectangle或Bound沒有返回文本框的大小,因爲我認爲它應該?底層的texbox矩形實際上比屏幕上顯示的小嗎?
任何幫助表示讚賞。謝謝。
編輯:這就是我講的截圖:
這裏是I類有:
public class SearchTextBox : TextBox
{
public SearchTextBox()
{
InitializeComponent();
Label lblClear = new Label();
lblClear.Text = "X";
lblClear.Font = this.Font;
lblClear.Location = new Point(this.DisplayRectangle.X + (this.DisplayRectangle.Width - 15), this.Bounds.Y);
lblClear.Size = new Size(15, 15);
this.Controls.Add(lblClear);
}
}
編輯:我得到了它的工作,但是這隻有當我從我的表格中刪除文本框並重新添加它時,纔會產生影響...
這看起來比在表單上放置的標準文本框寬**。 –