2014-04-01 218 views
0

我希望我的控件在拖動時顯示在屏幕上。在屏幕上繪製位圖

private void flowLayoutPanel1_DragEnter(object sender, DragEventArgs e) 
{ 
    FlowLayoutPanel _destination = (FlowLayoutPanel)sender; 
    e.Effect = _destination.Controls.GetChildIndex(_destination.GetChildAtPoint(_destination.PointToClient(new Point(e.X, e.Y)))) >= 0 ? DragDropEffects.Move : DragDropEffects.None; 


    foreach (Control control in flowLayoutPanel1.Controls) 
    { 
     List <Bitmap> controlsImgs = new List<Bitmap>(); 
     Rectangle controlsRect = new Rectangle(e.X,e.Y,control.Width,control.Height); 
     Bitmap b = new Bitmap(control.Width, control.Height); 
     control.DrawToBitmap(b, new Rectangle(0, 0, b.Width, b.Height)); 
     controlsImgs.Add(b); 

    } 

    for (int i = 0; i < controlsImgs.Count; i++) 
    { 
     //TODO 
    } 
} 

這裏是我有什麼,我有一個FlowLayoutPanel,在那裏你可以拖放一些控件這是面板,在我的foreach語句我想每個控制轉換成位圖圖像,所以拖動時,在DragEnter事件,我可以顯示控件的截圖。我認爲我做的是正確的,首先定義了一張Bitmap圖像列表,然後用控件寬度和高度創建了一個新的位圖,然後將該位圖添加到我的controlsImgs列表中。現在在我的for循環中,我必須在屏幕上繪製每個控件圖像。怎麼做 ?該控件的位置與鼠標位置相同,意味着e的位置。

回答

0

使用Control.DrawToBitmap。 (請參閱示例here。)

要設置新光標,請使用GiveFeedback事件。做:

e.UseDefaultCursors = false; 
Cursor.Current = MyCursor; 
+0

我需要我的控制被繪製在光標下,這可能嗎? –