0

我有一个文本,为了强调它,我想将背景绘制为矩形。

我如何尝试这样做是:

string curEdgePhrase = "Cur edge:";
SizeF curEdgePhraseSize = e.Graphics.MeasureString(curEdgePhrase, SystemFonts.DefaultFont);
string curEdgeValue = ((int)m_ImageStatForCurSelectedRegion.GetEdginess()).ToString();
SizeF curEdgeValueSize = e.Graphics.MeasureString(curEdgeValue, SystemFonts.DefaultFont);

string maxEdgePhrase = "Max edge:";
SizeF maxEdgePhraseSize = e.Graphics.MeasureString(maxEdgePhrase, SystemFonts.DefaultFont);
string maxEdgeValue = ((int)m_ImageStatForCurSelectedRegion_MaxValues.GetEdginess()).ToString();
SizeF maxEdgeValueSize = e.Graphics.MeasureString(maxEdgeValue, SystemFonts.DefaultFont);

SizeF fullValuesArea = new SizeF(curEdgePhraseSize.Width + curEdgeValueSize.Width /*Width*/,
    curEdgePhraseSize.Height + maxEdgePhraseSize.Height /*Height*/);

///***Draw statistic background rectangle***
Point statisticBackgroundRectStartPoint = new Point(10, 10);
Rectangle statisticBackground = new Rectangle(statisticBackgroundRectStartPoint, fullValuesArea.ToSize());

e.Graphics.DrawRectangle(DrawBorderStatisticBackground, statisticBackground);
e.Graphics.FillRectangle(BrushWhiteSmoke, statisticBackground);

所以,我正在测量短语 + 值的长度和宽度,并尝试将其设置为我的矩形的大小

结果我得到了这样的东西

在此处输入图像描述

你看到这个Cur词后面的灰色矩形了吗?这是一个结果...

但我真正需要的是

在此处输入图像描述

但是,如果我通过硬编码大小,我会得到这个结果..

我究竟做错了什么?

4

0 回答 0