熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

C#拖放技術的典型應用

2022-06-13   來源: .NET編程 

  在應用程序中有時用戶希望將數據從一個控件中拖到另一個控件中此時就需要用到拖放技術

  程序開發步驟

  ()新建一個窗體在窗體中添加兩個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
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.