我在Panel中加了好多控件,当程序运行起来后,如何设置能让我移动或者改变Panel内部控件的位置、大小,就像在设计的时候那样可以随意的用鼠标移动、改变大小,而不是通过输入数据改变~~~~就像设计时DesignMode=false时那样,那位高手指教一下!!多谢~

解决方案 »

  1.   

    可以自己从Panel中继承下,判断当鼠标移动到此Panel的边沿时,根据其位置将鼠标的光标改为箭头状。在OnMouseMove的过程中,修改Panel的大小就可以老
      

  2.   

    mousedown mousemove mouseup
    这三个事件里面写代码就行了。很简单的。
      

  3.   

    可以用WIN32API实现using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;using System.Runtime.InteropServices;  namespace testRunningDrag
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        public const int WM_SYSCOMMAND = 0x0112;
            public const int SC_MOVE = 0xF010;
            public const int HTCAPTION = 0x0002;
            [DllImport("user32.dll", EntryPoint = "SendMessageA")]
            private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
            [DllImport("user32.dll")]
            private static extern int ReleaseCapture();           private void pic1_MouseDown(object sender, MouseEventArgs e)
            {
                ReleaseCapture();
                SendMessage(pic1.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);   
            }
        }
    }
      

  4.   

    这个东西使用DesignHost对象比较方便,实际上vs本身的设计器就是用的这个东西你可以看看这个系列的文章
    http://panjiwen.cnblogs.com/archive/2005/10/archive/2005/10/10/251689.htmlps:实际微软也提供了DesignHost方面的demo,有两个版本net1.1和net2.0的(记不得名字了,自己找一下把)
      

  5.   

    楼上贴的没来得及细看,直接添加控件好像不行,回头再仔细研究研究下面是用事件实现的代码,你再加上鼠标图标变化和更好的鼠标定位处理应该也可以,希望对你有用:using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;using System.Runtime.InteropServices;  namespace testRunningDrag
    {
        public partial class Form1 : Form
        {
            bool AreaChange = false;
            Control moveCtrl;        public Form1()
            {
                InitializeComponent();
            }        public const int WM_SYSCOMMAND = 0x0112;
            public const int SC_MOVE = 0xF010;
            public const int HTCAPTION = 0x0002;
            [DllImport("user32.dll", EntryPoint = "SendMessageA")]
            private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
            [DllImport("user32.dll")]
            private static extern int ReleaseCapture();           private void pic1_MouseDown(object sender, MouseEventArgs e)
            {
                ReleaseCapture();
                SendMessage(pic1.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
            }        private void Form1_MouseMove(object sender, MouseEventArgs e)
            {
                if (this.AreaChange == true)
                {
                    moveCtrl.Width = e.X-pic1.Left;
                    moveCtrl.Height = e.Y-pic1.Top;
                }
            }        private void Form1_MouseDown(object sender, MouseEventArgs e)
            {
                //label1.Text = string.Format("{0},{1}     {2},{3}", e.X.ToString(), e.Y.ToString(), pic1.Left + pic1.Width, pic1.Top + pic1.Height);
                if (e.X - pic1.Left - pic1.Width < 10 && e.Y - pic1.Top - pic1.Height < 10)
                {
                    AreaChange = true;
                    moveCtrl = pic1;
                }
            }        private void Form1_MouseUp(object sender, MouseEventArgs e)
            {
                AreaChange = false;
            }
        }
    }
      

  6.   

    找了一下,微软的几个demo地址
    http://www.myfirm.cn/news/DotNetUserInterface/20080221013104408.html
      

  7.   

    to 7F:
    这仅仅是实现拖动,这个应该没有问题,想实现可以动态改变大小~~~to 8F:
    确实想要此种效果,但是看Demo发现其框架基本就是一个类似Vs的,用在我这好像大材小用~~不过确实很有用,得仔细研究一下~~我再考虑是否可以组合控制一下,在选择每个控件后,增加8个小Picturebox分布在Control周围,控制一下mouse显示,实现更改大小,不知道这样如何??不知道那位达人还有更好的办法??
    我觉得这个问题肯定有很多人遇到过,比如设计打印模板时就需要动态更改设计变量的为止等等~~~