我创建了一个小型Windows窗体测试应用程序来尝试一些拖放代码.该表单由三个PictureBoxes组成.我的目的是从一个PictureBox中抓取一张图片,在拖动操作期间将其显示为自定义光标,然后将其放在另一个PictureBox目标上.
只要它们在同一个表单上,这从一个PictureBox到另一个PictureBox就可以正常工作.
如果我打开同一个应用程序的两个实例并尝试在它们之间拖放,我会收到以下神秘错误:
此远程处理代理没有通道接收器,这意味着服务器没有正在侦听的已注册服务器通道,或者此应用程序没有合适的客户端通道与服务器通信.
但是,出于某种原因,它可以拖放到Wordpad(但不是MS Word或画笔).
三个PictureBoxes将它们的事件连接起来如下:
foreach (Control pbx in this.Controls) {
if (pbx is PictureBox) {
pbx.AllowDrop = true;
pbx.MouseDown += new MouseEventHandler(pictureBox_MouseDown);
pbx.GiveFeedback += new GiveFeedbackEventHandler(pictureBox_GiveFeedback);
pbx.DragEnter += new DragEventHandler(pictureBox_DragEnter);
pbx.DragDrop += new DragEventHandler(pictureBox_DragDrop);
}
}
Run Code Online (Sandbox Code Playgroud)
然后是这样的四个事件:
void pictureBox_MouseDown(object sender, MouseEventArgs e) {
int width = (sender as PictureBox).Image.Width;
int height = (sender as PictureBox).Image.Height;
Bitmap bmp = new Bitmap(width, height);
Graphics g = Graphics.FromImage(bmp);
g.DrawImage((sender as PictureBox).Image, 0, 0, width, height);
g.Dispose();
cursorCreatedFromControlBitmap = CustomCursors.CreateFormCursor(bmp, …Run Code Online (Sandbox Code Playgroud) 这个问题接近我感兴趣的问题,但并不完全.
我有一个用C#编写的.NET WinForms应用程序.我有一个ListView显示C#对象数组的控件.我已将它连接起来,以便您可以将这些listview项拖放到同一应用程序中的不同表单,并将对象数组(类型Session)正确传递给该另一个表单的drop handler.
但是,我现在想要支持跨进程拖放,我运行应用程序的多个实例.这看起来它将起作用(例如GetDataPresent成功),但最终在我实际尝试检索数据时抛出异常 - 无法转换object[]为Session[].
if (e.Data.GetDataPresent("Fiddler.Session[]"))
{
Session[] oDroppedSessions;
try
{
oDroppedSessions = (Session[])e.Data.GetData("Fiddler.Session[]");
}
catch (Exception eX)
{ // reaches here
}
}
Run Code Online (Sandbox Code Playgroud)
任何人都知道我是否必须ISerializable为我的对象实现才能使其工作?通常情况下,我只是尝试一下,但实现ISerializable这个课程将是非常重要的,我担心这样做可能会产生奇怪的副作用.
更新:实现ISerializable没有帮助 - 永远不会调用该方法.同样,将Serializable属性添加到类中也没有任何影响.还有其他想法吗?