在ZedGraph窗格中,可以将CurveItem
设置为“已选中”。
zedGraphControl.GraphPane.CurveList[0].IsSelected = true;
zedGraphControl.Refresh();
就我所见,这会将其颜色更改为Color.Gray
。
是否可以更改此选择状态颜色?
答案 0 :(得分:4)
我不知道这样的属性,但您可以通过手动覆盖ZedGraphControl的MouseClick事件并设置“选定的”CurveItem的颜色来完成此操作,如:
private void zedGraphControl1_MouseClick(object sender, MouseEventArgs e)
{
foreach (var curve in zedGraphControl1.GraphPane.CurveList)
{
curve.Color = Color.Black;
}
CurveItem nearestItem;
int nearestPoint;
zedGraphControl1.GraphPane.FindNearestPoint(e.Location, out nearestItem, out nearestPoint);
if (nearestItem != null)
{
nearestItem.Color = Color.Red;
}
zedGraphControl1.Refresh();
}
更新:查看http://www.opensourcejavaphp.net/csharp/zedgraph/Line.cs.html和http://www.opensourcejavaphp.net/csharp/zedgraph/Selection.cs.html的源代码,看起来Line.DrawCurve正在使用静态属性Selection.Line。如果不修改源代码,就很难改变这种行为。
Line.cs的一部分:
public void DrawCurve( Graphics g, GraphPane pane, CurveItem curve, float scaleFactor )
{
Line source = this;
if ( curve.IsSelected )
source = Selection.Line;
Selection.cs:
/// The <see cref="Line" /> type to be used for drawing "selected"
/// <see cref="LineItem" /> and <see cref="StickItem" /> types
/// </summary>
public static Line Line = new Line( Color.Gray );
答案 1 :(得分:0)
所选行是静态属性,但不是只读的。可以通过重置Selection.Line属性来更改格式:
public Form1()
{
InitializeComponent();
ZedGraph.Selection.Line.Width = 3;
ZedGraph.Selection.Line.Color = Color.Red;
...
}
重置选择线后,所有选定的线条将按指定绘制。