我正在尝试在ZedGraph上设置图例的字体大小。但是,大小从来没有出现在我设置的位置。
这个值从何而来?我已经检查了我的代码(我从其他人手中接管了项目,这是一个大项目,所以很难找到它),并在ZedGraph对象的其他地方查找某种缩放项,但找不到如何设置此值。它是以某种方式自动计算的吗?
我也在网上找过答案,但一无所获。
发布于 2015-10-09 20:56:47
这是Size的设置器:
set
{
if ( value != _size )
{
Remake( _scaledSize / _size * value, _size, ref _scaledSize,
ref _font );
_size = value;
}
}
//...
/// <summary>
/// Recreate the font based on a new scaled size. The font
/// will only be recreated if the scaled size has changed by
/// at least 0.1 points.
/// </summary>
/// <param name="scaleFactor">
/// The scaling factor to be used for rendering objects. This is calculated and
/// passed down by the parent <see cref="GraphPane"/> object using the
/// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
/// font sizes, etc. according to the actual size of the graph.
/// </param>
/// <param name="size">The unscaled size of the font, in points</param>
/// <param name="scaledSize">The scaled size of the font, in points</param>
/// <param name="font">A reference to the <see cref="Font"/> object</param>
private void Remake( float scaleFactor, float size, ref float scaledSize, ref Font font )
{
float newSize = size * scaleFactor;
float oldSize = ( font == null ) ? 0.0f : font.Size;
// Regenerate the font only if the size has changed significantly
if ( font == null ||
Math.Abs( newSize - oldSize ) > 0.1 ||
font.Name != this.Family ||
font.Bold != _isBold ||
font.Italic != _isItalic ||
font.Underline != _isUnderline )
{
FontStyle style = FontStyle.Regular;
style = ( _isBold ? FontStyle.Bold : style ) |
( _isItalic ? FontStyle.Italic : style ) |
( _isUnderline ? FontStyle.Underline : style );
scaledSize = size * (float)scaleFactor;
font = new Font( _family, scaledSize, style, GraphicsUnit.World );
}
}有趣的代码行是:
scaledSize = size * (float)scaleFactor;
font = new Font( _family, scaledSize, style, GraphicsUnit.World );这意味着您的大小是使用PaneBase.CalcScaleFactor缩放的。你应该看看这最后一个
发布于 2015-10-09 21:46:46
ZedGraph会根据窗格的大小自动缩放所有字体。
这是通过GraphPane.IsFontScaled属性控制的。将其设置为false,您的字体应保持您设置的大小。
https://stackoverflow.com/questions/33038582
复制相似问题