Browse Source

新增动态修改空间位置控件

yuzhengyang 9 years ago
parent
commit
b688d509f1

+ 12 - 0
Fork.Net/Y.Controls.Net20/Class1.cs

@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Y.Controls.Net20
+{
+    public class Class1
+    {
+    }
+}

+ 38 - 0
Fork.Net/Y.Controls.Net20/Container/FlexiblePanel.Designer.cs

@@ -0,0 +1,38 @@
+namespace Y.Controls.Net20.Container
+{
+    partial class FlexiblePanel
+    {
+        /// <summary> 
+        /// 必需的设计器变量。
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+        public System.Windows.Forms.AutoSizeMode AutoScaleMode { get; set; }
+        /// <summary> 
+        /// 清理所有正在使用的资源。
+        /// </summary>
+        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region 组件设计器生成的代码
+
+        /// <summary> 
+        /// 设计器支持所需的方法 - 不要修改
+        /// 使用代码编辑器修改此方法的内容。
+        /// </summary>
+        private void InitializeComponent()
+        {
+            components = new System.ComponentModel.Container();
+            this.AutoScaleMode = base.AutoSizeMode;
+            this.BackColor = System.Drawing.Color.Blue;
+        }
+
+        #endregion
+    }
+}

+ 314 - 0
Fork.Net/Y.Controls.Net20/Container/FlexiblePanel.cs

