如何在窗口控件上使用wpf中的DoDragDrop [英] how to use DoDragDrop in wpf on window control
本文介绍了如何在窗口控件上使用wpf中的DoDragDrop的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在wpf中有一个图片框。
代码是..
I have a picture box in wpf.
code is ..
<DockPanel Height="237">
<WindowsFormsHost Height="237">
<wf:PictureBox x:Name="LiveImage" MouseDown="LiveImage_MouseDown"/>
</WindowsFormsHost>
</DockPanel>
private void LiveImage_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (IsCropFrame)
{
try
{
CropPicture = new PictureBox();
CropPicture.CreateControl();
CropPicture.Width = 132;
CropPicture.Height = 170;
CropPicture.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
cropPen = new System.Drawing.Pen(System.Drawing.Color.Blue, 1);
LiveImage.CreateGraphics().DrawRectangle(cropPen, cropX, cropY, 132, 170);
IsCropFrame = false;
CropPicture.MouseDown += new System.Windows.Forms.MouseEventHandler(CropPicture_MouseDown);
CropPicture.MouseMove += new System.Windows.Forms.MouseEventHandler(CropPicture_MouseMove);
CropPicture.MouseUp += new System.Windows.Forms.MouseEventHandler(CropPicture_MouseUp);
//if (e.Button == MouseButtons.Left)
//{
// //var dragImage = new Bitmap((Bitmap)picBox.Image, picBox.Size);
// var dragImage = (Bitmap)CropPicture.Image;
// IntPtr icon = dragImage.GetHicon();
// // Cursor.Current = new Cursor(icon);
// DoDragDrop(CropPicture.Image, DragDropEffects.Copy);
// SystemDLL.User32.DestroyIcon(CropPicture);
//}
}
catch (Exception ex)
{
}
}
else
{
}
}>
private void CropPicture_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
dragging = true;
dragPoint = new System.Drawing.Point(e.X, e.Y);
}
private void CropPicture_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (dragging)
CropPicture.Location = new System.Drawing.Point(CropPicture.Location.X + e.X - dragPoint.X, CropPicture.Location.Y + e.Y - dragPoint.Y);
}
private void CropPicture_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
dragging = false;
}
没有发生CropPicture框的鼠标事件。
现在我想在LiveImage图片框的另一个地方拖动一个CropPicture框。
None of mouse events of CropPicture box is occurred.
Now I want to drag a CropPicture box in another place of LiveImage picture box.
推荐答案
尝试以下链接: -
在WPF中拖放 [ ^ ] < br $>
拖动和WPF中的内容 - 第二部分 [ ^ ]
Try below links :-
Drag and Drop in WPF[^]
Drag and Drop in WPF - Part II[^]
这篇关于如何在窗口控件上使用wpf中的DoDragDrop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文