C#仿OutLook的特色窗体设计

2024-04-04 16:36

本文主要是介绍C#仿OutLook的特色窗体设计,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录

1. 资源图片准备

2. 设计流程:

(1)用MenuStrip控件设计菜单栏

(2)用ToolStrip控件设计工具栏

(3)用StatusStrip控件设计状态栏

(4)ImageList组件装载树节点图标

(5)用TreeView控件和ImageList组件设计模型树

3.示例

(1)Form1.cs

(2)Form1.Designer.cs

(3)Resources.Designer.cs

(4)效果图


        用MenuStrip控件、ToolStrip控件、StatusStrip控件、TreeView控件、ImageList组件设计模仿OutLook风格的特色窗体。

1. 资源图片准备

        设计之前,先准备好资源图片,根据工具栏的按钮数量准备图片,根据模型树里节点的数量准备相应数量的图标文件。

        资源图片和图标的加载到项目中的方法,详见本文作者的其他文章:C#手动改变自制窗体的大小-CSDN博客  https://wenchm.blog.csdn.net/article/details/137027140

        资源图片和图标要分别加载。

2. 设计流程:

(1)用MenuStrip控件设计菜单栏

        通过加载MenuStrip控件,按照提示生成toolStripMenuItem1、toolStripMenuItem2、toolStripMenuItem3。依次修改其Text属性为“打开”、“设置”、“编辑”。

menuStrip1 = new MenuStrip();
toolStripMenuItem1 = new ToolStripMenuItem();
toolStripMenuItem2 = new ToolStripMenuItem();
toolStripMenuItem3 = new ToolStripMenuItem();
//
toolStripMenuItem1.Text = "打开";
//
toolStripMenuItem2.Text = "设置";
//
toolStripMenuItem3.Text = "编辑";

(2)用ToolStrip控件设计工具栏

        通过加载ToolStrip控件,按照提示生成toolStripButton1、toolStripButton2、toolStripButton3、toolStripComboBox1。依次修改其Text属性为“打开”、“设置”、“编辑”,依次修改其Image属性为资源文件的“打开1”、“设置1”、“编辑1”。

toolStrip1 = new ToolStrip();
toolStripButton1 = new ToolStripButton();
toolStripButton2 = new ToolStripButton();
toolStripButton3 = new ToolStripButton();
toolStripComboBox1 = new ToolStripComboBox();
//
toolStripButton1.Image = Properties.Resources.打开1;
toolStripButton1.Text = "打开";
//
toolStripButton2.Image = Properties.Resources.设置1;
toolStripButton2.Text = "设置";
//
toolStripButton3.Image = Properties.Resources.编辑1;
toolStripButton3.Text = "编辑";

(3)用StatusStrip控件设计状态栏

        通过加载ToolStrip控件,按照提示生成状态标签toolStripStatusLabel1,并修改其Text属性为“操作员***”。

 toolStripStatusLabel1.Name = "toolStripStatusLabel1";toolStripStatusLabel1.Text = "操作员***";

(4)ImageList组件装载树节点图标

        通过加载ImageList组件装在项目需要的图标,生成文件文件imageList1,鼠标点中该组件,右侧属性,选择图像开始装在图片,图片按Tag自动索引。或者鼠标点中该组件,该组件的右上角显示实心的箭头,点击箭头,开始选择图片,这里为根节点、子节点选择项目准备好的图标文件。

 

(5)用TreeView控件和ImageList组件设计模型树

         通过加载TreeView控件为项目创建模型树,鼠标点中TreeView控件,在该空间的右上角出现一个箭头,点击箭头,为该控件装载图标文件imageList1。或者鼠标点中TreeView控件,右侧属性,修改其Image属性为imageList1。然后,选择“编辑节点”,为项目创建根节点和各个子节点。给节点更名和配图。

3.示例

(1)Form1.cs

// Form1.cs
namespace _175
{public partial class Form1 : Form{public Form1(){InitializeComponent();}}
}

(2)Form1.Designer.cs

