首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 培训 数据库 书店 程序员
中国软件网
欢迎您:游客 | 登录 注册 帮助
  • 请问,我想做个像编程设计器那样的东东,可以创建控件,创建后还可以移动该控件,该怎么做呢?
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • chaojitanke
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    • 揭帖率:
    发表于:2008-08-09 10:09:27 楼主
    我想做的是,比如在窗体一侧有Button、label、textbox等控件,可以拖动其到窗体指定范围生成新控件,并且通过鼠标、键盘移动新生成控件的位置。
    现在创建控件我知道怎么做,移动指定控件也知道怎么做,但不知道我创建后的控件该怎么移动?
    主要是移动控件要知道是要移动哪个控件,比如Button1,可以通过设置其Top,Left属性移动。但是,程序运行后生成的控件,我怎么设定其属性?
    我该怎么捕捉移动的是哪个控件,并设置其属性呢?
    怎么实现类似设计器中的用鼠标多选控件并移动其位置的功能(用鼠标和键盘控制)?
    哦,还有,移动button可以用e.Data.GetData(typeof(Button))来知道移动的是哪个button,用e.Data.GetData(typeof(Label))知道移动的是哪个label
    但当button、label、textbox等都存在窗体中时,我怎么知道移动的是哪个控件?
    我邮箱chaojitanke2003@yahoo.com.cn,哪位大侠有源码麻烦给发下哈
    100  修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • HW_zxc_010
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-08-09 10:13:221楼 得分:0
    up
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • jiazhuoyang
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-08-09 10:15:192楼 得分:0
    使用skinfeature界面换肤组件啊。 完全支持c#的。界面精致,而且效果很棒!! 而且基本不需要编写代码就能实现播放器界面。
    www.skinfeature.com
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • chaojitanke
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-08-09 10:40:033楼 得分:0
    我现在知道如何得知移动的是什么类型的控件了。声明个公共type类型的数据,然后在移动控件时先给该数据赋值就好了
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • greateast
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-08-18 15:17:004楼 得分:0
    正在关于这个方面。希望可以探讨
    greateast2006@gmail.com
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • lwz1983
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-08-18 15:58:175楼 得分:0
     顶
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • BillMhw
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-08-23 14:20:236楼 得分:0
    有点难度,帮顶
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • skinfeature
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-08-23 14:20:327楼 得分:0
    http://www.skinfeature.com
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • csharp_start
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-08-23 15:30:568楼 得分:0
    http://blog.csdn.net/csharp_start/archive/2008/08/21/2806959.aspx
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • csharp_start
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-08-23 15:35:509楼 得分:0
    直接用FORM的话,不是很容易作到,通常,我们都采用创建一个容器(当然这个容器也可以是FORM),在容器中定义一个
    选中的控件集合,你在拖动鼠标范围的时候,会有一个矩形范围,这个范围与控件所在位置的重叠区域可以判断是哪些控件在刚才鼠标拖动的范围内,这个时候,你就要在数组中加入这些控件,并绘制他们被选中时的8个选择点.
    移动的时候,遍历这个数组,来达到所有选择控件的移动,缩放同理.如果是用键盘控制,判断键盘消息,操作比较类似.
    对齐的操作与移动比较相似,无非是找一个对齐基点,这个基点可以是第一个被选中的控件,也可以是最后一个.
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • kingcsx666
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-08-23 16:15:2510楼 得分:0
    up,难啊
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • ASP_lover
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-08-23 16:17:3611楼 得分:0
    该回复于2008-08-24 00:21:39被版主删除
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • thinkc
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-08-23 17:48:2912楼 得分:0
    sharpdevelop.net/OpenSource/SD/
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • syc958
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-08-23 17:53:0413楼 得分:0
    基本上没有什么用!
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • yankun1024
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-08-26 22:01:3214楼 得分:0
    建议参考WORD的自动化对象开发
    做个像vs2005一样的东东吧
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • yankun1024
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-08-26 22:02:1615楼 得分:0
    MSDN杂志上有一篇关于这个内容的文章
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • slin60
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-08-26 22:44:0716楼 得分:0
    这个功能你在.net中做是选对了,在.net中,通过应用框架包中现成的功能,可以很容易的实现你所需要的东西。
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • ProjectDD
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-08-27 00:32:4217楼 得分:0
    UP
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • KnowDotNet
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-08-27 00:33:3218楼 得分:0
    shapdevlop
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • haonanzhao
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-08-27 12:08:4619楼 得分:0
    很简单哦。
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • Feiin
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-08-27 12:20:0620楼 得分:0
    mark
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • luluyy
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-08-31 18:54:2021楼 得分:0
    #region ' >> using

    using System;
    using System.Collections;
    using System.Diagnostics;
    using System.Drawing;
    using System.Windows.Forms;

    #endregion
    namespace MovableControllerTest
    {
    /// <summary>
    /// 用于相关控件的大小变更和移动 </summary>
    ///
    public class MovableController
    {
           
            //// constructor
            //#region ' + constructor ()
            ///// <summary>
            ///// MovableController 初始化新实例 </summary>
            /////
            //public MovableController()
            //{
            //}
            //#endregion
           
           
    // field
    #region ' >> field
           
    private Control _control;

    private bool _isDraggingForResizing = false;
    private bool _isDraggingForMove = false;

    private int _resizingBorderWidth = 5;
    private Size _minimumSize = new Size( 39, 20 );//控件最小尺寸

    private Size _controlBeforeSize;//移动之前控件大小
    private Point _controlBeforeLocation;//移动之前控件的坐标
    private Point _cursorBeforeLocation;

    private LocationKind _draggingKind;//鼠标的种类

    private ArrayList _attachedControls = new ArrayList();//控件动态数组

    #endregion
           
           
    // property
    #region ' + ResizingBorderWidth : int { get,set }
    /// <summary>
    /// 为变更控件大小 取得或设置边界宽度
    /// 默认值为10 </summary>
    ///
    /// <exception cref="System.ArgumentOutOfRangeException">
    /// value小于0 </exception>
    ///
    public int ResizingBorderWidth
    {
    get { return _resizingBorderWidth; }
    set
    {
    if ( value <= 0 ) throw new ArgumentOutOfRangeException( "小于0" );

    _resizingBorderWidth = value;
    }
    }
    #endregion

    #region ' + MinimumSize : Size { get,set }
    /// <summary>
            /// 取得或设置变更控件大小时的最小值 </summary>
    /// <remarks>
    /// 由于用于大小变更的位置种类有9种
    /// 要设定的大小的高度和宽度都必须是ResizingBorderWidth的3倍以上 </remarks>
    ///
    /// <exception cref="System.ArgumentOutOfRangeException">
    /// value 的 Height 属性未到 ResizingBorderWidth 的 3 倍
            /// value 的 Width 属性未到 ResizingBorderWidth 的 3 倍 </exception>
    ///
    public Size MinimumSize
    {
    get { return _minimumSize; }
    set
    {
                    if (value.Height < ResizingBorderWidth * 3) throw new ArgumentOutOfRangeException("Height 属性未到 ResizingBorderWidth 的 3 倍");
                    if (value.Width < ResizingBorderWidth * 3) throw new ArgumentOutOfRangeException("Width 属性未到 ResizingBorderWidth 的 3 倍");

    _minimumSize = value;
    }
    }
    #endregion
    #region '  - AttachedControls : ArrayList { get }
    /// <summary>
    /// 取得相关控件的集合 </summary>
    ///
    private ArrayList AttachedControls
    {
    get { return _attachedControls; }
    }
    #endregion
    #region '  - Control : Control { get,set }
    /// <summary>
    /// 取得或设定控件 </summary>
    ///
    private Control Control
    {
    get { return _control; }
    set
    {
    if ( value == null ) throw new ArgumentNullException( "null 偱偡丅" );

    _control = value;
    }
    }
    #endregion
    #region '  - ControlBeforeLocation : Point { get,set }
    /// <summary>
    /// 取得或设定控件变更前的位置 </summary>
    ///
    private Point ControlBeforeLocation
    {
    get { return _controlBeforeLocation; }
    set
    {
    // debug
    Debug.WriteLine( "ControlBeforeLocation set:" );
    Debug.WriteLine( "    X:" + value.X.ToString() );
    Debug.WriteLine( "    Y:" + value.Y.ToString() );

    _controlBeforeLocation = value;
    }
    }
    #endregion
    #region '  - ControlBeforeSize : Size { get,set }
    /// <summary>
            /// 取得或设定控件变更前的大小 </summary>
    ///
    private Size ControlBeforeSize
    {
    get { return _controlBeforeSize; }
    set
    {
    // debug
    Debug.WriteLine( "ControlBeforeSize set:" );
    Debug.WriteLine( "    Width : " + value.Width.ToString() );
    Debug.WriteLine( "    Height: " + value.Height.ToString() );

    _controlBeforeSize = value;
    }
    }
    #endregion
    #region '  - CursorBeforeLocation : Point { get,set }
    /// <summary>
            /// 取得或设定控件变更前的鼠标指针位置 </summary>
    ///
    private Point CursorBeforeLocation
    {
    get { return _cursorBeforeLocation; }
    set
    {
    // debug
    Debug.WriteLine( "CursorBeforeLocation set:" );
    Debug.WriteLine( "    X: " + value.X.ToString() );
    Debug.WriteLine( "    Y: " + value.Y.ToString() );

    _cursorBeforeLocation = value;
    }
    }
    #endregion
    #region '  - DraggingKind : LocationKind { get,set }
    /// <summary>
            /// 取得或设定由拖拽状态所表示的位置种类 </summary>
    ///
    private LocationKind DraggingKind
    {
    get { return _draggingKind; }
    set { _draggingKind = value; }
    }
    #endregion
    #region '  - IsDraggingForResizing : bool { get,set }
    /// <summary>
    /// 取得或设定为变更控件大小而显示该控件是否正在被拖拽的值 </summary>
    ///
    private bool IsDraggingForResizing
    {
    get { return _isDraggingForResizing; }
    set
    {
    // debug
    Debug.WriteLine( "IsDraggingForResizing set: " + value.ToString() );

    _isDraggingForResizing = value;
    }
    }
    #endregion
    #region '  - IsDraggingForMove : bool { get,set }
    /// <summary>
            /// 取得或设定为移动控件而显示该控件是否正在被拖拽的值 </summary>
    ///
    private bool IsDraggingForMove
    {
    get { return _isDraggingForMove; }
    set
    {
    // debug
    Debug.WriteLine( "IsDraggingForMove set: " + value.ToString() );

    _isDraggingForMove = value;
    }
    }
    #endregion
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • luluyy
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-08-31 18:55:5622楼 得分:0
    // method
    #region ' + Attach ( Control ) : void
    /// <summary>
    /// 关联控件
    /// 忽视已被关联的控件 </summary>
    /// <remarks>
    /// 相关联的控件的高度或宽度未到 MinimumSize 属性值时
            /// 自动将其设定为MinimumSize值 </remarks>
    ///
    ///    <param name="anAttachingControl">
            ///    相关联控件 </param>
    ///
    /// <exception cref="System.ArgumentNullException">
    /// anAttachingControl 值为 null </exception>
    ///
    public void Attach( Control anAttachingControl )
    {
    if ( anAttachingControl == null ) throw new ArgumentNullException( "null" );

    if ( IsUnderMinimumSize( anAttachingControl.Size ) )
    {
    if ( anAttachingControl.Size.Height < MinimumSize.Height )
    {
    anAttachingControl.Size = new Size( anAttachingControl.Height, MinimumSize.Height );
    }
    if ( anAttachingControl.Size.Width < MinimumSize.Width )
    {
    anAttachingControl.Size = new Size( MinimumSize.Width, anAttachingControl.Width );
    }
    }

    if ( AttachedControls.Contains( anAttachingControl ) == false )
    {
    AttachedControls.Add( anAttachingControl );
    AttachControlEvent( anAttachingControl );
    }

    }
    #endregion
    #region ' + Detach ( Control ) : void
    /// <summary>
            /// 解除相关联的控件
            /// 忽视已解除关联的控件 </summary>
    ///
    ///    <param name="anAttachControl">
            ///    解除关联的控件 </param>
    ///
    /// <exception cref="System.ArgumentNullException">
    /// aDetachingControl 值为 null </exception>
    ///
    public void Detach( Control aDetachingControl )
    {
    if ( aDetachingControl == null ) throw new ArgumentNullException( "null" );

    if ( AttachedControls.Contains( aDetachingControl ) )
    {
    AttachedControls.Remove( aDetachingControl );
    DetachControlEvent( aDetachingControl );
    aDetachingControl.Cursor = Cursors.Default;
    }

    }
    #endregion
    #region '  - AttachControlEvent ( Control ) : void
    /// <summary>
    /// 注册控件事件 </summary>
    ///
    private void AttachControlEvent( Control aTargetControl )
    {
    aTargetControl.MouseDown += new MouseEventHandler( this.AttachedControl_MouseDown );
    aTargetControl.MouseMove += new MouseEventHandler( this.AttachedControl_MouseMove );
    aTargetControl.MouseUp += new MouseEventHandler( this.AttachedControl_MouseUp );
    aTargetControl.Paint += new PaintEventHandler( this.AttachedControl_Paint );
    }
    #endregion
    #region '  - DetachControlEvent ( Control ) : void
    /// <summary>
            /// 解除注册控件事件 </summary>
    ///
    private void DetachControlEvent( Control aTargetControl )
    {
    aTargetControl.MouseDown -= new MouseEventHandler( this.AttachedControl_MouseDown );
    aTargetControl.MouseMove -= new MouseEventHandler( this.AttachedControl_MouseMove );
    aTargetControl.MouseUp -= new MouseEventHandler( this.AttachedControl_MouseUp );
    aTargetControl.Paint -= new PaintEventHandler( this.AttachedControl_Paint );
    }
    #endregion
    #region '  - GetLocationKind ( Point ) : LocationKind
    /// <summary>
    /// 通过鼠标指针位置取得当前位置种类 </summary>
    ///
    private LocationKind GetLocationKind( Point aCursorLocation )
    {
    LocationKind kind;

    // is outer
    if ( ( aCursorLocation.X <= 0 &&
    Control.Width < aCursorLocation.X ) ||
    ( aCursorLocation.Y <= 0 &&
    Control.Height < aCursorLocation.Y ) )
    {
    kind = LocationKind.Outer;
    }
    // is UpperLeft
    else if ( aCursorLocation.X <= ResizingBorderWidth &&
    aCursorLocation.Y <= ResizingBorderWidth )
    {
    kind = LocationKind.UpperLeft;
    }
    // is UpperRigth
    else if ( Control.Width - ResizingBorderWidth <= aCursorLocation.X &&
    aCursorLocation.Y <= ResizingBorderWidth )
    {
    kind = LocationKind.UpperRight;
    }
    // is LowerLeft
    else if ( aCursorLocation.X <= ResizingBorderWidth &&
    Control.Height - ResizingBorderWidth <= aCursorLocation.Y )
    {
    kind = LocationKind.LowerLeft;
    }
    // is LowerRight
    else if ( Control.Width - ResizingBorderWidth <= aCursorLocation.X &&
    Control.Height - ResizingBorderWidth <= aCursorLocation.Y )
    {
    kind = LocationKind.LowerRight;
    }
    // is Upper
    else if ( aCursorLocation.Y <= ResizingBorderWidth )
    {
    kind = LocationKind.Upper;
    }
    // is Lower
    else if ( Control.Height - ResizingBorderWidth <=
    aCursorLocation.Y )
    {
    kind = LocationKind.Lower;
    }
    // is Left
    else if ( aCursorLocation.X <= ResizingBorderWidth )
    {
    kind = LocationKind.Left;
    }
    // is Right
    else if ( Control.Width - ResizingBorderWidth <=
    aCursorLocation.X )
    {
    kind = LocationKind.Right;
    }
    // is Inner
    else
    {
    kind = LocationKind.Inner;
    }

    // debug
    Debug.WriteLine( "GetLocaitonKind return: " + kind.ToString() );

    return kind;
    }
    #endregion
    #region '  - IsUnderMinimumSize ( Size ) : bool
    /// <summary>
    /// 取得表示控件大小是否在设定的最小值以内的值 </summary>
    ///
    private bool IsUnderMinimumSize( Size aControlSize )
    {
    if ( aControlSize.Width <= MinimumSize.Width ||
    aControlSize.Height <= MinimumSize.Height )
    {
    return true;
    }

    return false;
    }
    #endregion
    #region '  - SetupCursor ( LocationKind ) : void
    /// <summary>
    /// 根据位置种类设定鼠标指针类型 </summary>
    ///
    private void SetupCursor( LocationKind aLocationKind )
    {
    switch ( aLocationKind )
    {
    case LocationKind.Upper:
    case LocationKind.Lower:

    if ( Control.Cursor != Cursors.SizeNS )
    {
    Control.Cursor = Cursors.SizeNS;
    }
    break;

    case LocationKind.UpperRight:
    case LocationKind.LowerLeft:

    if ( Control.Cursor != Cursors.SizeNESW )
    {
    Control.Cursor = Cursors.SizeNESW;
    }
    break;

    case LocationKind.Right:
    case LocationKind.Left:

    if ( Control.Cursor != Cursors.SizeWE )
    {
    Control.Cursor = Cursors.SizeWE;
    }
    break;

    case LocationKind.LowerRight:
    case LocationKind.UpperLeft:

    if ( Control.Cursor != Cursors.SizeNWSE )
    {
    Control.Cursor = Cursors.SizeNWSE;
    }
    break;

    case LocationKind.Inner:

    if ( Control.Cursor != Cursors.SizeAll )
    {
    Control.Cursor = Cursors.SizeAll;
    }
    break;

    default:

    Control.Cursor = Cursors.Default;
    break;
    }
    }
    #endregion
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • luluyy
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-08-31 18:56:4023楼 得分:0
    #region '  - ResizeControl ( Point ) : void
    /// <summary>
    /// 变更控件大小 </summary>
    ///
    private void ResizeControl( Point aCursorLocation )
    {
    int diffWidth;
    int diffHeight;
    Size changedSize;
    Point changedLocation;

    switch ( DraggingKind )
    {
    // Upper
    case LocationKind.Upper:

    diffHeight = CursorBeforeLocation.Y + aCursorLocation.Y;

    changedSize = new Size( Control.Width,
                            Control.Height - diffHeight );
    changedLocation = new Point( Control.Location.X,
                                Control.Location.Y + diffHeight );

    ResizeControl( changedLocation, changedSize );
    break;

    // UpperRight
    case LocationKind.UpperRight:

    diffHeight = CursorBeforeLocation.Y + aCursorLocation.Y;
    diffWidth = CursorBeforeLocation.X - aCursorLocation.X;

    changedSize = new Size( ControlBeforeSize.Width - diffWidth,
                            Control.Height - diffHeight );
    changedLocation = new Point( Control.Location.X,
                                Control.Location.Y + diffHeight );

    ResizeControl( changedLocation, changedSize );
    break;

    // Rigth
    case LocationKind.Right:

    diffWidth = CursorBeforeLocation.X - aCursorLocation.X;

    changedSize = new Size( ControlBeforeSize.Width - diffWidth,
                            ControlBeforeSize.Height );

    ResizeControl( changedSize );
    break;

    // LowerRight
    case LocationKind.LowerRight:

    diffWidth = CursorBeforeLocation.X - aCursorLocation.X;
    diffHeight = CursorBeforeLocation.Y - aCursorLocation.Y;

    changedSize = new Size( ControlBeforeSize.Width - diffWidth,
                            ControlBeforeSize.Height - diffHeight );

    ResizeControl( changedSize );
    break;

    // lower
    case LocationKind.Lower:

    diffHeight = CursorBeforeLocation.Y - aCursorLocation.Y;

    changedSize = new Size( ControlBeforeSize.Width,
                            ControlBeforeSize.Height - diffHeight );

    ResizeControl( changedSize );
    break;

    // LowerLeft
    case LocationKind.LowerLeft:

    diffHeight = CursorBeforeLocation.Y - aCursorLocation.Y;
    diffWidth = CursorBeforeLocation.X + aCursorLocation.X;

    changedSize = new Size( Control.Width - diffWidth, ControlBeforeSize.Height - diffHeight );
    changedLocation = new Point( Control.Location.X + diffWidth, Control.Location.Y );

    ResizeControl( changedLocation, changedSize );
    break;

    // Left
    case LocationKind.Left:

    diffWidth = CursorBeforeLocation.X + aCursorLocation.X;

    changedSize = new Size( Control.Width - diffWidth,
                            Control.Height );
    changedLocation = new Point( Control.Location.X + diffWidth,
                                Control.Location.Y );

    ResizeControl( changedLocation, changedSize );
    break;

    // UpperLeft
    case LocationKind.UpperLeft:

    diffHeight = CursorBeforeLocation.Y + aCursorLocation.Y;
    diffWidth = CursorBeforeLocation.X + aCursorLocation.X;

    changedSize = new Size( Control.Width - diffWidth, Control.Height - diffHeight );
    changedLocation = new Point( Control.Location.X + diffWidth, Control.Location.Y + diffHeight );

    ResizeControl( changedLocation, changedSize );
    break;

    default:

    break;
    }

    Control.Refresh();
               
    }
    #endregion
    #region '  - ResizeControl ( Size ) : void
    /// <summary>
            /// 变更控件大小 </summary>
    ///
    private void ResizeControl( Size aNewSize )
    {
               
    if ( IsUnderMinimumSize( aNewSize ) )
    {
    int width = MinimumSize.Width;
    int height = MinimumSize.Height;

    if ( MinimumSize.Width < aNewSize.Width )
    {
    width = aNewSize.Width+37;
    }
    if ( MinimumSize.Height < aNewSize.Height )
    {
    height = aNewSize.Height+39;
    }

    Control.Size = new Size( width, height );
    }
    else
    {
    Control.Size = aNewSize;
    }
    }
    #endregion
    #region '  - ResizeControl ( Point, Size ) : void
    /// <summary>
            /// 变更控件大小 </summary>
    ///
    private void ResizeControl( Point aNewLocation, Size aNewSize )
    {
    if ( IsUnderMinimumSize( aNewSize ) )
    {
    int width = aNewSize.Width;
    int height = aNewSize.Height;
    int x = aNewLocation.X;
    int y = aNewLocation.Y;

    if ( aNewSize.Width <= MinimumSize.Width )
    {
    width = MinimumSize.Width;

    if ( DraggingKind == LocationKind.UpperRight )
    {
    x = ControlBeforeLocation.X;
    }
    else
    {
    x = Control.Left + Control.Size.Width - MinimumSize.Width;
    }
    }
    if ( aNewSize.Height <= MinimumSize.Height )
    {
    if ( DraggingKind == LocationKind.LowerLeft )
    {
    y = ControlBeforeLocation.Y;
    }
    else
    {
    y = Control.Top + Control.Size.Height - MinimumSize.Height;
    }
    height = MinimumSize.Height;
    }

    Control.SetBounds( x,
                      y,
                      width,
                      height,
                      BoundsSpecified.All );
    }
    else
    {
    Control.SetBounds( aNewLocation.X,
                      aNewLocation.Y,
                      aNewSize.Width,
                      aNewSize.Height,
                      BoundsSpecified.All );
    }
    }
    #endregion
    #region '  - MoveControl ( Point ) : void
    /// <summary>
    /// 移动控件 </summary>
    ///
    private void MoveControl( Point aCursorLocation )
    {
    Control.Location =
    new Point( ControlBeforeLocation.X - ( CursorBeforeLocation.X - aCursorLocation.X ),
              ControlBeforeLocation.Y - ( CursorBeforeLocation.Y - aCursorLocation.Y ) );
    ControlBeforeLocation = Control.Location;
    Control.Refresh();
    }
    #endregion
           
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • chaojitanke
    • 等级:
    • 可用分等级:
    • 总技术专家分:
    • 总技术专家分排名:
    发表于:2008-09-01 21:11:3124楼 得分:0
    楼上,有Demo么?能不能发个给我?chaojitanke2003@yahoo.com.cn
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天