- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章asp.net DoDragDrop 方法的使用由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
在类库中的定义为: 。
复制代码代码如下
[UIPermissionAttribute(SecurityAction.Demand, Clipboard = UIPermissionClipboard.OwnClipboard)] public DragDropEffects DoDragDrop( Object data, DragDropEffects allowedEffects ) 。
其中data参数为要拖放的数据,如果拖动操作需要于另一个进程的应用程序相互操作,data代表的数据应该是基本托管类(String,BitMap,或MetaFile),或者是实现 ISerializable 或IDataObject的对象。 allowedEffects参数表示拖放的效果,为一个枚举值(DragDropEffects).返回值也为DragDropEffects枚举值。 当开始调用DoDragDrop方法拖动一个数据对象时,DoDragDrops在拖放过程中,检测当前光标位置下的控件是不是有效的放置目标。如果当前光标下的控件是有效的放置目标,则GiveFeedBack事件以指定的拖放效果引发。在检测当前位置光标是否为有效的拖放目标时,DoDragDrops方法同时跟踪光标位置,键盘状态和鼠标状态的更改。 (1)如果用于移出了一个窗口,则引发DragLeave事件。 (2)如果移入了另外一个控件,则引发该控件的DragEnter事件。 (3)如果鼠标移动,但是停留在一个控件中,则引发DragOver事件。 如果检测到更改了键盘或者鼠标状态,则引发拖放源的QueryContinueDrag事件, 并根据事件的QueryContinueDragEventArgs的Action属性值确定继续拖动,放置数据或取消操作。 (1)如果Action属性指定为Continue,则将引发DragOver事件。 (2)如果Action属性指定为Drop,则将放置效果返回给源,以便应用程序对数据进行适当的操作;例如,如果是移动操作,则剪切数据。 (3)如果是DragAction的值为Cancel,则引发DragLeave事件 从csdn上摘抄一段示例代码: 下面的代码示例演示在两个 ListBox 控件之间的拖放操作。当拖动动作启动时,该示例调用 DoDragDrop 方法。在 MouseDown 事件期间,如果从鼠标位置起鼠标移动的距离大于 SystemInformation..::.DragSize,则启动拖动动作。IndexFromPoint 方法用于确定在 MouseDown 事件期间要拖动的项的索引。 该示例还演示如何对拖放操作使用自定义光标。该示例要求应用程序目录中存在两个光标文件:3dwarro.cur 和 3dwno.cur,分别用于自定义拖动光标和禁止停放光标。如果选中 UseCustomCursorsCheckCheckBox,则使用自定义光标。自定义光标在 GiveFeedback 事件处理程序中设置。 键盘状态在右 ListBox 的 DragOver 事件处理程序中计算,以确定基于 Shift、Ctrl、Alt 或 Ctrl+Alt 键的状态将发生哪种拖动操作。放置动作在 ListBox 中发生的位置也在 DragOver 事件期间确定。如果要放置的数据不是 String,则 DragDropEffects 中将把 DragEventArgs.sEffect 设置为 None。最后,停放状态在 DropLocationLabelLabel 中显示。 要放置的用于右 ListBox 的数据在 DragDrop 事件处理程序中确定,并且在 ListBox 中的适当位置添加该 String 值。如果拖动操作移动到窗体边框的外面,则 QueryContinueDrag 事件处理程序中将取消拖放操作 。
复制代码代码如下
using System; using System.Drawing; using System.Windows.Forms; namespace Snip_DragNDrop { public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.ListBox ListDragSource; private System.Windows.Forms.ListBox ListDragTarget; private System.Windows.Forms.CheckBox UseCustomCursorsCheck; private System.Windows.Forms.Label DropLocationLabel; private int indexOfItemUnderMouseToDrag; private int indexOfItemUnderMouseToDrop; private Rectangle dragBoxFromMouseDown; private Point screenOffset; private Cursor MyNoDropCursor; private Cursor MyNormalCursor; /// The main entry point for the application. [STAThread] static void Main() { Application.Run(new Form1()); } public Form1() { this.ListDragSource = new System.Windows.Forms.ListBox(); this.ListDragTarget = new System.Windows.Forms.ListBox(); this.UseCustomCursorsCheck = new System.Windows.Forms.CheckBox(); this.DropLocationLabel = new System.Windows.Forms.Label(); this.SuspendLayout(); // ListDragSource this.ListDragSource.Items.AddRange(new object[] {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"}); this.ListDragSource.Location = new System.Drawing.Point(10, 17); this.ListDragSource.Size = new System.Drawing.Size(120, 225); this.ListDragSource.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ListDragSource_MouseDown); this.ListDragSource.QueryContinueDrag += new System.Windows.Forms.QueryContinueDragEventHandler(this.ListDragSource_QueryContinueDrag); this.ListDragSource.MouseUp += new System.Windows.Forms.MouseEventHandler(this.ListDragSource_MouseUp); this.ListDragSource.MouseMove += new System.Windows.Forms.MouseEventHandler(this.ListDragSource_MouseMove); this.ListDragSource.GiveFeedback += new System.Windows.Forms.GiveFeedbackEventHandler(this.ListDragSource_GiveFeedback); // ListDragTarget this.ListDragTarget.AllowDrop = true; this.ListDragTarget.Location = new System.Drawing.Point(154, 17); this.ListDragTarget.Size = new System.Drawing.Size(120, 225); this.ListDragTarget.DragOver += new System.Windows.Forms.DragEventHandler(this.ListDragTarget_DragOver); this.ListDragTarget.DragDrop += new System.Windows.Forms.DragEventHandler(this.ListDragTarget_DragDrop); this.ListDragTarget.DragEnter += new System.Windows.Forms.DragEventHandler(this.ListDragTarget_DragEnter); this.ListDragTarget.DragLeave += new System.EventHandler(this.ListDragTarget_DragLeave); // UseCustomCursorsCheck this.UseCustomCursorsCheck.Location = new System.Drawing.Point(10, 243); this.UseCustomCursorsCheck.Size = new System.Drawing.Size(137, 24); this.UseCustomCursorsCheck.Text = "Use Custom Cursors"; // DropLocationLabel this.DropLocationLabel.Location = new System.Drawing.Point(154, 245); this.DropLocationLabel.Size = new System.Drawing.Size(137, 24); this.DropLocationLabel.Text = "None"; // Form1 this.ClientSize = new System.Drawing.Size(292, 270); this.Controls.AddRange(new System.Windows.Forms.Control[] {this.ListDragSource, this.ListDragTarget, this.UseCustomCursorsCheck, this.DropLocationLabel}); this.Text = "drag-and-drop Example"; this.ResumeLayout(false); } private void ListDragSource_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { // Get the index of the item the mouse is below. indexOfItemUnderMouseToDrag = ListDragSource.IndexFromPoint(e.X, e.Y); if (indexOfItemUnderMouseToDrag != ListBox.NoMatches) { // Remember the point where the mouse down occurred. The DragSize indicates // the size that the mouse can move before a drag event should be started. Size dragSize = SystemInformation.DragSize; // Create a rectangle using the DragSize, with the mouse position being // at the center of the rectangle. dragBoxFromMouseDown = new Rectangle(new Point(e.X - (dragSize.Width /2), e.Y - (dragSize.Height /2)), dragSize); } else // Reset the rectangle if the mouse is not over an item in the ListBox. dragBoxFromMouseDown = Rectangle.Empty; } private void ListDragSource_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { // Reset the drag rectangle when the mouse button is raised. dragBoxFromMouseDown = Rectangle.Empty; } private void ListDragSource_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if ((e.Button & MouseButtons.Left) == MouseButtons.Left) { // If the mouse moves outside the rectangle, start the drag. if (dragBoxFromMouseDown != Rectangle.Empty && !dragBoxFromMouseDown.Contains(e.X, e.Y)) { // Create custom cursors for the drag-and-drop operation. try { MyNormalCursor = new Cursor("3dwarro.cur"); MyNoDropCursor = new Cursor("3dwno.cur"); } catch { // An error occurred while attempting to load the cursors, so use // standard cursors. UseCustomCursorsCheck.Checked = false; }finally { // The screenOffset is used to account for any desktop bands // that may be at the top or left side of the screen when // determining when to cancel the drag drop operation. screenOffset = SystemInformation.WorkingArea.Location; // Proceed with the drag-and-drop, passing in the list item. DragDropEffects dropEffect = ListDragSource.DoDragDrop(ListDragSource.Items[indexOfItemUnderMouseToDrag], DragDropEffects.All | DragDropEffects.Link); // If the drag operation was a move then remove the item. if (dropEffect == DragDropEffects.Move) { ListDragSource.Items.RemoveAt(indexOfItemUnderMouseToDrag); // Selects the previous item in the list as long as the list has an item. if (indexOfItemUnderMouseToDrag > 0) ListDragSource.SelectedIndex = indexOfItemUnderMouseToDrag -1; else if (ListDragSource.Items.Count > 0) // Selects the first item. ListDragSource.SelectedIndex =0; } // Dispose of the cursors since they are no longer needed. if (MyNormalCursor != null) MyNormalCursor.Dispose(); if (MyNoDropCursor != null) MyNoDropCursor.Dispose(); } } } } private void ListDragSource_GiveFeedback(object sender, System.Windows.Forms.GiveFeedbackEventArgs e) { // Use custom cursors if the check box is checked. if (UseCustomCursorsCheck.Checked) { // Sets the custom cursor based upon the effect. e.UseDefaultCursors = false; if ((e.Effect & DragDropEffects.Move) == DragDropEffects.Move) Cursor.Current = MyNormalCursor; else Cursor.Current = MyNoDropCursor; } } private void ListDragTarget_DragOver(object sender, System.Windows.Forms.DragEventArgs e) { // Determine whether string data exists in the drop data. If not, then // the drop effect reflects that the drop cannot occur. if (!e.Data.GetDataPresent(typeof(System.String))) { e.Effect = DragDropEffects.None; DropLocationLabel.Text = "None - no string data."; return; } // Set the effect based upon the KeyState. if ((e.KeyState & (8+32)) == (8+32) && (e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) { // KeyState 8 + 32 = CTL + ALT // Link drag-and-drop effect. e.Effect = DragDropEffects.Link; } else if ((e.KeyState & 32) == 32 && (e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) { // ALT KeyState for link. e.Effect = DragDropEffects.Link; } else if ((e.KeyState & 4) == 4 && (e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) { // SHIFT KeyState for move. e.Effect = DragDropEffects.Move; } else if ((e.KeyState & 8) == 8 && (e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) { // CTL KeyState for copy. e.Effect = DragDropEffects.Copy; } else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) { // By default, the drop action should be move, if allowed. e.Effect = DragDropEffects.Move; } else e.Effect = DragDropEffects.None; // Get the index of the item the mouse is below. // The mouse locations are relative to the screen, so they must be // converted to client coordinates. indexOfItemUnderMouseToDrop = ListDragTarget.IndexFromPoint(ListDragTarget.PointToClient(new Point(e.X, e.Y))); // Updates the label text. if (indexOfItemUnderMouseToDrop != ListBox.NoMatches){ DropLocationLabel.Text = "Drops before item #" + (indexOfItemUnderMouseToDrop + 1); } else DropLocationLabel.Text = "Drops at the end."; } private void ListDragTarget_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) { // Ensure that the list item index is contained in the data. if (e.Data.GetDataPresent(typeof(System.String))) { Object item = (object)e.Data.GetData(typeof(System.String)); // Perform drag-and-drop, depending upon the effect. if (e.Effect == DragDropEffects.Copy || e.Effect == DragDropEffects.Move) { // Insert the item. if (indexOfItemUnderMouseToDrop != ListBox.NoMatches) ListDragTarget.Items.Insert(indexOfItemUnderMouseToDrop, item); else ListDragTarget.Items.Add(item); } } // Reset the label text. DropLocationLabel.Text = "None"; } private void ListDragSource_QueryContinueDrag(object sender, System.Windows.Forms.QueryContinueDragEventArgs e) { // Cancel the drag if the mouse moves off the form. ListBox lb = sender as ListBox; if (lb != null) { Form f = lb.FindForm(); // Cancel the drag if the mouse moves off the form. The screenOffset // takes into account any desktop bands that may be at the top or left // side of the screen. if (((Control.MousePosition.X - screenOffset.X) < f.DesktopBounds.Left) || ((Control.MousePosition.X - screenOffset.X) > f.DesktopBounds.Right) || ((Control.MousePosition.Y - screenOffset.Y) < f.DesktopBounds.Top) || ((Control.MousePosition.Y - screenOffset.Y) > f.DesktopBounds.Bottom)) { e.Action = DragAction.Cancel; } } } private void ListDragTarget_DragEnter(object sender, System.Windows.Forms.DragEventArgs e) { // Reset the label text. DropLocationLabel.Text = "None"; } private void ListDragTarget_DragLeave(object sender, System.EventArgs e) { // Reset the label text. DropLocationLabel.Text = "None"; } } } 。
对用这种拖放操作和微软的服务,容器模式的关系,留在以后再学习.
最后此篇关于asp.net DoDragDrop 方法的使用的文章就讲到这里了,如果你想了解更多关于asp.net DoDragDrop 方法的使用的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我试图对 ASP.Net MVC 有一个高层次的理解,我开始意识到它看起来很像原始的 ASP 脚本。过去,我们将“模型”/业务逻辑代码组织到 VBScript 类或 VB COM 组件中。 当然,现在
我已经搜索了一段时间,但似乎找不到答案。 我想在我的旋转木马中显示一个计数器,左边是当前项目(工作),左边是项目总数。 我的代码:
. 最佳答案 Scott Gu 称这些为代码块。这就是我的看法。 http://weblogs.asp.net/scottgu/archive/2010/04/06/new-lt-gt-syntax
我有一个使用 Visual Studio 2010/.net 4/VB 制作的网站。 我真的很喜欢我发现的 FAQ 系统的布局,因为它很简单,但它是经典的 asp。所以,显然,我不能包括我的母版页布局
好吧,对于你们许多人来说,这个问题可能有一个非常明显的答案,但它让我难住了。 我有一个 asp.net Web 表单,上面有两个控件(嗯,不止这两个,但我们将重点关注这些) - 第一个是 asp:dr
当我将 ASP.NET 复选框控件设置为 asp.net 更新面板的异步回发触发器时,EventName 属性是什么? 最佳答案 我相信它是 CheckedChanged。 关于asp.net - a
我有一个用经典 asp 编写的(巨大的)网站。现在我必须切换到 vb.net (razor)。有没有办法将这两个结合起来直到切换完成? 有没有办法让应用程序与经典的 asp 和 vb.net 一起工作
I am creating a products page, where the user selects an option in a radiobuttonlist for example, an
我最近将一个经典的 ASP 应用程序转换为 ASP.NET 3.5,但我觉得我的经典 ASP 版本要快一些(我不知道可能买家会后悔)。 所以你们能帮我解决这个问题吗,让我知道哪个更快,asp、asp.
从本周开始,我被要求开始学习如何使用 ASP 开发网站。我通过 XNA 对 C# 有一定的经验,所以这部分对我来说并不是什么麻烦。 我一直在关注Music Store Tutorial这需要我设置一个
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 8 年前。 Improve this ques
我想将一些表单变量发布到经典 ASP 页面中。我不想改变经典的 ASP 页面,因为需要完成大量的工作,以及消耗它们的页面数量。 经典的 ASP 页面需要将表单变量 Username 和 Userpas
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
在某种程度上,这可能是一个异端问题。我们有一个大型站点,其中许多页面仍在ASP中。通常,并没有真正动态的,而是包括(通过SSI或Server.Execute)定期重新生成的HTML块。看起来好像是一个
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 9 年前。 Improve this ques
我有一个遗留的 ASP 应用程序——在不久的某个时候——需要迁移到 ASP.Net 2.0(以与也在 2.0 中的其他应用程序兼容)。 对于这类事情是否有最佳实践,即作为第一步将当前 html、vbs
我目前在一家公司工作,该公司使用 ASP.NET Webforms 和旧 ASP 页面的组合进行 Web 开发。这对于他们当前的项目来说效果很好,但我想说服/建议他们切换到 ASP.NET MVC,因
我有一个经典的 asp 应用程序。我想将该页面的竞赛表格发布到 Asp.Net 表格。原因是我想在进入数据库之前使用我在 Asp.Net 页面中内置的大量逻辑进行验证,而我对 asp 不太了解。更不用
我知道在 ASP.NET MVC 中,您可以拥有移动 View 并执行类似 Index.mobile.cshtml 的操作。和 _Layout.mobile.cshtml并且服务器知道将这些 View
我需要从一些服务器端 c#.net 代码中调用经典 asp 页面上的 VBscript 函数 - 有谁知道一种干净的方法来做到这一点?在 .net 中重写函数不是一种选择。 我会再解释一下这个问题..
我是一名优秀的程序员,十分优秀!