// 仿OutLook的特色窗体
namespace _175
{partial class Form1{/// <summary>///  Required designer variable./// </summary>private System.ComponentModel.IContainer components = null;/// <summary>///  Clean up any resources being used./// </summary>/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>protected override void Dispose(bool disposing){if (disposing && (components != null)){components.Dispose();}base.Dispose(disposing);}#region Windows Form Designer generated code/// <summary>///  Required method for Designer support - do not modify///  the contents of this method with the code editor./// </summary>private void InitializeComponent(){components = new System.ComponentModel.Container();System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));TreeNode treeNode1 = new TreeNode("打开");TreeNode treeNode2 = new TreeNode("设置");TreeNode treeNode3 = new TreeNode("编辑");TreeNode treeNode4 = new TreeNode("菜单项", new TreeNode[] { treeNode1, treeNode2, treeNode3 });menuStrip1 = new MenuStrip();toolStripMenuItem1 = new ToolStripMenuItem();toolStripMenuItem2 = new ToolStripMenuItem();toolStripMenuItem3 = new ToolStripMenuItem();toolStrip1 = new ToolStrip();toolStripButton1 = new ToolStripButton();toolStripButton2 = new ToolStripButton();toolStripButton3 = new ToolStripButton();toolStripComboBox1 = new ToolStripComboBox();statusStrip1 = new StatusStrip();toolStripStatusLabel1 = new ToolStripStatusLabel();imageList1 = new ImageList(components);treeView1 = new TreeView();menuStrip1.SuspendLayout();toolStrip1.SuspendLayout();statusStrip1.SuspendLayout();SuspendLayout();// // menuStrip1// menuStrip1.Items.AddRange(new ToolStripItem[] { toolStripMenuItem1, toolStripMenuItem2, toolStripMenuItem3 });menuStrip1.Location = new Point(0, 0);menuStrip1.Name = "menuStrip1";menuStrip1.Size = new Size(309, 25);menuStrip1.TabIndex = 0;menuStrip1.Text = "menuStrip1";// // toolStripMenuItem1// toolStripMenuItem1.Name = "toolStripMenuItem1";toolStripMenuItem1.Size = new Size(44, 21);toolStripMenuItem1.Text = "打开";// // toolStripMenuItem2// toolStripMenuItem2.Name = "toolStripMenuItem2";toolStripMenuItem2.Size = new Size(44, 21);toolStripMenuItem2.Text = "设置";// // toolStripMenuItem3// toolStripMenuItem3.Name = "toolStripMenuItem3";toolStripMenuItem3.Size = new Size(44, 21);toolStripMenuItem3.Text = "编辑";// // toolStrip1// toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripButton1, toolStripButton2, toolStripButton3, toolStripComboBox1 });toolStrip1.Location = new Point(0, 25);toolStrip1.Name = "toolStrip1";toolStrip1.Size = new Size(309, 25);toolStrip1.TabIndex = 1;toolStrip1.Text = "toolStrip1";// // toolStripButton1// toolStripButton1.Image = Properties.Resources.打开1;toolStripButton1.ImageTransparentColor = Color.Magenta;toolStripButton1.Name = "toolStripButton1";toolStripButton1.Size = new Size(52, 22);toolStripButton1.Text = "打开";// // toolStripButton2// toolStripButton2.Image = Properties.Resources.设置1;toolStripButton2.ImageTransparentColor = Color.Magenta;toolStripButton2.Name = "toolStripButton2";toolStripButton2.Size = new Size(52, 22);toolStripButton2.Text = "设置";// // toolStripButton3// toolStripButton3.Image = Properties.Resources.编辑1;toolStripButton3.ImageTransparentColor = Color.Magenta;toolStripButton3.Name = "toolStripButton3";toolStripButton3.Size = new Size(52, 22);toolStripButton3.Text = "编辑";// // toolStripComboBox1// toolStripComboBox1.Name = "toolStripComboBox1";toolStripComboBox1.Size = new Size(121, 25);// // statusStrip1// statusStrip1.Items.AddRange(new ToolStripItem[] { toolStripStatusLabel1 });statusStrip1.Location = new Point(0, 169);statusStrip1.Name = "statusStrip1";statusStrip1.Size = new Size(309, 22);statusStrip1.TabIndex = 2;statusStrip1.Text = "statusStrip1";// // toolStripStatusLabel1// toolStripStatusLabel1.Name = "toolStripStatusLabel1";toolStripStatusLabel1.Size = new Size(59, 17);toolStripStatusLabel1.Text = "操作员***";// // imageList1// imageList1.ColorDepth = ColorDepth.Depth32Bit;imageList1.ImageStream = (ImageListStreamer)resources.GetObject("imageList1.ImageStream");imageList1.TransparentColor = Color.Transparent;imageList1.Images.SetKeyName(0, "打开.ico");imageList1.Images.SetKeyName(1, "打开.ico");imageList1.Images.SetKeyName(2, "设置.ico");imageList1.Images.SetKeyName(3, "编辑.ico");// // treeView1// treeView1.ImageIndex = 0;treeView1.ImageList = imageList1;treeView1.Location = new Point(2, 52);treeView1.Name = "treeView1";treeNode1.ImageIndex = 1;treeNode1.Name = "节点1";treeNode1.Text = "打开";treeNode2.ImageIndex = 2;treeNode2.Name = "节点2";treeNode2.Text = "设置";treeNode3.ImageIndex = 3;treeNode3.Name = "节点3";treeNode3.Text = "编辑";treeNode4.ImageIndex = 0;treeNode4.Name = "节点0";treeNode4.Text = "菜单项";treeView1.Nodes.AddRange(new TreeNode[] { treeNode4 });treeView1.SelectedImageIndex = 0;treeView1.Size = new Size(307, 114);treeView1.TabIndex = 3;// // Form1// AutoScaleDimensions = new SizeF(7F, 17F);AutoScaleMode = AutoScaleMode.Font;ClientSize = new Size(309, 191);Controls.Add(treeView1);Controls.Add(statusStrip1);Controls.Add(toolStrip1);Controls.Add(menuStrip1);FormBorderStyle = FormBorderStyle.Fixed3D;MainMenuStrip = menuStrip1;Name = "Form1";StartPosition = FormStartPosition.CenterScreen;Text = "Form1";menuStrip1.ResumeLayout(false);menuStrip1.PerformLayout();toolStrip1.ResumeLayout(false);toolStrip1.PerformLayout();statusStrip1.ResumeLayout(false);statusStrip1.PerformLayout();ResumeLayout(false);PerformLayout();}#endregionprivate MenuStrip menuStrip1;private ToolStrip toolStrip1;private StatusStrip statusStrip1;private ImageList imageList1;private TreeView treeView1;private ToolStripMenuItem toolStripMenuItem1;private ToolStripMenuItem toolStripMenuItem2;private ToolStripMenuItem toolStripMenuItem3;private ToolStripButton toolStripButton1;private ToolStripButton toolStripButton2;private ToolStripButton toolStripButton3;private ToolStripStatusLabel toolStripStatusLabel1;private ToolStripComboBox toolStripComboBox1;}
}

(3)Resources.Designer.cs

//------------------------------------------------------------------------------
// <auto-generated>
//     此代码由工具生成。
//     运行时版本:4.0.30319.42000
//
//     对此文件的更改可能会导致不正确的行为,并且如果
//     重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------namespace _175.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("_175.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.Icon 类型的本地化资源。/// </summary>internal static System.Drawing.Icon 打开 {get {object obj = ResourceManager.GetObject("打开", resourceCulture);return ((System.Drawing.Icon)(obj));}}internal static System.Drawing.Bitmap 打开1{get{object obj = ResourceManager.GetObject("打开1", resourceCulture);return ((System.Drawing.Bitmap)(obj));}}/// <summary>///   查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。/// </summary>internal static System.Drawing.Icon 编辑 {get {object obj = ResourceManager.GetObject("编辑", resourceCulture);return ((System.Drawing.Icon)(obj));}}internal static System.Drawing.Bitmap 编辑1{get{object obj = ResourceManager.GetObject("编辑1", resourceCulture);return ((System.Drawing.Bitmap)(obj));}}/// <summary>///   查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。/// </summary>internal static System.Drawing.Icon 设置 {get {object obj = ResourceManager.GetObject("设置", resourceCulture);return ((System.Drawing.Icon)(obj));}}internal static System.Drawing.Bitmap 设置1{get{object obj = ResourceManager.GetObject("设置1", resourceCulture);return ((System.Drawing.Bitmap)(obj));}}}
}

