2012-10-03 31 views
2

自定義UserControl ChartControlShelf包含TableLayoutPanel帶有3個子控件,所有類型Panel。兒童沒有EventHandlers。Windows.Forms DragLeave事件意外觸發

ShelfContainer將所有事件處理器的用戶控件ChartControlShelf

ChartControlShelf chartControlShelf = new ChartControlShelf(); 
chartControlShelf.DragOver+=new DragEventHandler(chartControlShelf_DragOver); 
chartControlShelf.DragLeave+=new EventHandler(chartControlShelf_DragLeave); 

....

private void chartControlShelf_DragOver(object sender, DragEventArgs e) { 

     ChartControlShelf chartControlShelf = (ChartControlShelf)sender; 

     if (chartControlShelf.panelControlShelf.PointToClient(Cursor.Position).Y < chartControlShelf.tlpChartControlShelf.Size.Height/2) { 
      chartControlShelf.panelInsertTop.BackColor = CustomColorsColors.DragEnter; 
      chartControlShelf.panelInsertBottom.BackColor = CustomColorsColors.DragLeave; 
     } 
     else { 
      chartControlShelf.panelInsertBottom.BackColor = CustomColorsColors.DragEnter; 
      chartControlShelf.panelInsertTop.BackColor = CustomColorsColors.DragLeave; 
     } 
    } 

    private void chartControlShelf_DragLeave(object sender, EventArgs e) { 
     ChartControlShelf chartControlShelf = (ChartControlShelf)sender; 
     chartControlShelf.panelInsertTop.BackColor = CustomColorsColors.DragLeave; 
     chartControlShelf.panelInsertBottom.BackColor = CustomColorsColors.DragLeave; 

    } 

爲什麼* chartControlShelf_DragLeave *燒我的鼠標離開ChartControlShelf用戶控件以前

回答

4

鼠標光標「屬於」指針下方直接可見的控件。聽起來很奇怪,當光標「進入」ChartControlShelf中的一個控件時,它也會「離開」ChartControlSelf。

+2

我有一個類似的問題,你的回答指出我在正確的方向。對我來說,解決方案是在除了主控件之外的所有控件上將屬性AllowDrop設置爲false。 –