@@ -0,0 +1,314 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Drawing;
+using System.Data;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using System.Xml;
+
+namespace Y.Controls.Net20.Container
+{
+    public partial class FlexiblePanel : Panel
+    {
+        /// <summary>
+        /// 光标状态
+        /// </summary>
+        private enum EnumMousePointPosition
+        {
+            MouseSizeNone = 0, //'无   
+            MouseSizeRight = 1, //'拉伸右边框   
+            MouseSizeLeft = 2, //'拉伸左边框   
+            MouseSizeBottom = 3, //'拉伸下边框   
+            MouseSizeTop = 4, //'拉伸上边框   
+            MouseSizeTopLeft = 5, //'拉伸左上角   
+            MouseSizeTopRight = 6, //'拉伸右上角   
+            MouseSizeBottomLeft = 7, //'拉伸左下角   
+            MouseSizeBottomRight = 8, //'拉伸右下角   
+            MouseDrag = 9   // '鼠标拖动   
+        }
+        #region 属性
+        private static string xmlDocPath = "";
+        private XmlDocument doc;
+        private const int Band = 5;
+        private const int MinWidth = 10;
+        private const int MinHeight = 10;
+        private EnumMousePointPosition m_MousePointPosition;
+        private Point p, p1;
+        #endregion
+        public FlexiblePanel()
+        {
+            InitializeComponent();
+        }
+
+        #region 改变控件大小和移动位置用到的方法
+
+
+
+        private void MyMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
+        {
+            p.X = e.X;
+            p.Y = e.Y;
+            p1.X = e.X;
+            p1.Y = e.Y;
+        }
+        /// <summary>
+        /// 鼠标离开事件需要改进
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void MyMouseLeave(object sender, EventArgs e)
+        {
+            Control s = (Control)sender;
+
+            XmlNodeList nodes = doc.GetElementsByTagName(s.Name);
+            XmlElement xn;
+            if (nodes.Count != 1)
+            {
+                xn = doc.CreateElement(s.Name);
+            }
+            else
+            {
+                xn = (XmlElement)doc.GetElementsByTagName(s.Name)[0];
+            }
+            xn.SetAttribute("Top", s.Top.ToString());
+            xn.SetAttribute("Left", s.Left.ToString());
+            xn.SetAttribute("Width", s.Width.ToString());
+            xn.SetAttribute("Height", s.Height.ToString());
+
+
+            XmlNodeList xnl = doc.GetElementsByTagName(this.Name);
+            XmlElement xnp;
+            if (xnl.Count < 1)
+            {
+                xnp = doc.CreateElement(this.Name);
+            }
+            else
+            {
+                xnp = (XmlElement)xnl[0];
+            }
+            xnp.AppendChild((XmlNode)xn);
+            doc.DocumentElement.AppendChild((XmlNode)xnp);
+            doc.Save(xmlDocPath);
+
+            m_MousePointPosition = EnumMousePointPosition.MouseSizeNone;
+            this.Cursor = Cursors.Arrow;
+        }
+
+        private EnumMousePointPosition MousePointPosition(Size size, System.Windows.Forms.MouseEventArgs e)
+        {
+
+            if ((e.X >= -1 * Band) | (e.X <= size.Width) | (e.Y >= -1 * Band) | (e.Y <= size.Height))
+            {
+                if (e.X < Band)
+                {
+                    if (e.Y < Band) { return EnumMousePointPosition.MouseSizeTopLeft; }
+                    else
+                    {
+                        if (e.Y > -1 * Band + size.Height)
+                        { return EnumMousePointPosition.MouseSizeBottomLeft; }
+                        else
+                        { return EnumMousePointPosition.MouseSizeLeft; }
+                    }
+                }
+                else
+                {
+                    if (e.X > -1 * Band + size.Width)
+                    {
+                        if (e.Y < Band)
+                        { return EnumMousePointPosition.MouseSizeTopRight; }
+                        else
+                        {
+                            if (e.Y > -1 * Band + size.Height)
+                            { return EnumMousePointPosition.MouseSizeBottomRight; }
+                            else
+                            { return EnumMousePointPosition.MouseSizeRight; }
+                        }
+                    }
+                    else
+                    {
+                        if (e.Y < Band)
+                        { return EnumMousePointPosition.MouseSizeTop; }
+                        else
+                        {
+                            if (e.Y > -1 * Band + size.Height)
+                            { return EnumMousePointPosition.MouseSizeBottom; }
+                            else
+                            { return EnumMousePointPosition.MouseDrag; }
+                        }
+                    }
+                }
+            }
+            else
+            { return EnumMousePointPosition.MouseSizeNone; }
+        }
+        private void MyMouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
+        {
+            Control lCtrl = (sender as Control);
+
+            if (e.Button == MouseButtons.Left)
+            {
+                switch (m_MousePointPosition)
+                {
+                    case EnumMousePointPosition.MouseDrag:
+                        lCtrl.Left = lCtrl.Left + e.X - p.X;
+                        lCtrl.Top = lCtrl.Top + e.Y - p.Y;
+                        break;
+                    case EnumMousePointPosition.MouseSizeBottom:
+                        lCtrl.Height = lCtrl.Height + e.Y - p1.Y;
+                        p1.X = e.X;
+                        p1.Y = e.Y; //'记录光标拖动的当前点   
+                        break;
+                    case EnumMousePointPosition.MouseSizeBottomRight:
+                        lCtrl.Width = lCtrl.Width + e.X - p1.X;
+                        lCtrl.Height = lCtrl.Height + e.Y - p1.Y;
+                        p1.X = e.X;
+                        p1.Y = e.Y; //'记录光标拖动的当前点   
+                        break;
+                    case EnumMousePointPosition.MouseSizeRight:
+                        lCtrl.Width = lCtrl.Width + e.X - p1.X;
+                        //       lCtrl.Height = lCtrl.Height + e.Y - p1.Y;   
+                        p1.X = e.X;
+                        p1.Y = e.Y; //'记录光标拖动的当前点   
+                        break;
+                    case EnumMousePointPosition.MouseSizeTop:
+                        lCtrl.Top = lCtrl.Top + (e.Y - p.Y);
+                        lCtrl.Height = lCtrl.Height - (e.Y - p.Y);
+                        break;
+                    case EnumMousePointPosition.MouseSizeLeft:
+                        lCtrl.Left = lCtrl.Left + e.X - p.X;
+                        lCtrl.Width = lCtrl.Width - (e.X - p.X);
+                        break;
+                    case EnumMousePointPosition.MouseSizeBottomLeft:
+                        lCtrl.Left = lCtrl.Left + e.X - p.X;
+                        lCtrl.Width = lCtrl.Width - (e.X - p.X);
+                        lCtrl.Height = lCtrl.Height + e.Y - p1.Y;
+                        p1.X = e.X;
+                        p1.Y = e.Y; //'记录光标拖动的当前点   
+                        break;
+                    case EnumMousePointPosition.MouseSizeTopRight:
+                        lCtrl.Top = lCtrl.Top + (e.Y - p.Y);
+                        lCtrl.Width = lCtrl.Width + (e.X - p1.X);
+                        lCtrl.Height = lCtrl.Height - (e.Y - p.Y);
+                        p1.X = e.X;
+                        p1.Y = e.Y; //'记录光标拖动的当前点   
+                        break;
+                    case EnumMousePointPosition.MouseSizeTopLeft:
+                        lCtrl.Left = lCtrl.Left + e.X - p.X;
+                        lCtrl.Top = lCtrl.Top + (e.Y - p.Y);
+                        lCtrl.Width = lCtrl.Width - (e.X - p.X);
+                        lCtrl.Height = lCtrl.Height - (e.Y - p.Y);
+                        break;
+                    default:
+                        break;
+                }
+                if (lCtrl.Width < MinWidth) lCtrl.Width = MinWidth;
+                if (lCtrl.Height < MinHeight) lCtrl.Height = MinHeight;
+
+            }
+            else
+            {
+                m_MousePointPosition = MousePointPosition(lCtrl.Size, e);   //'判断光标的位置状态   
+                switch (m_MousePointPosition)   //'改变光标   
+                {
+                    case EnumMousePointPosition.MouseSizeNone:
+                        this.Cursor = Cursors.Arrow;        //'箭头   
+                        break;
+                    case EnumMousePointPosition.MouseDrag:
+                        this.Cursor = Cursors.SizeAll;      //'四方向   
+                        break;
+                    case EnumMousePointPosition.MouseSizeBottom:
+                        this.Cursor = Cursors.SizeNS;       //'南北   
+                        break;
+                    case EnumMousePointPosition.MouseSizeTop:
+                        this.Cursor = Cursors.SizeNS;       //'南北   
+                        break;
+                    case EnumMousePointPosition.MouseSizeLeft:
+                        this.Cursor = Cursors.SizeWE;       //'东西   
+                        break;
+                    case EnumMousePointPosition.MouseSizeRight:
+                        this.Cursor = Cursors.SizeWE;       //'东西   
+                        break;
+                    case EnumMousePointPosition.MouseSizeBottomLeft:
+                        this.Cursor = Cursors.SizeNESW;     //'东北到南西   
+                        break;
+                    case EnumMousePointPosition.MouseSizeBottomRight:
+                        this.Cursor = Cursors.SizeNWSE;     //'东南到西北   
+                        break;
+                    case EnumMousePointPosition.MouseSizeTopLeft:
+                        this.Cursor = Cursors.SizeNWSE;     //'东南到西北   
+                        break;
+                    case EnumMousePointPosition.MouseSizeTopRight:
+                        this.Cursor = Cursors.SizeNESW;     //'东北到南西   
+                        break;
+                    default:
+                        break;
+                }
+            }
+
+        }
+
+
+        #endregion
+
+        #region 初始化鼠标事件委托和控件大小和移动
+        private void initProperty()
+        {
+            for (int i = 0; i < this.Controls.Count; i++)
+            {
+                this.Controls[i].MouseDown += new System.Windows.Forms.MouseEventHandler(MyMouseDown);
+                this.Controls[i].MouseLeave += new System.EventHandler(MyMouseLeave);
+                this.Controls[i].MouseMove += new System.Windows.Forms.MouseEventHandler(MyMouseMove);
+            }
+
+        }
+        private void initStyle()
+        {
+            Control s;
+            for (int i = 0; i < this.Controls.Count; i++)
+            {
+                s = this.Controls[i];
+                XmlNodeList nodes = doc.GetElementsByTagName(s.Name);
+                if (nodes.Count == 1)
+                {
+                    XmlAttributeCollection xac = nodes[0].Attributes;
+                    foreach (XmlAttribute xa in xac)
+                    {
+                        if (xa.Value == "")
+                            continue;
+                        switch (xa.Name)
+                        {
+                            case "Top":
+                                var Top = Convert.ToInt32(xa.Value);
+                                if (Top > 0 && Top < this.Height - s.Height)
+                                    s.Top = Top;
+                                break;
+                            case "Left":
+                                var Left = Convert.ToInt32(xa.Value);
+                                if (Left > 0 && Left < this.Width - s.Width)
+                                    s.Left = Left;
+                                break;
+                            default:
+                                break;
+                        }
+                    }
+                }
+            }
+        }
+        #endregion
+        /// <summary>
+        /// 用于实现容器内控件移动和改变大小的方法
+        /// </summary>
+        /// <param name="XmlDoc">用于保存控件的属性的XML文档</param>
+        public void InitMouseAndContolStyle(string XmlDocPath)
+        {
+            xmlDocPath = XmlDocPath;
+            doc = new XmlDocument();
+            doc.Load(XmlDocPath);
+            initProperty();
+            initStyle();
+        }
+    }
+}

