winform自定义控件的问题,急,马上揭帖
我想写个控件,页面放个pictureBox和label
不知道怎么重写那个拖动的事件,因为pictureBox和label占满了页面,那个mouseup事件被挡住了
怎么写拖动pic和label就是拖动userControl1,高手说下,急用!
[解决办法]
顶一个先,
那你就在mouseup事件方法中,再注册一个事件,对UserControl1的,不知道我说的对不对。。
[解决办法]
实现DoDrag,DropDrag(印象)
[解决办法]
学习中,....
[解决办法]
LZ阐述问题不是很清除,按照我的理解,我写了个测试用的用户控件,该(UserControl1)控件里面包含一个Dock属性为Fill的PictureBox,这样,pic控件就全部覆盖了usercontrol,此控件主要功能为:用户可以在外部拖拽一个图像文件进USerControl,当成功后把改图像文件的图片设置为pic控件的背景图,源代码如下:
UserControl1.cs:
- C# code
using System;using System.Collections.Generic;using System.ComponentModel;using System.Drawing;using System.Data;using System.Text;using System.Windows.Forms;using System.IO;namespace Common{ public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); } private void UserControl1_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop))//表示此时为文件拖拽 e.Effect = DragDropEffects.Copy; } private void UserControl1_DragDrop(object sender, DragEventArgs e) { string fileName = ((string[])e.Data.GetData(DataFormats.FileDrop))[0]; try { Image image = Image.FromFile(fileName); this.pictureBox1.Image = image; } catch { MessageBox.Show("当前拖拽的文件不是有效的图像文件"); return; } } }}
[解决办法]
事件过滤,
由这两个事件,触发U控件的事件.
[解决办法]
楼主再说明白一点吧。
[解决办法]
[Quote=引用:]
- C# code
using System;using System.Collections.Generic;using System.ComponentModel;using System.Drawing;using System.Data;using System.Text;using System.Windows.Forms;using System.IO;namespace Common{ public partial class UserControl1 : UserControl { public UserControl1() { InitializeComponent(); } private void UserControl1_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop))//表示此时为文件拖拽 e.Effect = DragDropEffects.Copy; } private void UserControl1_DragDrop(object sender, DragEventArgs e) { string fileName = ((string[])e.Data.GetData(DataFormats.FileDrop))[0]; try { Image image = Image.FromFile(fileName); this.pictureBox1.Image = image; } catch { MessageBox.Show("当前拖拽的文件不是有效的图像文件"); return; } } }}