我想在TextBox
以下顯示ToolTip
消息,但也希望它們右對齊。如何在C中對齊控件和工具提示消息的右邊緣#
我能夠將ToolTip消息定位在文本框的右邊緣,所以我試圖通過消息長度移動留言。
所以我試圖通過使用TextRenderer.MeasureText()來獲得字符串長度,但是位置有點偏離,如下所示。
private void button1_Click(object sender, EventArgs e)
{
ToolTip myToolTip = new ToolTip();
string test = "This is a test string.";
int textWidth = TextRenderer.MeasureText(test, SystemFonts.DefaultFont, textBox1.Size, TextFormatFlags.LeftAndRightPadding).Width;
int toolTipTextPosition_X = textBox1.Size.Width - textWidth;
myToolTip.Show(test, textBox1, toolTipTextPosition_X, textBox1.Size.Height);
}
我試圖在MeasureText()函數不同的標誌,但它並沒有幫助,而且由於工具提示消息具有填充,我去TextFormatFlags.LeftAndRightPadding。
需要明確的是,這是我想達到的目標:
嘗試用myToolTip.Font替換SystemFonts.DefaultFont。 – Graffito
@Graffito:沒有這樣的事情。當擁有者繪製工具提示時,可以決定使用哪個字體。 – TaW
對不起,字體只在ToolTip.Draw事件中可用(OwnerDraw = true)。 – Graffito