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

目录

1.Cursor类的Position属性

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

3.Resources设计

(1)Resources资源图片管理

(2)GetObject方法设计

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资源图片管理

(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};}}
}

4.示例

// 手动改变自制窗体的大小
using _164.Properties;namespace _164
{public partial class Form1 : Form{private Panel? panel_BR;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();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_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 += new MouseEventHandler(Panel_Right_MouseDown!);panel_Left.MouseMove += new MouseEventHandler(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_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 += new MouseEventHandler(Panel_TitleLeft_MouseDown!);panel_TitleMiddle.MouseMove += new MouseEventHandler(Panel_TitleLeft_MouseMove!);panel_TitleMiddle.SuspendLayout();// // pictureBox1// pictureBox1 = new PictureBox{Anchor = AnchorStyles.Top | AnchorStyles.Right,BackColor = Color.Transparent,Cursor = Cursors.Hand,Image = Resources.GetObject("pictureBox1.Image")!,SizeMode = PictureBoxSizeMode.StretchImage,Location = new Point(260, 3),Name = "pictureBox1",Size = new Size(11, 11),TabIndex = 0,TabStop = false,Tag = "11"};pictureBox1.Click += new EventHandler(PictureBox1_Click!);// // 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 += new MouseEventHandler(Panel_TitleLeft_MouseDown!);panel_TitleLeft.MouseMove += new MouseEventHandler(Panel_TitleLeft_MouseMove!);// // 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_Bn",Size = new Size(276, 10),TabIndex = 2};panel_BottomMiddle.MouseDown += new MouseEventHandler(Panel_Right_MouseDown!);panel_BottomMiddle.MouseMove += new MouseEventHandler(Panel_Right_MouseMove!);// // panel_BottomRight// panel_BR = 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_BR",Size = new Size(8, 10),TabIndex = 1};panel_BR.MouseDown += new MouseEventHandler(Panel_Right_MouseDown!);panel_BR.MouseMove += new MouseEventHandler(Panel_Right_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_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_BR);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_BR":						//如果移动的是窗体的右下角{//如果窗体的大小不为窗体大小的最小值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;			//设置窗体的宽度为70if (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_Bn"://如果移动的是窗体的底边框{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;}}}}#endregionprivate 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);}}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/770217.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[综述笔记]Flexible large-scale fMRI analysis: A survey

论文网址&#xff1a;Flexible large-scale fMRI analysis: A survey | IEEE Conference Publication | IEEE Xplore 英文是纯手打的&#xff01;论文原文的summarizing and paraphrasing。可能会出现难以避免的拼写错误和语法错误&#xff0c;若有发现欢迎评论指正&#xff0…

关于网格数据导出指定格式的测试(以Gmsh导出nas格式为例)

本文主要讲述Gmsh如何导出nas格式的网格数据&#xff0c;众所周知&#xff0c;Gmsh可以导出多种网格数据格式&#xff0c;比如大家熟悉的msh、stl、inp、cgns&#xff08;似乎不完善&#xff09;等等&#xff0c;但是gmsh不支持nas格式的导出&#xff0c;只支持nas格式的导入&a…

银行量子金融系统应用架构设计

量子金融&#xff08;即Financial-Quantum&#xff0c;简称Fin-Q&#xff09;&#xff0c;特指量子科技在金融行业中的应用。 目前&#xff0c;量子科技中以量子保密通信、量子随机数和量子计算发展进度较快&#xff0c;取得了诸多阶段性重大技术突破和商用成果&#xff0c;这…

Linux Ncurses库部分函数使用说明

目录 1. initscr&#xff08;&#xff09;函数 2. endwin&#xff08;&#xff09;函数 3. curs_set()函数 4.noecho()函数 5. keypad()函数 6. start_color()函数 7.init_pair()函数 8.getch()函数 9.move()函数 10.addch()函数 11. refresh()函数 12.inch()函数…

1072. 按列翻转得到最大值等行数

文章目录 题意思路代码 题意 题目链接 可以翻转任意列&#xff0c;求全是1和全是0的行&#xff0c;最多有多少行。 思路 对一行而言&#xff0c;能翻转成相同的&#xff08;同为1&#xff0c;或者同为0&#xff09;&#xff0c;则相等。能反转成相反的&#xff0c;则巧好&am…

实战|使用 Node.js 和 htmx 构建全栈应用程序

在本教程中&#xff0c;我将演示如何使用 Node 作为后端和 htmx 作为前端来构建功能齐全的 CRUD 应用程序。这将演示 htmx 如何集成到全栈应用程序中&#xff0c;使您能够评估其有效性并确定它是否是您未来项目的不错选择。 htmx 是一个现代 JavaScript 库&#xff0c;旨在通过…

刘亦菲式能量保护法

➊睡到没有起床气才起来的10小时姑娘 有一次有人问刘亦菲有没有起床气&#xff0c;她调皮地回答&#xff1a;我一般都是睡到不气才起 没错&#xff0c;这位神仙姐姐连睡觉都是一种仙气 看回她以前的社交账号&#xff0c;不是在睡觉就是在赶往梦乡的路上&#xff0c;高铁上、房车…

多叉树题目:N 叉树的前序遍历

文章目录 题目标题和出处难度题目描述要求示例数据范围进阶 解法一思路和算法代码复杂度分析 解法二思路和算法代码复杂度分析 解法三思路和算法代码复杂度分析 题目 标题和出处 标题&#xff1a;N 叉树的前序遍历 出处&#xff1a;589. N 叉树的前序遍历 难度 3 级 题目…

vue/js总结合集

vuex的五大核心 内容作用映射位置调用其它state设置状态mapStatecomputedgetters获取内容mapGetterscomputed计算数据后返回mutations修改数据mapMutationsmethodscommit可以异步&#xff08;不建议&#xff09;不利于调试actions异步操作mapActionsmethodsdispatchmodules模块…

Docker 中安装 Redis

要在 Docker 中安装 Redis&#xff0c;你可以按照以下步骤进行操作&#xff1a; 拉取 Redis 镜像&#xff1a;在命令行中执行以下命令&#xff0c;从 Docker Hub 上拉取 Redis 镜像&#xff1a; docker pull redis 运行 Redis 容器&#xff1a;执行以下命令来在 Docker 中运行…

一文速通自监督学习(Self-supervised Learning):教机器自我探索的艺术

一文速通自监督学习&#xff08;Self-supervised Learning&#xff09;&#xff1a;教机器自我探索的艺术 前言自监督学习是什么&#xff1f;自监督学习的魔力常见的自监督学习方法1. 对比学习2. 预测缺失部分3. 旋转识别4. 时间顺序预测 结语 &#x1f308;你好呀&#xff01;…

蓝桥杯单片机快速开发笔记——特训1 LED闪烁和数码管同步显示

一、示例题目&#xff1a; 在CT107D单片机综合训练平台上&#xff0c;通过I/O模式编写代码&#xff0c;实现以下功能&#xff1a; 系统上电后&#xff0c;初始状态为关闭蜂鸣器、继电器、全部指示灯和数码管&#xff0c;然后进入循环&#xff0c;实现灯光闪烁和数码管计数。数…

代码随想录Day32

Day 32 贪心算法 Part03 今日任务 1005.K次取反后最大化的数组和 加油站 分发糖果 代码实现 1005.K次取反后最大化的数组和 这题有点思路&#xff0c;和题解也差不多&#xff0c;但是没完全通&#xff0c;感觉很复杂&#xff0c;无法下手 public int largestSumAfterKNeg…

Docker新手攻略:编辑Dockerfile、构建镜像、启动容器全攻略

万能dockerfile编写模板文件 FROM openjdk:11.0 as builder WORKDIR application ARG JAR_FILEtarget/*.jar COPY ${JAR_FILE} application.jar RUN java -Djarmodelayertools -jar application.jar extractFROM openjdk:11.0 WORKDIR application COPY --frombuilder applica…

Springboot项目结构

1. 一个正常的企业项目里一种通用的项目结构和代码层级划分的指导意见&#xff1a; 一般分为如下几层&#xff1a; 开放接口层 终端显示层 Web 层 Service 层 Manager 层 DAO 层 外部接口或第三方平台 2. 以当下非常火热的Spring Boot典型项目结构为例&#xff0c;创建出…

typeScript3(数组类型)

类型[ ] let arr: number[] [1,2,3] //数字类型的数组 let arr:string[] [1, 2] //字符串类型的数组 let arr:any[] [1,2,false] //任意类型的数组 数组泛型 Array<类型> let arr:Array<number> [1,2,3] 接口表示数组 //只要索引的类型是数字时&#xff0c;那…

Java基础---IO流习题

使用对象IO流简单练习一个图书管理系统 Book类&#xff08;书类&#xff09; package day2024_03_21.pojo;import java.io.Serializable;public class Book implements Serializable {private static final long serialVersionUID 1L;private Integer BookId;private Stri…

import * as的使用

import * as 是将一个模块的所有导出内容作为一个命名空间对象导入到当前模块中&#xff0c;其中 * 表示导入该模块中的所有导出内容&#xff0c;而 as 则用于指定导入的命名空间对象的名称。 例如&#xff1a;在 formatter 文件中有两个方法导出 const a () > {console.…

代码随想录算法训练营第三十四天 |1005. K 次取反后最大化的数组和 、134. 加油站、135. 分发糖果

代码随想录算法训练营第三十四天 |1005. K 次取反后最大化的数组和 、134. 加油站、135. 分发糖果 1005. K 次取反后最大化的数组和题目解法 134. 加油站题目解法 135. 分发糖果题目解法 感悟 1005. K 次取反后最大化的数组和 题目 解法 考虑绝对值 class Solution { public…