How do I get SizeScreenCoors when I set the Size of Annotation to Automatic?
Posted: Tue Dec 12, 2023 8:55 am
Now SizeScreenCoords is always an incorrect value。
A place for LightningChart Ultimate related Q&A's.
https://lightningchart.com/forum/
Code: Select all
AnnotationXY annotation = new AnnotationXY(ChartView.ViewXY, ChartView.ViewXY.XAxes[1], ChartView.ViewXY.YAxes[1])
{
Style = AnnotationStyle.Rectangle,
LocationCoordinateSystem = CoordinateSystem.RelativeCoordinatesToTarget,
BorderVisible = false,
AllowDragging = false,
AllowResize = false,
AllowRotate = false,
AllowTargetMove = false,
AllowAnchorAdjust = false,
AllowUserInteraction = false,
Anchor = new PointDoubleXY(0, 1),
AutoSizePadding = 2,
ArrowStyleBegin = ArrowStyle.None,
ArrowStyleEnd = ArrowStyle.None,
Behind = true,
KeepVisible = false,
Visible = false,
Sizing = AnnotationXYSizing.Automatic
};
Code: Select all
AnnotationXY annotation = ChartView.ViewXY.Annotations[0];
var annotationWidth = annotation.SizeScreenCoords.Width;
var annotationHeight = annotation.SizeScreenCoords.Height;
Code: Select all
float fMaxWidth = 0;
float fMaxHeight = 0;
string[] aContent = annotation.Text.Split('\n');
for (int i = 0; i < aContent.Length; i++)
{
var point = _chart.MeasureTextPX(aContent[i], annotation.TextStyle.Font);
if (fMaxWidth < point.X)
fMaxWidth = point.X;
fMaxHeight += point.Y;
}
size = new Size(fMaxWidth + 2 * annotation.AutoSizePadding, fMaxHeight + 35);