首页 > 编程语言 >C#手动改变自制窗体的大小

C#手动改变自制窗体的大小

时间:2024-03-30 09:33:04浏览次数:16  
标签:C# 自制 System 窗体 new panel Resources Panel

目录

1.Cursor类的Position属性

2.改变窗体大小的计算方法

3.Resources设计

(1)Resources资源图片管理

(2)GetObject方法设计

(3)两种获取资源图片的方法

4.示例


        当用户去除Winform窗体边框,自行设置窗体外观时,用户就不能使用Windows窗体应用的功能对自定义窗体的大小进行随意改变了。

        此时手动改变无边框窗体的大小需要自定义改变窗体大小的方法,才能实现通过鼠标拖拽自定义窗体的右边、下边、右下角改变窗体的大小。改变自制窗体的大小时,主要用到了Cursor类的Position属性以及窗体的Width、Height、Top和Left属性,另外,还用到了改变窗体大小的计算方法。

1.Cursor类的Position属性

        Cursor类代表用于绘制鼠标指针的图像,其Position属性用于获取或设置光标位置。该属性的语法格式如下:

public static Point Position {get;set;}
参数说明
属性值:代表光标位置的Point(采用屏幕坐标)结构。

2.改变窗体大小的计算方法

        重要的算法就是如何根据鼠标的移动来设置窗体的大小:首先,用当前鼠标在屏幕上的X坐标值减去窗体左边距与屏幕左边距的距离,然后再加上鼠标与边框右端的距离,并将值设为当前窗体的宽度。实现代码如下:

Form.Width =Cursor.Position.X-Frm.Left+(Pan.Width -Example_X);

        其中,Form为窗体名称,Pan为显示窗体边框的控件名称,Example_X为鼠标按下时的X坐标值。说明:以上计算方法是在Panel控件的MouseMove事件中执行的。

3.Resources设计

(1)Resources资源图片管理

        按以下流程操作:

  • 新建文件夹Resources,并把项目所需图片放在这个文件夹中;
  • 把文件夹Resources放在项目的根目录下;
  • 打开VS上的项目,或者新建项目,新建的项目右侧资源管理器里是没有Properties和Resources文件夹的。
  • 在资源管理器中新建Properties和Resources文件夹:打开Form.cs[设计]→ 鼠标点中窗体任意位置→ 右侧资源管理器→ 鼠标选中BackGroudImage属性,选择资源,选中单选按钮项目资源文件(Properties\Resources)→ 确定,其它什么也不要操作。这时候观察右侧资源管理器,新建Properties文件夹成功,如果Resources文件夹位置仿制的正确,资源管理器上还会有Resources文件夹。但是,此时的Resources文件并没有关联到Properties上。
  • 在Properties文件夹的Resources.Designer.cs自动管理资源图片:鼠标双击Resources.resx文件,在弹出的窗体上,文件菜单里选择图片,添加资源菜单栏里选择添加现有文件。在新弹出的窗体里,找到Resources文件夹,并添加其中的所有图片,确定。VS会自动生成Resources.Designer.cs里的图片资源的属性。
  • 在Resources.Designer.cs里添加或更新GetObject方法;

(2)GetObject方法设计

         图片资源的属性是自动生成的,但是在程序中获取或加载图片的GetObject方法需要手动设计进Resources.Designer.cs中。

internal static Image GetObject(string v)
{
    return v switch
    {
        "panel_TitleLeft" => panel_TitleLeft,
        "panel_TitleMiddle" => panel_TitleMiddle,
        "panel_TitleRight" => panel_TitleRight,
        "panel_Left" => panel_Left,
        "panel_Right" => panel_Right,
        "panel_BottomLeft" => panel_BottomLeft,
        "panel_BottomMiddle" => panel_BottomMiddle,
        "panel_BottomRight" => panel_BottomRight,
        "pictureBox1_Image" => pictureBox1_Image,
        _ => null
    };
}
// Resources.Designer.cs
//------------------------------------------------------------------------------
// <auto-generated>
//     此代码由工具生成。
//     运行时版本:4.0.30319.42000
//
//     对此文件的更改可能会导致不正确的行为,并且如果
//     重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------

namespace _164.Properties {
    using System;
    
    
    /// <summary>
    ///   一个强类型的资源类,用于查找本地化的字符串等。
    /// </summary>
    // 此类是由 StronglyTypedResourceBuilder
    // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
    // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
    // (以 /str 作为命令选项),或重新生成 VS 项目。
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    internal class Resources {
        
        private static global::System.Resources.ResourceManager resourceMan;
        
        private static global::System.Globalization.CultureInfo resourceCulture;
        
        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        internal Resources() {
        }
        
        /// <summary>
        ///   返回此类使用的缓存的 ResourceManager 实例。
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Resources.ResourceManager ResourceManager {
            get {
                if (object.ReferenceEquals(resourceMan, null)) {
                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("_164.Properties.Resources", typeof(Resources).Assembly);
                    resourceMan = temp;
                }
                return resourceMan;
            }
        }
        
        /// <summary>
        ///   重写当前线程的 CurrentUICulture 属性,对
        ///   使用此强类型资源类的所有资源查找执行重写。
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Globalization.CultureInfo Culture {
            get {
                return resourceCulture;
            }
            set {
                resourceCulture = value;
            }
        }
        
        /// <summary>
        ///   查找 System.Drawing.Bitmap 类型的本地化资源。
        /// </summary>
        internal static System.Drawing.Bitmap panel_BottomLeft {
            get {
                object obj = ResourceManager.GetObject("panel_BottomLeft", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }
        
        /// <summary>
        ///   查找 System.Drawing.Bitmap 类型的本地化资源。
        /// </summary>
        internal static System.Drawing.Bitmap panel_BottomMiddle {
            get {
                object obj = ResourceManager.GetObject("panel_BottomMiddle", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }
        
        /// <summary>
        ///   查找 System.Drawing.Bitmap 类型的本地化资源。
        /// </summary>
        internal static System.Drawing.Bitmap panel_BottomRight {
            get {
                object obj = ResourceManager.GetObject("panel_BottomRight", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }
        
        /// <summary>
        ///   查找 System.Drawing.Bitmap 类型的本地化资源。
        /// </summary>
        internal static System.Drawing.Bitmap panel_Left {
            get {
                object obj = ResourceManager.GetObject("panel_Left", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }
        
        /// <summary>
        ///   查找 System.Drawing.Bitmap 类型的本地化资源。
        /// </summary>
        internal static System.Drawing.Bitmap panel_Right {
            get {
                object obj = ResourceManager.GetObject("panel_Right", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }
        
        /// <summary>
        ///   查找 System.Drawing.Bitmap 类型的本地化资源。
        /// </summary>
        internal static System.Drawing.Bitmap panel_TitleLeft {
            get {
                object obj = ResourceManager.GetObject("panel_TitleLeft", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }
        
        /// <summary>
        ///   查找 System.Drawing.Bitmap 类型的本地化资源。
        /// </summary>
        internal static System.Drawing.Bitmap panel_TitleMiddle {
            get {
                object obj = ResourceManager.GetObject("panel_TitleMiddle", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }
        
        /// <summary>
        ///   查找 System.Drawing.Bitmap 类型的本地化资源。
        /// </summary>
        internal static System.Drawing.Bitmap panel_TitleRight {
            get {
                object obj = ResourceManager.GetObject("panel_TitleRight", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }
        
        /// <summary>
        ///   查找 System.Drawing.Bitmap 类型的本地化资源。
        /// </summary>
        internal static System.Drawing.Bitmap pictureBox1_Image {
            get {
                object obj = ResourceManager.GetObject("pictureBox1_Image", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }

        internal static Image GetObject(string v)
        {
            return v switch
            {
                "panel_TitleLeft" => panel_TitleLeft,
                "panel_TitleMiddle" => panel_TitleMiddle,
                "panel_TitleRight" => panel_TitleRight,
                "panel_Left" => panel_Left,
                "panel_Right" => panel_Right,
                "panel_BottomLeft" => panel_BottomLeft,
                "panel_BottomMiddle" => panel_BottomMiddle,
                "panel_BottomRight" => panel_BottomRight,
                "pictureBox1_Image" => pictureBox1_Image,
                _ => null
            };
        }
    }
}

(3)两种获取资源图片的方法

         在程序设计中有两种通过编程获取资源图片的方法,一种是通过GetObject方法,比如:

 panel_Left = new Panel
 {
     //
     BackgroundImage = Resources.GetObject("panel_Left")!,
     BackgroundImageLayout = ImageLayout.Stretch,
     //
 }

        另一种,通过Properties.Resources直接访问指定的资源图片,比如:

panel_Left.BackgroundImage = Properties.Resources.panel_Left;
panel_Left.BackgroundImageLayout = ImageLayout.Stretch;

4.示例

// 手动改变自制窗体的大小
//
using _164.Properties;

namespace _164
{
    public partial class Form1 : Form
    {
        private Panel? panel_BottomRight;
        private Panel? panel_Center;
        private Panel? panel_TitleRight;
        private Panel? panel_BottomLeft;
        private Panel? panel_BottomMiddle;
        private PictureBox? pictureBox1;
        private Panel? panel_TitleLeft;
        private Panel? panel_Right;
        private Panel? panel_Left;
        private Panel? panel_Title;
        private Panel? panel_Bottom;
        private Panel? panel_TitleMiddle;
        private static int example_X = 0;
        private static int example_Y = 0;
        private static int example_W = 0;
        private static Point cPoint;

        public static int Example_X { get => example_X; set => example_X = value; }
        public static int Example_Y { get => example_Y; set => example_Y = value; }
        public static int Example_W { get => example_W; set => example_W = value; }
        public static Point CPoint { get => cPoint; set => cPoint = value; }

        public Form1()
        {
            InitializeComponent();
            StartPosition = FormStartPosition.CenterScreen;
            Load += Form1_Load;
        }

        private void Form1_Load(object? sender, EventArgs e)
        {
            // 
            // panel_Right
            // 
            panel_Right = new Panel
            {
                BackColor = Color.Transparent,
                BackgroundImage = Resources.GetObject("panel_Right")!,
                BackgroundImageLayout = ImageLayout.Stretch,
                Cursor = Cursors.SizeWE,
                Dock = DockStyle.Right,
                Location = new Point(286, 19),
                Name = "panel_Right",
                Size = new Size(6, 96),
                TabIndex = 10
            };
            //panel_Right.MouseDown += new MouseEventHandler(Panel_Right_MouseDown!);
            //panel_Right.MouseMove += new MouseEventHandler(Panel_Right_MouseMove!);
            panel_Right.MouseDown += Panel_Right_MouseDown!;
            panel_Right.MouseMove += Panel_Right_MouseMove!;

            // 
            // panel_Left
            //
            panel_Left = new Panel
            {
                BackColor = Color.Transparent,
                BackgroundImage = Resources.GetObject("panel_Left")!,
                BackgroundImageLayout = ImageLayout.Stretch,
                Dock = DockStyle.Left,
                Location = new Point(0, 19),
                Name = "panel_Left",
                Size = new Size(6, 96),
                TabIndex = 9
            };
            panel_Left.MouseDown += Panel_Right_MouseDown!;
            panel_Left.MouseMove += Panel_Right_MouseMove!;

            // 
            // panel_Center
            // 
            panel_Center = new Panel
            {
                BackColor = Color.Honeydew,
                Dock = DockStyle.Fill,
                Location = new Point(6, 19),
                Name = "panel_Center",
                Size = new Size(280, 96),
                TabIndex = 13
            };

            // 
            // panel_TitleRight
            // 
            panel_TitleRight = new Panel
            {
                BackColor = Color.Transparent,
                BackgroundImage = Resources.GetObject("panel_TitleRight")!,
                BackgroundImageLayout = ImageLayout.Stretch,
                Dock = DockStyle.Right,
                Location = new Point(284, 0),
                Name = "panel_TitleRight",
                Size = new Size(8, 19),
                TabIndex = 1,
                Tag = "3"
            };
            //panel_TitleRight.MouseDown += new MouseEventHandler(Panel_TitleLeft_MouseDown!);
            //panel_TitleRight.MouseMove += new MouseEventHandler(Panel_TitleLeft_MouseMove!);
            panel_TitleRight.MouseDown += Panel_TitleLeft_MouseDown!;
            panel_TitleRight.MouseMove += Panel_TitleLeft_MouseMove!;

            // 
            // pictureBox1
            // 
            pictureBox1 = new PictureBox
            {
                Anchor = AnchorStyles.Top | AnchorStyles.Right, //控件随动
                BackColor = Color.Transparent,
                Visible = true,
                Cursor = Cursors.Hand,
                Image = Resources.GetObject("pictureBox1_Image")!,
                Location = new Point(258, 3),
                Name = "pictureBox1",
                Size = new Size(11, 11),
                TabIndex = 0,
                TabStop = false,
                Tag = "11"
            };
            pictureBox1.Click += PictureBox1_Click!;

            // 
            // panel_TitleMiddle
            // 
            panel_TitleMiddle = new Panel
            {
                BackColor = Color.Transparent,
                BackgroundImage = Resources.GetObject("panel_TitleMiddle")!,
                BackgroundImageLayout = ImageLayout.Stretch,
                Dock = DockStyle.Fill,
                Location = new Point(12, 0),
                Name = "panel_TitleMiddle",
                Size = new Size(272, 19),
                TabIndex = 2,
                Tag = "2"
            };
            panel_TitleMiddle.Controls.Add(pictureBox1);
            panel_TitleMiddle.MouseDown += Panel_TitleLeft_MouseDown!;
            panel_TitleMiddle.MouseMove += Panel_TitleLeft_MouseMove!;

            // 
            // panel_TitleLeft
            // 
            panel_TitleLeft = new Panel
            {
                BackColor = Color.Transparent,
                BackgroundImage = Resources.GetObject("panel_TitleLeft")!,
                BackgroundImageLayout = ImageLayout.Stretch,
                Dock = DockStyle.Left,
                Location = new Point(0, 0),
                Name = "panel_TitleLeft",
                Size = new Size(12, 19),
                TabIndex = 0,
                Tag = "1"
            };
            panel_TitleLeft.MouseDown += Panel_TitleLeft_MouseDown!;
            panel_TitleLeft.MouseMove += Panel_TitleLeft_MouseMove!;

            // 
            // panel_Title
            // 
            panel_Title = new Panel
            {
                BackColor = Color.Transparent,
                Dock = DockStyle.Top,
                Location = new Point(0, 0),
                Name = "panel_Title",
                Size = new Size(292, 19),
                TabIndex = 7
            };
            panel_Title.Controls.Add(panel_TitleMiddle);
            panel_Title.Controls.Add(panel_TitleRight);
            panel_Title.Controls.Add(panel_TitleLeft);
            panel_Title.SuspendLayout();

            // 
            // panel_BottomLeft
            // 
            panel_BottomLeft = new Panel
            {
                BackColor = Color.Transparent,
                BackgroundImage = Resources.GetObject("panel_BottomLeft")!,
                BackgroundImageLayout = ImageLayout.Stretch,
                Cursor = Cursors.SizeNS,
                Dock = DockStyle.Left,
                Location = new Point(0, 0),
                Name = "panel_BottomLeft",
                Size = new Size(8, 10),
                TabIndex = 0
            };

            // 
            // panel_BottomMiddle
            // 
            panel_BottomMiddle = new Panel
            {
                BackColor = Color.Transparent,
                BackgroundImage = Resources.GetObject("panel_BottomMiddle")!,
                BackgroundImageLayout = ImageLayout.Stretch,
                Cursor = Cursors.SizeNS,
                Dock = DockStyle.Fill,
                Location = new Point(8, 0),
                Name = "panel_BottomMiddle",
                Size = new Size(276, 10),
                TabIndex = 2
            };
            panel_BottomMiddle.MouseDown += Panel_Right_MouseDown!;
            panel_BottomMiddle.MouseMove += Panel_Right_MouseMove!;

            // 
            // panel_BottomRight
            // 
            panel_BottomRight = new Panel
            {
                BackColor = Color.Transparent,
                BackgroundImage = Resources.GetObject("panel_BottomRight")!,
                BackgroundImageLayout = ImageLayout.Stretch,
                Cursor = Cursors.SizeNWSE,
                Dock = DockStyle.Right,
                Location = new Point(284, 0),
                Name = "panel_BottomRight",
                Size = new Size(8, 10),
                TabIndex = 1
            };
            panel_BottomRight.MouseDown += Panel_Right_MouseDown!;
            panel_BottomRight.MouseMove += Panel_Right_MouseMove!;

            // 
            // panel_Bottom
            // 
            panel_Bottom = new Panel
            {
                BackColor = Color.Transparent,
                Dock = DockStyle.Bottom,
                Location = new Point(0, 115),
                Name = "panel_Bottom",
                Size = new Size(292, 10),
                TabIndex = 8
            };
            panel_Bottom.Controls.Add(panel_BottomMiddle);
            panel_Bottom.Controls.Add(panel_BottomRight);
            panel_Bottom.Controls.Add(panel_BottomLeft);
            panel_Bottom.SuspendLayout();

            // 
            // Form1
            // 
            AutoScaleDimensions = new SizeF(6F, 12F);
            AutoScaleMode = AutoScaleMode.Font;
            ClientSize = new Size(292, 125);
            Controls.Add(panel_Center);
            Controls.Add(panel_Right);
            Controls.Add(panel_Left);
            Controls.Add(panel_Title);
            Controls.Add(panel_Bottom);
            FormBorderStyle = FormBorderStyle.None;
            Name = "Form1";
            Text = "Form1";
            panel_BottomMiddle.ResumeLayout(false);
            panel_Title.ResumeLayout(false);
            panel_Bottom.ResumeLayout(false);
        }

        #region  利用窗体上的控件移动窗体
        /// <summary>
        /// 利用控件移动窗体
        /// </summary>
        /// <param Frm="Form">窗体</param>
        /// <param e="MouseEventArgs">控件的移动事件</param>
        public static void FormMove(Form Frm, MouseEventArgs e)  //Form或MouseEventArgs添加命名空间using System.Windows.Forms;
        {
            if (e.Button == MouseButtons.Left)
            {
                Point myPosittion = Control.MousePosition;//获取当前鼠标的屏幕坐标
                myPosittion.Offset(CPoint.X, CPoint.Y);//重载当前鼠标的位置
                Frm.DesktopLocation = myPosittion;//设置当前窗体在屏幕上的位置
            }
        }
        #endregion

        #region  获取鼠标的当前位置
        /// <summary>
        /// 获取鼠标的当前位置
        /// </summary>
        /// <param Frm="Form">窗体</param>
        /// <param e="MouseEventArgs">窗体上有关鼠标的一些信息</param>
        public static void FormScreenSizeInfo(Form Frm, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Example_X = e.X;
                Example_Y = e.Y;
                Example_W = Frm.Width;
            }
        }
        #endregion

        #region  改变窗体的大小(用于鼠标的移动事件)
        /// <summary>
        /// 改变窗体的大小(用于鼠标的移动事件)
        /// </summary>
        /// <param Frm="Form">窗体</param>
        /// <param Pan="Panel">设置窗体边框的控件</param>
        /// <param e="MouseEventArgs">窗体上有关鼠标的一些信息</param>
        public void FormScreen_EnlargeSize(Form Frm, Panel Pan, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                switch (Pan.Name)
                {
                    case "panel_Right":		//如果移动的是窗体的右边框
                        {
                            if (Width <= 70)	//如果窗体的宽度小于等于70
                            {
                                Frm.Width = 70;//设置窗体的宽度为70
                                //如果用鼠标向右移动窗体的右边框
                                if (Cursor.Position.X - Frm.Left + (Pan.Width - Example_X) > Frm.Width)
                                {
                                //根据鼠标的移动值,增加窗体的宽度
                                    Frm.Width = Cursor.Position.X - Frm.Left + (Pan.Width - Example_X);
                                }
                                break;
                            }
                            //根据鼠标的移动值,增加窗体的宽度
                            Frm.Width = Cursor.Position.X - Frm.Left + (Pan.Width - Example_X);
                            break;
                        }
                    case "panel_BottomRight":		//如果移动的是窗体的右下角
                        {
                            //如果窗体的大小不为窗体大小的最小值
                            if (Width > 70 && Height > (panel_Title!.Height + panel_BottomMiddle!.Height + 1))
                            {
                                //根据鼠标的移动改变窗体的大小
                                Frm.Height = Cursor.Position.Y - Frm.Top + (Pan.Height - Example_Y);
                                Frm.Width = Cursor.Position.X - Frm.Left + (Pan.Width - Example_X);
                            }
                            else
                            {
                                if (Width <= 70)//如果窗体的宽度小于等于最小值
                                {
                                    Frm.Width = 70;//设置窗体的宽度为70
                                    if (Height <= (panel_Title!.Height + panel_BottomMiddle!.Height + 1))//如果窗体的高小于最小值
                                    {
                                        Frm.Height = panel_Title.Height + panel_BottomMiddle.Height + 1;//设置窗体的最小高度
                                        //如果用鼠标向下移动窗体的底边框
                                        if (Cursor.Position.Y - Frm.Top + (Pan.Height - Example_Y) > Frm.Height)
                                        {
                                            //根据鼠标的移动值,增加窗体的高度
                                            Frm.Height = Cursor.Position.Y - Frm.Top + (Pan.Height - Example_Y);
                                        }
                                        break;
                                    }
                                    //如果用鼠标向右移动窗体
                                    if (Cursor.Position.X - Frm.Left + (Pan.Width - Example_X) > Frm.Width)
                                    {
                                        //增加窗体的宽度
                                        Frm.Width = Cursor.Position.X - Frm.Left + (Pan.Width - Example_X);
                                    }
                                    break;
                                }
                                if (Height <= (panel_Title!.Height + panel_BottomMiddle!.Height + 1))   //如果窗体的高度小于等于最小值
                                {
                                    Frm.Height = panel_Title.Height + panel_BottomMiddle.Height + 1;  //设置窗体的高度为最小值
                                    Frm.Width = Cursor.Position.X - Frm.Left + (Pan.Width - Example_X);//改变窗体的宽度
                                    //如果用鼠标向下移动窗体的边框
                                    if (Cursor.Position.Y - Frm.Top + (Pan.Height - Example_Y) > Frm.Height)
                                    {
                                        Frm.Height = Cursor.Position.Y - Frm.Top + (Pan.Height - Example_Y);//增加窗体的高度
                                    }
                                    break;
                                }
                            }
                            break;
                        }
                    case "panel_BottomMiddle"://如果移动的是窗体的底边框
                        {
                            if (Height <= (panel_Title!.Height + panel_BottomMiddle!.Height + 1))//如果窗体的高度小于等于最小值
                            {
                                Frm.Height = panel_Title.Height + panel_BottomMiddle.Height + 1;//设置窗体的高度为最小值
                                //如果用鼠标向下移动窗体的下边框
                                if (Cursor.Position.Y - Frm.Top + (Pan.Height - Example_Y) > Frm.Height)
                                {
                                    Frm.Height = Cursor.Position.Y - Frm.Top + (Pan.Height - Example_Y);	//增加窗体的高度
                                }
                                break;
                            }
                            Frm.Height = Cursor.Position.Y - Frm.Top + (Pan.Height - Example_Y);			//增加窗体的高度
                            break;
                        }
                }
            }
        }
        #endregion

        private void Panel_Right_MouseDown(object sender, MouseEventArgs e)
        {
            FormScreenSizeInfo(this, e);//获取鼠标的当前位置
        }

        private void Panel_Right_MouseMove(object sender, MouseEventArgs e)
        {
            FormScreen_EnlargeSize(this, (Panel)sender, e);//改变窗体的大小
        }

        private void PictureBox1_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void Panel_TitleLeft_MouseDown(object sender, MouseEventArgs e)
        {
            int Tem_X = -e.X;
            if (Convert.ToInt16(((Panel)sender).Tag!.ToString()) == 2)//如果移动的是标题栏的中间部分
                Tem_X = -e.X - panel_TitleLeft!.Width;
            if (Convert.ToInt16(((Panel)sender).Tag!.ToString()) == 3)//如果移动的是标题栏的尾端
                Tem_X = -(Width - ((Panel)sender).Width) - e.X;
            CPoint = new Point(Tem_X, -e.Y);
        }

        private void Panel_TitleLeft_MouseMove(object sender, MouseEventArgs e)
        {
            FormMove(this, e);
        }
    }
}

 

 

 

标签:C#,自制,System,窗体,new,panel,Resources,Panel
From: https://blog.csdn.net/wenchm/article/details/137027140

相关文章

  • 图像分类实战:深度学习在CIFAR-10数据集上的应用
    1.前言        图像分类是计算机视觉领域的一个核心任务,算法能够自动识别图像中的物体或场景,并将其归类到预定义的类别中。近年来,深度学习技术的发展极大地推动了图像分类领域的进步。CIFAR-10数据集作为计算机视觉领域的一个经典小型数据集,为研究者提供了一个理想的......
  • CrossOver2024最新免费版虚拟机软件 Mac和Linux系统上运行Windows 应用/游戏 CrossOve
    CrossOver是一款由CodeWeavers公司开发的,运行在Mac和Linux操作系统下,能够模拟Windows系统应用运行环境的软件。它不需要用户单独安装Windows操作系统,就能让Windows平台上的应用程序在Mac和Linux上顺畅运行。CrossOver在技术上使用了Wine(Windows模拟器)的代码,通过提供一个兼容层,......
  • 基于深度学习的OCR,如何解决图像像素差的问题?
    基于深度学习的OCR技术在处理图像像素差的问题时确实面临一定的挑战。图像像素差可能导致OCR系统无法准确识别文本,从而影响其精度和可靠性。尽管已经有一些方法如SRN-Deblur、超分SR和GAN系列被尝试用于解决这个问题,但效果并不理想。然而,这并不意味着这个问题无解。以下是一......
  • 发票是扫码验真好,还是OCR后进行验真好?
    随着科技的进步,电子发票的普及使得发票的验真方式也在不断演进。目前,我们常见的发票验真方式主要有两种:一种是扫描发票上的二维码进行验真,另一种是通过OCR(OpticalCharacterRecognition,光学字符识别)技术识别发票上的文字信息,再根据这些信息去税务局进行查验。那么,为何在有了二......
  • 京东一面挂在了CAS算法的三大问题上,痛定思痛不做同一个知识点的小丑
    写在开头在介绍synchronized关键字时,我们提到了锁升级时所用到的CAS算法,那么今天我们就来好好学一学这个CAS算法。CAS算法对build哥来说,可谓是刻骨铭心,记得是研二去找实习的时候,当时对很多八股文的内容浅尝辄止,很多深奥的知识点只是知道个概念,源码看的也不深,代码量也不够,京东一......
  • Java static(1)
    类变量与类一起加载一次,在内存中保留一份,可以被类和所有的对象共享。实例变量实例变量属于对象,每个对象都有一份,只能被对象访问。publicclassTestStatic{publicstaticvoidmain(String[]args){Student1.name="张三";Student1student1......
  • centos7提示 file /root/.serverauth.13703 does not exist
    情况背景:安装虚拟数据服务器,使用系统为centos7,安装完成后,开始安装图形化程序,在虚拟服务器上一切正常,输入startx也会正常显示图形操作界面问题来源:现在通过其他电脑远程连接虚拟数据服务器,输入地址进入也是正常,但是输入“startx”命令后就显示失败代码,无法进入图形操作界面,如......
  • java Web洗衣店管理系统用eclipse定制开发mysql数据库BS模式java编程jdbc
    一、源码特点   JSP洗衣店管理系统是一套完善的web设计系统,对理解JSPjava编程开发语言有帮助,系统具有完整的源代码和数据库,系统主要采用B/S模式开发。开发环境为TOMCAT7.0,eclipse开发,数据库为Mysql5.0,使用java语言开发。javaWeb洗衣店管理系统二、功能介绍(......
  • java Web 疫苗预约管理系统用eclipse定制开发mysql数据库BS模式java编程jdbc
    一、源码特点   JSP疫苗预约管理系统是一套完善的web设计系统,对理解JSPjava编程开发语言有帮助,系统具有完整的源代码和数据库,系统主要采用B/S模式开发。开发环境为TOMCAT7.0,eclipse开发,数据库为Mysql5.0,使用java语言开发。javaWeb疫苗预约管理系统二、功能介......
  • 接收文件流并导出至excel以及对二进制文件流内容的校验
    废话不说上代码consthandleRightDownload=async()=>{axios({method:'post',url:'/my/handleAndDownloadExcel',//请求地址这里写后端的地址,注意加上`/api`以确保最终的请求能被替换掉,/api表示server要替换的前缀'/api'->''data:{......