简体   繁体   English

如何用鼠标移动C#表格图例?

[英]How to move C# form legend with mouse?

I am creating a plotting program and I was wondering how to move a chart's legend with the mouse? 我正在创建一个绘图程序,我想知道如何用鼠标移动图表的图例? So you would click on the legend and then you could move it anywhere inside the chart area. 因此,您可以单击图例,然后将其移动到图表区域内的任何位置。

Using manual double-buffering of the chart, draw the legend at the current mouse position (perhaps + (15,15)) on the back-buffer just prior to drawing the back buffer to the screen. 使用图表的手动双缓冲,在将后缓冲区绘制到屏幕之前,在后缓冲区上的当前鼠标位置(也许+(15,15))绘制图例。 You can also set an Alpha to make the legend semi-transparent until the user drops it. 您还可以设置Alpha,以使图例变为半透明,直到用户将其删除为止。

You can create a little form without borders to build your legend or use a ToolTip item. 您可以创建一个无边界的小表格来构建图例或使用工具提示项。 Then you could move with mouseMove event: 然后,您可以使用mouseMove事件移动:

    private void frmMain_MouseMove(object sender, MouseEventArgs e)
    {
        if (e.Button = System.Windows.Forms.MouseButtons.Left)
            ChangeLegendPosition(e.X, e.Y);
    }

Where ChangeLegendPosition is your function that updates your form/tooltip position. 其中ChangeLegendPosition是您的函数,用于更新表单/工具提示位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM