在应用程序中有时用户希望将数据从一个控件中拖到另一个控件中此时就需要用到拖放技术
程序开发步骤
()新建一个窗体在窗体中添加两个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);
}}