+ 36 - 0
Fork.Net/Y.Controls.Net20/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的一般信息由以下
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("Y.Controls.Net20")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Y.Controls.Net20")]
+[assembly: AssemblyCopyright("Copyright ©  2017")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+//将 ComVisible 设置为 false 将使此程序集中的类型
+//对 COM 组件不可见。  如果需要从 COM 访问此程序集中的类型,
+//请将此类型的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("490e9be8-814d-4617-8271-41a73c373f7d")]
+
+// 程序集的版本信息由下列四个值组成: 
+//
+//      主版本
+//      次版本
+//      生成号
+//      修订号
+//
+//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
+// 方法是按如下所示使用“*”: :
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 57 - 0
Fork.Net/Y.Controls.Net20/Y.Controls.Net20.csproj

@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{490E9BE8-814D-4617-8271-41A73C373F7D}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Y.Controls.Net20</RootNamespace>
+    <AssemblyName>Y.Controls.Net20</AssemblyName>
+    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <TargetFrameworkProfile />
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Windows.Forms" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Class1.cs" />
+    <Compile Include="Container\FlexiblePanel.cs">
+      <SubType>Component</SubType>
+    </Compile>
+    <Compile Include="Container\FlexiblePanel.Designer.cs">
+      <DependentUpon>FlexiblePanel.cs</DependentUpon>
+    </Compile>
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

+ 49 - 0
Fork.Net/Y.Controls/Container/FlexiblePanel.Designer.cs

@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Drawing;
+using System.Data;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using System.Xml;
+
+namespace Y.Controls.Container
+{
+    partial class FlexiblePanel
+    {
+        /// <summary> 
+        /// 必需的设计器变量。
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+        public System.Windows.Forms.AutoSizeMode AutoScaleMode { get; set; }
+        /// <summary> 
+        /// 清理所有正在使用的资源。
+        /// </summary>
+        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region 组件设计器生成的代码
+
+        /// <summary> 
+        /// 设计器支持所需的方法 - 不要修改
+        /// 使用代码编辑器修改此方法的内容。
+        /// </summary>
+        private void InitializeComponent()
+        {
+            components = new System.ComponentModel.Container();
+            this.AutoScaleMode = base.AutoSizeMode;
+            this.BackColor = System.Drawing.Color.White;
+        }
+
+        #endregion
+    }
+}

+ 327 - 0
Fork.Net/Y.Controls/Container/FlexiblePanel.cs

@@ -0,0 +1,327 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Drawing;
+using System.Data;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using System.Xml;
+
+namespace Y.Controls.Container
+{
+    public partial class FlexiblePanel : Panel
+    {
+        Color HighlightColor = ColorTranslator.FromHtml("#78c4ec");
+
+        /// <summary>
+        /// 光标状态
+        /// </summary>
+        private enum EnumMousePointPosition
+        {
+            MouseSizeNone = 0, //'无   
+            MouseSizeRight = 1, //'拉伸右边框   
+            MouseSizeLeft = 2, //'拉伸左边框   
+            MouseSizeBottom = 3, //'拉伸下边框   
+            MouseSizeTop = 4, //'拉伸上边框   
+            MouseSizeTopLeft = 5, //'拉伸左上角   
+            MouseSizeTopRight = 6, //'拉伸右上角   
+            MouseSizeBottomLeft = 7, //'拉伸左下角   
+            MouseSizeBottomRight = 8, //'拉伸右下角   
+            MouseDrag = 9   // '鼠标拖动   
+        }
+        #region 属性
+        private static string xmlDocPath = "";
+        private XmlDocument doc;
+        private const int Band = 5;
+        private const int MinWidth = 10;
+        private const int MinHeight = 10;
+        private EnumMousePointPosition m_MousePointPosition;
+        private Point p, p1;
+        #endregion
+        public FlexiblePanel()
+        {
+            SetStyle(ControlStyles.UserPaint, true);
+            SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.  
+            SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲  
+            InitializeComponent();
+        }
+
+        #region 改变控件大小和移动位置用到的方法
+
+
+
+        private void MyMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
+        {
+            p.X = e.X;
+            p.Y = e.Y;
+            p1.X = e.X;
+            p1.Y = e.Y;
+        }
+        /// <summary>
+        /// 鼠标离开事件需要改进
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void MyMouseLeave(object sender, EventArgs e)
+        {
+            Control s = (Control)sender;
+
+            XmlNodeList nodes = doc.GetElementsByTagName(s.Name);
+            XmlElement xn;
+            if (nodes.Count != 1)
+            {
+                xn = doc.CreateElement(s.Name);
+            }
+            else
+            {
+                xn = (XmlElement)doc.GetElementsByTagName(s.Name)[0];
+            }
+            xn.SetAttribute("Top", s.Top.ToString());
+            xn.SetAttribute("Left", s.Left.ToString());
+            xn.SetAttribute("Width", s.Width.ToString());
+            xn.SetAttribute("Height", s.Height.ToString());
+
+
+            XmlNodeList xnl = doc.GetElementsByTagName(this.Name);
+            XmlElement xnp;
+            if (xnl.Count < 1)
+            {
+                xnp = doc.CreateElement(this.Name);
+            }
+            else
+            {
+                xnp = (XmlElement)xnl[0];
+            }
+            xnp.AppendChild((XmlNode)xn);
+            doc.DocumentElement.AppendChild((XmlNode)xnp);
+            doc.Save(xmlDocPath);
+
+            m_MousePointPosition = EnumMousePointPosition.MouseSizeNone;
+            this.Cursor = Cursors.Arrow;
+            ((Control)sender).BackColor = Color.Transparent;
+        }
+
+        private EnumMousePointPosition MousePointPosition(Size size, System.Windows.Forms.MouseEventArgs e)
+        {
+
+            if ((e.X >= -1 * Band) | (e.X <= size.Width) | (e.Y >= -1 * Band) | (e.Y <= size.Height))
+            {
+                if (e.X < Band)
+                {
+                    if (e.Y < Band) { return EnumMousePointPosition.MouseSizeTopLeft; }
+                    else
+                    {
+                        if (e.Y > -1 * Band + size.Height)
+                        { return EnumMousePointPosition.MouseSizeBottomLeft; }
+                        else
+                        { return EnumMousePointPosition.MouseSizeLeft; }
+                    }
+                }
+                else
+                {
+                    if (e.X > -1 * Band + size.Width)
+                    {
+                        if (e.Y < Band)
+                        { return EnumMousePointPosition.MouseSizeTopRight; }
+                        else
+                        {
+                            if (e.Y > -1 * Band + size.Height)
+                            { return EnumMousePointPosition.MouseSizeBottomRight; }
+                            else
+                            { return EnumMousePointPosition.MouseSizeRight; }
+                        }
+                    }
+                    else
+                    {
+                        if (e.Y < Band)
+                        { return EnumMousePointPosition.MouseSizeTop; }
+                        else
+                        {
+                            if (e.Y > -1 * Band + size.Height)
+                            { return EnumMousePointPosition.MouseSizeBottom; }
+                            else
+                            { return EnumMousePointPosition.MouseDrag; }
+                        }
+                    }
+                }
+            }
+            else
+            { return EnumMousePointPosition.MouseSizeNone; }
+        }
+        private void MyMouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
+        {
+            Control lCtrl = (sender as Control);
+
+            if (e.Button == MouseButtons.Left)
+            {
+                switch (m_MousePointPosition)
+                {
+                    case EnumMousePointPosition.MouseDrag:
+                        lCtrl.Left = lCtrl.Left + e.X - p.X;
+                        lCtrl.Top = lCtrl.Top + e.Y - p.Y;
+                        break;
+                    case EnumMousePointPosition.MouseSizeBottom:
+                        lCtrl.Height = lCtrl.Height + e.Y - p1.Y;
+                        p1.X = e.X;
+                        p1.Y = e.Y; //'记录光标拖动的当前点   
+                        break;
+                    case EnumMousePointPosition.MouseSizeBottomRight:
+                        lCtrl.Width = lCtrl.Width + e.X - p1.X;
+                        lCtrl.Height = lCtrl.Height + e.Y - p1.Y;
+                        p1.X = e.X;
+                        p1.Y = e.Y; //'记录光标拖动的当前点   
+                        break;
+                    case EnumMousePointPosition.MouseSizeRight:
+                        lCtrl.Width = lCtrl.Width + e.X - p1.X;
+                        //       lCtrl.Height = lCtrl.Height + e.Y - p1.Y;   
+                        p1.X = e.X;
+                        p1.Y = e.Y; //'记录光标拖动的当前点   
+                        break;
+                    case EnumMousePointPosition.MouseSizeTop:
+                        lCtrl.Top = lCtrl.Top + (e.Y - p.Y);
+                        lCtrl.Height = lCtrl.Height - (e.Y - p.Y);
+                        break;
+                    case EnumMousePointPosition.MouseSizeLeft:
+                        lCtrl.Left = lCtrl.Left + e.X - p.X;
+                        lCtrl.Width = lCtrl.Width - (e.X - p.X);
+                        break;
+                    case EnumMousePointPosition.MouseSizeBottomLeft:
+                        lCtrl.Left = lCtrl.Left + e.X - p.X;
+                        lCtrl.Width = lCtrl.Width - (e.X - p.X);
+                        lCtrl.Height = lCtrl.Height + e.Y - p1.Y;
+                        p1.X = e.X;
+                        p1.Y = e.Y; //'记录光标拖动的当前点   
+                        break;
+                    case EnumMousePointPosition.MouseSizeTopRight:
+                        lCtrl.Top = lCtrl.Top + (e.Y - p.Y);
+                        lCtrl.Width = lCtrl.Width + (e.X - p1.X);
+                        lCtrl.Height = lCtrl.Height - (e.Y - p.Y);
+                        p1.X = e.X;
+                        p1.Y = e.Y; //'记录光标拖动的当前点   
+                        break;
+                    case EnumMousePointPosition.MouseSizeTopLeft:
+                        lCtrl.Left = lCtrl.Left + e.X - p.X;
+                        lCtrl.Top = lCtrl.Top + (e.Y - p.Y);
+                        lCtrl.Width = lCtrl.Width - (e.X - p.X);
+                        lCtrl.Height = lCtrl.Height - (e.Y - p.Y);
+                        break;
+                    default:
+                        break;
+                }
+                if (lCtrl.Width < MinWidth) lCtrl.Width = MinWidth;
+                if (lCtrl.Height < MinHeight) lCtrl.Height = MinHeight;
+
+            }
+            else
+            {
+                m_MousePointPosition = MousePointPosition(lCtrl.Size, e);   //'判断光标的位置状态   
+                switch (m_MousePointPosition)   //'改变光标   
+                {
+                    case EnumMousePointPosition.MouseSizeNone:
+                        this.Cursor = Cursors.Arrow;        //'箭头  
+                        break;
+                    case EnumMousePointPosition.MouseDrag:
+                        this.Cursor = Cursors.SizeAll;      //'四方向   
+                        ((Control)sender).BackColor = HighlightColor;
+                        break;
+                    case EnumMousePointPosition.MouseSizeBottom:
+                        this.Cursor = Cursors.SizeNS;       //'南北   
+                        break;
+                    case EnumMousePointPosition.MouseSizeTop:
+                        this.Cursor = Cursors.SizeNS;       //'南北   
+                        break;
+                    case EnumMousePointPosition.MouseSizeLeft:
+                        this.Cursor = Cursors.SizeWE;       //'东西   
+                        break;
+                    case EnumMousePointPosition.MouseSizeRight:
+                        this.Cursor = Cursors.SizeWE;       //'东西   
+                        break;
+                    case EnumMousePointPosition.MouseSizeBottomLeft:
+                        this.Cursor = Cursors.SizeNESW;     //'东北到南西   
+                        break;
+                    case EnumMousePointPosition.MouseSizeBottomRight:
+                        this.Cursor = Cursors.SizeNWSE;     //'东南到西北   
+                        break;
+                    case EnumMousePointPosition.MouseSizeTopLeft:
+                        this.Cursor = Cursors.SizeNWSE;     //'东南到西北   
+                        break;
+                    case EnumMousePointPosition.MouseSizeTopRight:
+                        this.Cursor = Cursors.SizeNESW;     //'东北到南西   
+                        break;
+                    default:
+                        break;
+                }
+            }
+
+        }
+
+
+        #endregion
+
+        #region 初始化鼠标事件委托和控件大小和移动
+        private void initProperty()
+        {
+            for (int i = 0; i < this.Controls.Count; i++)
+            {
+                this.Controls[i].MouseDown += new System.Windows.Forms.MouseEventHandler(MyMouseDown);
+                this.Controls[i].MouseLeave += new System.EventHandler(MyMouseLeave);
+                this.Controls[i].MouseMove += new System.Windows.Forms.MouseEventHandler(MyMouseMove);
+            }
+
+        }
+        private void initStyle()
+        {
+            Control s;
+            for (int i = 0; i < this.Controls.Count; i++)
+            {
+                s = this.Controls[i];
+                XmlNodeList nodes = doc.GetElementsByTagName(s.Name);
+                if (nodes.Count == 1)
+                {
+                    XmlAttributeCollection xac = nodes[0].Attributes;
+                    foreach (XmlAttribute xa in xac)
+                    {
+                        if (xa.Value == "")
+                            continue;
+                        switch (xa.Name)
+                        {
+                            case "Top":
+                                var Top = Convert.ToInt32(xa.Value);
+                                //if (Top > 0 && Top < this.Height - s.Height)
+                                s.Top = Top;
+                                break;
+                            case "Left":
+                                var Left = Convert.ToInt32(xa.Value);
+                                //if (Left > 0 && Left < this.Width - s.Width)
+                                s.Left = Left;
+                                break;
+                            case "Width":
+                                s.Width = Convert.ToInt32(xa.Value);
+                                break;
+                            case "Height":
+                                s.Height = Convert.ToInt32(xa.Value);
+                                break;
+                            default:
+                                break;
+                        }
+                    }
+                }
+            }
+        }
+        #endregion
+        /// <summary>
+        /// 用于实现容器内控件移动和改变大小的方法
+        /// </summary>
+        /// <param name="XmlDoc">用于保存控件的属性的XML文档</param>
+        public void InitMouseAndContolStyle(string XmlDocPath)
+        {
+            xmlDocPath = XmlDocPath;
+            doc = new XmlDocument();
+            doc.Load(XmlDocPath);
+            initProperty();
+            initStyle();
+        }
+    }
+}

+ 8 - 1
Fork.Net/Y.Controls/Y.Controls.csproj

@@ -9,8 +9,9 @@
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>Y.Controls</RootNamespace>
     <AssemblyName>Y.Controls</AssemblyName>
-    <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
+    <TargetFrameworkProfile />
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
@@ -42,6 +43,12 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Container\FlexiblePanel.cs">
+      <SubType>Component</SubType>
+    </Compile>
+    <Compile Include="Container\FlexiblePanel.Designer.cs">
+      <DependentUpon>FlexiblePanel.cs</DependentUpon>
+    </Compile>
     <Compile Include="Loadings\SimpleLoading.cs">
       <SubType>UserControl</SubType>
     </Compile>

+ 8 - 0
Fork.Net/Y.Utils.Net20/TxtUtils/IniTool.cs

@@ -384,6 +384,14 @@ namespace Y.Utils.Net20.TxtUtils
             string flag = GetStringValue(iniFile, section, key, "");
             return flag.ToLower() == "true" ? true : false;
         }
+        public static int GetIntValue(string iniFile, string section, string key, int defaultValue = 0)
+        {
+            int rs = 0;
+            string number = GetStringValue(iniFile, section, key, "Unknown");
+            if (int.TryParse(number, out rs))
+                return rs;
+            return defaultValue;
+        }
         #endregion
     }
 }

+ 16 - 1
Fork.Net/Y.Utils.Net20/TxtUtils/TxtTool.cs

@@ -61,7 +61,22 @@ namespace Y.Utils.Net20.TxtUtils
                 {
                     string result = "", line;
                     while ((line = sr.ReadLine()) != null)
-                        result += line.ToString();
+                        result += line.ToString() + Environment.NewLine;
+                    return result;
+                }
+            }
+            catch (Exception e) { }
+            return null;
+        }
+        public static string Read(string file, Encoding encoding)
+        {
+            try
+            {
+                using (StreamReader sr = new StreamReader(file, encoding))
+                {
+                    string result = "", line;
+                    while ((line = sr.ReadLine()) != null)
+                        result += line.ToString() + Environment.NewLine;
                     return result;
                 }
             }