在應用程序中有時用戶希望將數據從一個控件中拖到另一個控件中此時就需要用到拖放技術
程序開發步驟
()新建一個窗體在窗體中添加兩個Label控件和兩個TextBox控件並將兩個TextBox控件分別命名為txtDataTart和txtScoure
()將txtDataTart文本框的AllowDrop屬性設置為true
()程序主要代碼如下
private void txtDataTart_DragDrop(object sender DragEventArgs e)
{
txtDataTartText = eDataGetData(DataFormatsText)ToString();
}
private void txtDataTart_DragEnter(object sender DragEventArgs e)
{
eEffect = DragDropEffectsCopy;
}
private void txtScoure_MouseMove(object sender MouseEventArgs e)
{
if ((eButton & MouseButtonsLeft) == MouseButtonsLeft)
{
string reportPath = ApplicationStartupPathSubstring( ApplicationStartupPathSubstring(
ApplicationStartupPathLastIndexOf())LastIndexOf());
reportPath += @sldwarrocur;
MyNoDropCursor = new Cursor(reportPath);
DragDropEffects dropEffect = thistxtScoureDoDragDrop(thistxtScoureText DragDropEffectsCopy | DragDropEffectsLink);
} }
From:http://tw.wingwit.com/Article/program/net/201311/13614.html