【发布时间】:2011-01-27 22:07:52
【问题描述】:
在我的 C# WinForms 应用程序中,我使用拖放将项目从 TreeView 控件移动到 Chart 控件。 (这是一个带有作业列表的计划应用程序,用户将它们放到计划中)。当用户将一个项目放到图表上的现有数据点上时,我希望新项目成为一个数据点并取代旧项目(在队列中向下移动)。
以下是我所拥有的 DragDrop 事件处理程序,它不完全(但几乎)工作:
private void chart1_DragDrop(object sender, DragEventArgs e)
{
if (draggedJob != null) // This is set when user starts dragging
{
HitTestResult testResult = chart1.HitTest(e.X, e.Y, ChartElementType.DataPoint);
switch (testResult.ChartElementType)
{
case ChartElementType.DataPoint:
// This should happen if I dropped an item onto an existing DataPoint
// ...but testResult.ChartElementType is always "Nothing"
DataPoint existingPoint = (DataPoint)testResult.Object;
JobOrder jobToDisplace = (JobOrder)existingPoint.Tag;
ScheduleJob(draggedJob, jobToDisplace);
break;
default:
//This happens every time (it adds the item to the end of the schedule)
ScheduleJob(draggedJob);
break;
}
RefreshTreeView();
RefreshChart();
draggedJob = null;
}
}
谁能拯救我的理智并帮助我弄清楚如何判断用户将工作放到哪个 DataPoint 上?
【问题讨论】:
标签: c# winforms drag-and-drop charts