(4)效果图

 

这篇关于C#仿OutLook的特色窗体设计的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/876294

相关文章

C#如何去掉文件夹或文件名非法字符

《C#如何去掉文件夹或文件名非法字符》:本文主要介绍C#如何去掉文件夹或文件名非法字符的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录C#去掉文件夹或文件名非法字符net类库提供了非法字符的数组这里还有个小窍门总结C#去掉文件夹或文件名非法字符实现有输入字

C#之List集合去重复对象的实现方法

《C#之List集合去重复对象的实现方法》:本文主要介绍C#之List集合去重复对象的实现方法,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录C# List集合去重复对象方法1、测试数据2、测试数据3、知识点补充总结C# List集合去重复对象方法1、测试数据

C#实现将Office文档(Word/Excel/PDF/PPT)转为Markdown格式

《C#实现将Office文档(Word/Excel/PDF/PPT)转为Markdown格式》Markdown凭借简洁的语法、优良的可读性,以及对版本控制系统的高度兼容性,逐渐成为最受欢迎的文档格式... 目录为什么要将文档转换为 Markdown 格式使用工具将 Word 文档转换为 Markdown(.

MyBatis设计SQL返回布尔值(Boolean)的常见方法

《MyBatis设计SQL返回布尔值(Boolean)的常见方法》这篇文章主要为大家详细介绍了MyBatis设计SQL返回布尔值(Boolean)的几种常见方法,文中的示例代码讲解详细,感兴趣的小伙伴... 目录方案一:使用COUNT查询存在性(推荐)方案二:条件表达式直接返回布尔方案三:存在性检查(EXI

Java调用C#动态库的三种方法详解

《Java调用C#动态库的三种方法详解》在这个多语言编程的时代,Java和C#就像两位才华横溢的舞者,各自在不同的舞台上展现着独特的魅力,然而,当它们携手合作时,又会碰撞出怎样绚丽的火花呢?今天,我们... 目录方法1:C++/CLI搭建桥梁——Java ↔ C# 的“翻译官”步骤1:创建C#类库(.NET

C#代码实现解析WTGPS和BD数据

《C#代码实现解析WTGPS和BD数据》在现代的导航与定位应用中,准确解析GPS和北斗(BD)等卫星定位数据至关重要,本文将使用C#语言实现解析WTGPS和BD数据,需要的可以了解下... 目录一、代码结构概览1. 核心解析方法2. 位置信息解析3. 经纬度转换方法4. 日期和时间戳解析5. 辅助方法二、L

使用C#删除Excel表格中的重复行数据的代码详解

《使用C#删除Excel表格中的重复行数据的代码详解》重复行是指在Excel表格中完全相同的多行数据,删除这些重复行至关重要,因为它们不仅会干扰数据分析,还可能导致错误的决策和结论,所以本文给大家介绍... 目录简介使用工具C# 删除Excel工作表中的重复行语法工作原理实现代码C# 删除指定Excel单元

C#使用MQTTnet实现服务端与客户端的通讯的示例

《C#使用MQTTnet实现服务端与客户端的通讯的示例》本文主要介绍了C#使用MQTTnet实现服务端与客户端的通讯的示例,包括协议特性、连接管理、QoS机制和安全策略,具有一定的参考价值,感兴趣的可... 目录一、MQTT 协议简介二、MQTT 协议核心特性三、MQTTNET 库的核心功能四、服务端(BR

C#继承之里氏替换原则分析

《C#继承之里氏替换原则分析》:本文主要介绍C#继承之里氏替换原则,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录C#里氏替换原则一.概念二.语法表现三.类型检查与转换总结C#里氏替换原则一.概念里氏替换原则是面向对象设计的基本原则之一:核心思想:所有引py

C#实现访问远程硬盘的图文教程

《C#实现访问远程硬盘的图文教程》在现实场景中,我们经常用到远程桌面功能,而在某些场景下,我们需要使用类似的远程硬盘功能,这样能非常方便地操作对方电脑磁盘的目录、以及传送文件,这次我们将给出一个完整的... 目录引言一. 远程硬盘功能展示二. 远程硬盘代码实现1. 底层业务通信实现2. UI 实现三. De