2014-01-29 51 views
1

我怎樣才能阻止Windows(7/8)從滾動(觸摸事件?)的InfragisticsUltraGrid當用戶的鼠標左鍵向下,移動?這種行爲搞亂了我的Dragdrop事件。防止電網下來

我使用UltraGrid來接收和啓動拖動。當用戶點擊網格中的一個項目時,我將一個變量leftButton設置爲true,以防止將項目放在自身上。我正在使用MouseLeaveElement從網格內啓動DoDragDropDragDrop

代碼如下。它的工作在Windows XP中,但在Windows 7失敗,8 mainGrid_MouseLeaveElement鼠標左鍵被釋放時,現在被稱爲,這就是後期,因爲那個時候的阻力應該已經完成​​。它看起來像Windows操作系統正在接管,當鼠標左鍵和鼠標正在移動。當釋放鼠標按鈕時,它將它釋放回應用程序。

private leftMouseDown = false; 

public void Fill(ToolbarForm ownerForm, DocumentOwner owner, int? ownerIdentifier) 
{ 
    ... 
    this.mainGrid.DragDrop += new DragEventHandler(grid_DragDrop); 
    this.mainGrid.DragEnter += new DragEventHandler(grid_DragEnter); 
    this.mainGrid.MouseDown += new MouseEventHandler(mainGrid_MouseDown); 
    this.mainGrid.MouseUp += new MouseEventHandler(mainGrid_MouseUp); 
    this.mainGrid.MouseLeaveElement += new Infragistics.Win.UIElementEventHandler(mainGrid_MouseLeaveElement); 
    ... 
} 

void mainGrid_MouseLeaveElement(object sender, Infragistics.Win.UIElementEventArgs e) 
{ 
    if (leftMouseDown) 
    { 
     ... 
     DataObject data = new DataObject(); 
     data.SetFileDropList(files); 
     this.mainGrid.DoDragDrop(data, DragDropEffects.Copy); 
     leftMouseDown = false; 
    } 
} 

void mainGrid_MouseUp(object sender, MouseEventArgs e) 
{ 
    if (e.Button == System.Windows.Forms.MouseButtons.Left) 
     leftMouseDown = false; 
} 

void mainGrid_MouseDown(object sender, MouseEventArgs e) 
{ 
    if (e.Button == System.Windows.Forms.MouseButtons.Left) 
     leftMouseDown = true; 
} 

public void grid_DragDrop(object sender, DragEventArgs e) 
{ 
    string[] filenames = (string[])e.Data.GetData(DataFormats.FileDrop); 

    foreach (string filename in filenames) 
    { 
     this.AddDocument(filename); 
    } 
} 

private void grid_DragEnter(object sender, DragEventArgs e) 
{ 
    if (e.Data.GetDataPresent(DataFormats.FileDrop, false) && !leftMouseDown) 
    { 
     e.Effect = DragDropEffects.All; 
    } 

    else e.Effect = DragDropEffects.None; 
} 

回答

1

通過使用maingrid而不是MouseLeaveElement的SelectionDrag事件解決了此問題。

void maingrid_SelectionDrag(object sender, Infragistics.Win.UIElementEventArgs e) 
{ 
    if (leftMouseDown) 
    { 
     ... 
     DataObject data = new DataObject(); 
     data.SetFileDropList(files); 
     this.mainGrid.DoDragDrop(data, DragDropEffects.Copy); 
     leftMouseDown = false; 
    } 
} 

代替

void mainGrid_MouseLeaveElement(object sender, Infragistics.Win.UIElementEventArgs e) 
{ 
    if (leftMouseDown) 
    { 
     ... 
     DataObject data = new DataObject(); 
     data.SetFileDropList(files); 
     this.mainGrid.DoDragDrop(data, DragDropEffects.Copy); 
     leftMouseDown = false; 
    } 
} 
+0

您可以發佈示例代碼和標記問題的回答? –