我确定这个问题有一个简单的解决方案,我不知道,但我会问无论如何。我有这样的代码:当锚点关闭时,C#图线注释消失轴查看
HorizontalLineAnnotation h = new HorizontalLineAnnotation();
h.AnchorX = startOfNewGraph;
h.Width = newGraphWidth;
h.AxisX = resultGraph.ChartAreas[0].AxisX;
h.AxisY = resultGraph.ChartAreas[0].AxisY;
h.IsSizeAlwaysRelative = false;
h.ClipToChartArea = resultGraph.ChartAreas[0].Name;
originalHLAAnchors.Add(h.AnchorX);
originalHLAWidths.Add(h.Width);
resultGraph.Annotations.Add(h);
我的问题是,当我的图形视图缩放到其AnchorX是视图外的注释消失。我希望保持这种状态,以便即使注释的末尾都不在视图中,我仍然可以看到它们之间的界限。这里就是我试图做补救:
private void resultGraph_AxisViewChanged(object sender, ViewEventArgs e)
{
if (e.Axis == resultGraph.ChartAreas[0].AxisX)
{
ResizeHorizontalAnnotations();
}
}
private void ResizeHorizontalAnnotations()
{
int count = 0;
for (int i = 0; i < resultGraph.Annotations.Count; i++)
{
if (resultGraph.Annotations[i] is HorizontalLineAnnotation)
{
if (originalHLAAnchors[count] < resultGraph.ChartAreas[0].AxisX.ScaleView.ViewMinimum)
{
resultGraph.Annotations[i].AnchorX = resultGraph.ChartAreas[0].AxisX.ScaleView.ViewMinimum + 0.0005;
if ((originalHLAAnchors[count] + originalHLAWidths[count]) >= resultGraph.ChartAreas[0].AxisX.ScaleView.ViewMaximum)
{
resultGraph.Annotations[i].Width = resultGraph.ChartAreas[0].AxisX.ScaleView.ViewMaximum - resultGraph.ChartAreas[0].AxisX.ScaleView.ViewMinimum;
}
else
{
resultGraph.Annotations[i].Width -= resultGraph.ChartAreas[0].AxisX.ScaleView.ViewMinimum - originalHLAAnchors[count];
}
}
else
{
resultGraph.Annotations[i].AnchorX = originalHLAAnchors[count];
resultGraph.Annotations[i].Width = originalHLAWidths[count];
}
resultGraph.Annotations[i].Visible = true;
count++;
}
}
resultGraph.UpdateAnnotations();
}
然而,这段代码似乎并没有擦出火花。注释没有显示,当我第一次尝试时,所以我加了0.005到AnchorX,看它是否必须稍微超过视图。这也没有用。当我检查注释的本地值时,数字是正确的。注释只是无法正确显示或完全显示。 UpdateAnnotations()缩小视图并禁用我的注释。
任何想法?
我终于回到现在,你的第一句话就是答案。我所需要做的就是将值设置为X而不是AnchorX,即使在X不可见的情况下它也能正常工作。知道这是简单的事情! – cl12