【问题标题】:Reset Mouse First Click When Zooming in MSCharts放大 MSCharts 时重置鼠标首次单击
【发布时间】:2012-08-22 02:01:08
【问题描述】:

我在我的 winform 中使用 MSCharts 来显示一些图表。 我设置了图表,以便用户可以缩放:

chart1.ChartAreas[0].CursorX.IsUserEnabled = true;
chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;

我还使用 MouseDown 事件和 Call Hit 测试方法在图表中向下钻取并显示其他图表信息。 :

private void chart1_MouseDown(object sender, MouseEventArgs e)
{
  //***** Call Hit Test Method
  HitTestResult result = chart1.HitTest(e.X, e.Y);
  if (result.ChartElementType == ChartElementType.DataPoint || result.ChartElementType == ChartElementType.DataPointLabel)
   {
   //*************************Goes into the Pie Chart - Dept
      int z = result.PointIndex;
      result.Series.XValueType = ChartValueType.DateTime;
      DateTime x = DateTime.FromOADate(result.Series.Points[z].XValue);
      string name = result.Series.Name.ToString();
      name = name + "(" + x.ToShortDateString() + ")";
      if (funChartExists(name) == false)
      {       
         subMakeNewPieSeries(result.Series.Name.ToString(), x, name);
      }
      chart1.ChartAreas["Pie"].Visible = true;
      chart1.ChartAreas["Task"].Visible = false;
      chart1.ChartAreas["Default"].Visible = false;
      chart1.Series[name].Enabled = true;
      chart1.Legends[0].Enabled = false;
      chart1.ChartAreas["Default"].RecalculateAxesScale();
   }
   chart1.Invalidate();
}

我还有一个将图表重置为第一个视图的按钮:

private void cmbReset_Click(object sender, EventArgs e)
{
    chart1.ChartAreas["Pie"].Visible = false;
    chart1.ChartAreas["Task"].Visible = false;
    chart1.ChartAreas["Default"].Visible = true;
    chart1.Legends[0].Enabled = true;
    for (int x = 0; x < chart1.Series.Count; x++)
    {
        if (chart1.Series[x].ChartArea == "Pie" || chart1.Series[x].ChartArea == "Task")
        {
            chart1.Series[x].Enabled = false;
        }
    }
    chart1.ChartAreas["Default"].RecalculateAxesScale();
    chart1.Invalidate();        
}

我的问题是当我返回主图表(使用重置按钮)时,图表保留了第一次向下钻取时的鼠标单击,并等待第二次单击(或鼠标向上)放大。所以当您移动鼠标时,它正在拖动一个深灰色的背景选择,等待第二个缩放点。

有没有办法重置鼠标选择缩放值,或者在我进行命中测试时将其关闭,然后在重置后重新打开?

【问题讨论】:

    标签: c# mouse zooming reset mschart


    【解决方案1】:

    首先,我们什么时候应该使用鼠标向下,什么时候应该使用鼠标向上?

    当操作是按钮向下并以按钮向上结束的序列的一部分时,应使用鼠标向下。

    当操作是单一性质(“点击”)时,应使用鼠标上键。

    你应该使用向下还是向上? up 功能是否正常,是否解决了您的问题?

    作为一般经验法则(有时会被天真的程序员忽略),鼠标按下 + 鼠标移动 + 鼠标向上操作具有以下形式:

    MouseDown
        Capture the mouse
    
    MouseMove
        If MouseIsCaptured
            Perform move operation
    
    MouseUp
        If MouseIsCaptured
            Release capture and finalize the operation
    

    如果图表控件遵循此过程,您的解决方案可能就像自己释放鼠标捕获一样简单。这应该是chartControlInstance.Capture = false

    【讨论】:

    • 我将 Hit Test Method 移至 Mouse Up 事件,这似乎符合我的要求。它看到 MouseUp 位置与鼠标向下位于同一位置并且不缩放,然后获取鼠标位置以向下钻取到其他图表。我尝试了 chartControlInstance.Capture = false,但这似乎对我的缩放问题没有任何帮助。
    • @JohnMamberg 我注意到您的 MouseDown 方法是一个事件处理程序。要中断图表控件的向下+移动+向上操作,您可以尝试在自己的类中派生它,然后使用 OnMouseDown 覆盖而不是事件。这将允许您首先调用基类实现,然后尝试释放鼠标捕获。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-20
    相关资源
    最近更新 更多