C#设计树形程序界面的方法:创建特殊窗体

目录

1.TreeView控件

2.实例 

(1)Resources.Designer.cs

(2)Form1.Designer.cs

(3)Form1.cs

(4)生成效果


        以树形来显示程序的菜单,可以更直观、更快捷地对窗体进行操作,而且树型菜单比菜单栏更加美观实用。

1.TreeView控件

        TreeView控件又称为树控件,它可以为用户显示节点层次结构,而每个节点又可以包含子节点,包含子节点的节点叫父节点,其效果就像在Windows操作系统的Windows资源管理器功能的左窗口中显示文件和文件夹一样。TreeView控件的ExpandAll方法用来展开所有树节点,语法格式如下:

public void ExpandAll()

        TreeView控件经常用来设计Windows窗体的左侧导航菜单。

2.实例 

        本实例在制作以树形显示的程序界面时,主要用TreeView控件及其ExpandAll方法。 

(1)Resources.Designer.cs

//------------------------------------------------------------------------------
// <auto-generated>
//     此代码由工具生成。
//     运行时版本:4.0.30319.42000
//
//     对此文件的更改可能会导致不正确的行为,并且如果
//     重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------

namespace _194.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("_194.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 上 {
            get {
                object obj = ResourceManager.GetObject("上", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }
        
        /// <summary>
        ///   查找 System.Drawing.Bitmap 类型的本地化资源。
        /// </summary>
        internal static System.Drawing.Bitmap 右 {
            get {
                object obj = ResourceManager.GetObject("右", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }
    }
}

(2)Form1.Designer.cs

namespace _194
{
    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()
        {
            TreeNode treeNode1 = new TreeNode("企业类型设置");
            TreeNode treeNode2 = new TreeNode("企业性质设置");
            TreeNode treeNode3 = new TreeNode("企业级别设置");
            TreeNode treeNode4 = new TreeNode("企业资信设置");
            TreeNode treeNode5 = new TreeNode("基础信息维护", new TreeNode[] { treeNode1, treeNode2, treeNode3, treeNode4 });
            TreeNode treeNode6 = new TreeNode("客户信息");
            TreeNode treeNode7 = new TreeNode("联系人信息");
            TreeNode treeNode8 = new TreeNode("业务往来");
            TreeNode treeNode9 = new TreeNode("客户信息维护", new TreeNode[] { treeNode6, treeNode7, treeNode8 });
            TreeNode treeNode10 = new TreeNode("客户投诉");
            TreeNode treeNode11 = new TreeNode("客户反馈");
            TreeNode treeNode12 = new TreeNode("客户服务", new TreeNode[] { treeNode10, treeNode11 });
            TreeNode treeNode13 = new TreeNode("联系人信息查询");
            TreeNode treeNode14 = new TreeNode("客户信息查询");
            TreeNode treeNode15 = new TreeNode("客户信息查询", new TreeNode[] { treeNode13, treeNode14 });
            TreeNode treeNode16 = new TreeNode("客户信息报表");
            TreeNode treeNode17 = new TreeNode("业务往来报表");
            TreeNode treeNode18 = new TreeNode("联系人信息表");
            TreeNode treeNode19 = new TreeNode("打印报表", new TreeNode[] { treeNode16, treeNode17, treeNode18 });
            TreeNode treeNode20 = new TreeNode("调用Word");
            TreeNode treeNode21 = new TreeNode("调用EXCEL");
            TreeNode treeNode22 = new TreeNode("辅助工具", new TreeNode[] { treeNode20, treeNode21 });
            menuStrip1 = new MenuStrip();
            toolStripMenuItem2 = new ToolStripMenuItem();
            toolStripMenuItem3 = new ToolStripMenuItem();
            toolStripMenuItem4 = new ToolStripMenuItem();
            toolStripMenuItem1 = new ToolStripMenuItem();
            panel1 = new Panel();
            splitContainer1 = new SplitContainer();
            treeView1 = new TreeView();
            pictureBox1 = new PictureBox();
            menuStrip1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit();
            splitContainer1.Panel1.SuspendLayout();
            splitContainer1.Panel2.SuspendLayout();
            splitContainer1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
            SuspendLayout();
            // 
            // menuStrip1
            // 
            menuStrip1.Dock = DockStyle.None;
            menuStrip1.Items.AddRange(new ToolStripItem[] { toolStripMenuItem2, toolStripMenuItem3, toolStripMenuItem4, toolStripMenuItem1 });
            menuStrip1.Location = new Point(0, 0);
            menuStrip1.Name = "menuStrip1";
            menuStrip1.Size = new Size(352, 25);
            menuStrip1.TabIndex = 0;
            menuStrip1.Text = "menuStrip1";
            // 
            // toolStripMenuItem2
            // 
            toolStripMenuItem2.Name = "toolStripMenuItem2";
            toolStripMenuItem2.Size = new Size(92, 21);
            toolStripMenuItem2.Text = "客户信息维护";
            // 
            // toolStripMenuItem3
            // 
            toolStripMenuItem3.Name = "toolStripMenuItem3";
            toolStripMenuItem3.Size = new Size(68, 21);
            toolStripMenuItem3.Text = "客户服务";
            // 
            // toolStripMenuItem4
            // 
            toolStripMenuItem4.Name = "toolStripMenuItem4";
            toolStripMenuItem4.Size = new Size(92, 21);
            toolStripMenuItem4.Text = "客户信息查询";
            // 
            // toolStripMenuItem1
            // 
            toolStripMenuItem1.Name = "toolStripMenuItem1";
            toolStripMenuItem1.Size = new Size(92, 21);
            toolStripMenuItem1.Text = "基础信息查询";
            // 
            // panel1
            // 
            panel1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            panel1.BackgroundImage = Properties.Resources.上;
            panel1.BackgroundImageLayout = ImageLayout.Stretch;
            panel1.Location = new Point(0, 28);
            panel1.Name = "panel1";
            panel1.Size = new Size(496, 40);
            panel1.TabIndex = 1;
            // 
            // splitContainer1
            // 
            splitContainer1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
            splitContainer1.Location = new Point(0, 65);
            splitContainer1.Name = "splitContainer1";
            // 
            // splitContainer1.Panel1
            // 
            splitContainer1.Panel1.Controls.Add(treeView1);
            // 
            // splitContainer1.Panel2
            // 
            splitContainer1.Panel2.BackgroundImageLayout = ImageLayout.Stretch;
            splitContainer1.Panel2.Controls.Add(pictureBox1);
            splitContainer1.Size = new Size(496, 282);
            splitContainer1.SplitterDistance = 165;
            splitContainer1.TabIndex = 2;
            // 
            // treeView1
            // 
            treeView1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left;
            treeView1.Location = new Point(0, 0);
            treeView1.Name = "treeView1";
            treeNode1.Name = "节点6";
            treeNode1.Text = "企业类型设置";
            treeNode2.Name = "节点7";
            treeNode2.Text = "企业性质设置";
            treeNode3.Name = "节点8";
            treeNode3.Text = "企业级别设置";
            treeNode4.Name = "节点9";
            treeNode4.Text = "企业资信设置";
            treeNode5.Name = "节点0";
            treeNode5.Text = "基础信息维护";
            treeNode6.Name = "节点10";
            treeNode6.Text = "客户信息";
            treeNode7.Name = "节点11";
            treeNode7.Text = "联系人信息";
            treeNode8.Name = "节点12";
            treeNode8.Text = "业务往来";
            treeNode9.Name = "节点1";
            treeNode9.Text = "客户信息维护";
            treeNode10.Name = "节点13";
            treeNode10.Text = "客户投诉";
            treeNode11.Name = "节点14";
            treeNode11.Text = "客户反馈";
            treeNode12.Name = "节点2";
            treeNode12.Text = "客户服务";
            treeNode13.Name = "节点15";
            treeNode13.Text = "联系人信息查询";
            treeNode14.Name = "节点16";
            treeNode14.Text = "客户信息查询";
            treeNode15.Name = "节点3";
            treeNode15.Text = "客户信息查询";
            treeNode16.Name = "节点17";
            treeNode16.Text = "客户信息报表";
            treeNode17.Name = "节点18";
            treeNode17.Text = "业务往来报表";
            treeNode18.Name = "节点19";
            treeNode18.Text = "联系人信息表";
            treeNode19.Name = "节点4";
            treeNode19.Text = "打印报表";
            treeNode20.Name = "节点20";
            treeNode20.Text = "调用Word";
            treeNode21.Name = "节点21";
            treeNode21.Text = "调用EXCEL";
            treeNode22.Name = "节点5";
            treeNode22.Text = "辅助工具";
            treeView1.Nodes.AddRange(new TreeNode[] { treeNode5, treeNode9, treeNode12, treeNode15, treeNode19, treeNode22 });
            treeView1.Size = new Size(165, 282);
            treeView1.TabIndex = 0;
            // 
            // pictureBox1
            // 
            pictureBox1.BackgroundImage = Properties.Resources.右;
            pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
            pictureBox1.Dock = DockStyle.Fill;
            pictureBox1.Location = new Point(0, 0);
            pictureBox1.Name = "pictureBox1";
            pictureBox1.Size = new Size(327, 282);
            pictureBox1.TabIndex = 0;
            pictureBox1.TabStop = false;
            // 
            // Form1
            // 
            AutoScaleDimensions = new SizeF(7F, 17F);
            AutoScaleMode = AutoScaleMode.Font;
            ClientSize = new Size(497, 347);
            Controls.Add(splitContainer1);
            Controls.Add(panel1);
            Controls.Add(menuStrip1);
            MainMenuStrip = menuStrip1;
            Name = "Form1";
            Text = "Form1";
            Load += Form1_Load;
            menuStrip1.ResumeLayout(false);
            menuStrip1.PerformLayout();
            splitContainer1.Panel1.ResumeLayout(false);
            splitContainer1.Panel2.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)splitContainer1).EndInit();
            splitContainer1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
            ResumeLayout(false);
            PerformLayout();
        }

        #endregion

        private MenuStrip menuStrip1;
        private ToolStripMenuItem toolStripMenuItem1;
        private ToolStripMenuItem toolStripMenuItem2;
        private ToolStripMenuItem toolStripMenuItem3;
        private ToolStripMenuItem toolStripMenuItem4;
        private Panel panel1;
        private SplitContainer splitContainer1;
        private TreeView treeView1;
        private PictureBox pictureBox1;
    }
}

(3)Form1.cs

namespace _194
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 展开所有节点
        /// </summary>
        private void Form1_Load(object sender, EventArgs e)
        {
            treeView1.ExpandAll();
        }
    }
}

(4)生成效果

 

 

        这是一个缺点,当拖拽窗体放大时,panel2里的图片不能stretch,请网友看到给一个修复的建议吧。

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

PostgreSQL大版本如何升级?

&#x1f4e2;&#x1f4e2;&#x1f4e2;&#x1f4e3;&#x1f4e3;&#x1f4e3; 哈喽&#xff01;大家好&#xff0c;我是【IT邦德】&#xff0c;江湖人称jeames007&#xff0c;10余年DBA及大数据工作经验 一位上进心十足的【大数据领域博主】&#xff01;&#x1f61c;&am…

算法训练营day25

零、回溯算法理论 参考链接13.1 回溯算法 - Hello 算法 (hello-algo.com) 1.尝试与回退 之所以称之为回溯算法&#xff0c;是因为该算法在搜索解空间时会采用“尝试”与“回退”的策略。当算法在搜索过程中遇到某个状态无法继续前进或无法得到满足条件的解时&#xff0c;它会…

vue使用海康控件开发包——浏览器直接查看海康监控画面

1、下载控件开发包 2、安装插件&#xff08;双击/demo/codebase/HCWebSDKPlugin.exe进行安装&#xff09; 3、打开/demo/index.html文件 4、在页面上输入你的海康监控的登录信息进行预览 如果有监控画面则可以进行下面的操作 注意&#xff1a;以下操作都在Vue项目进行 5、复…

【Unity】shader中参数传递

1、前言 unity shader这个对于我来说是真的有点难&#xff0c;今天这篇文章主要还是总结下最近学习到的一些东西&#xff0c;避免过段时间忘记了&#xff0c;可能有不对&#xff0c;欢迎留言纠正。 2、参数传递的两种方式 2.1 语义传递 语义传递这个相对来说是简单的 shad…

ENVI不同版本个人使用对比

ENVI不同版本个人使用对比 文章目录 ENVI不同版本个人使用对比前言对比5.3学习版5.6学习版6.0试用版 总结 前言 目前来看&#xff0c;流传较广的可供大家免费获取的ENVI版本主要是5.3学习版 5.6学习版 6.0学习版这三个版本&#xff0c;不同的版本有不同特色&#xff0c;在此做…

21.7K Star力荐!跨平台的开源免费可视化爬虫,让数据采集不再是难题!

朋友们!你是否曾梦想着轻松地从网上抓取数据,却苦于编程技能的门槛?现在,有了EasySpider,这一切都变得触手可及!这不仅仅是一个工具,它是一个革命性的网络爬虫神器,让你能够像专业人士一样,无需编写一行代码,就能轻松设计和执行爬虫任务。无论是动态内容还是复杂页面…

【介绍下分布式系统】

&#x1f308;个人主页: 程序员不想敲代码啊 &#x1f3c6;CSDN优质创作者&#xff0c;CSDN实力新星&#xff0c;CSDN博客专家 &#x1f44d;点赞⭐评论⭐收藏 &#x1f91d;希望本文对您有所裨益&#xff0c;如有不足之处&#xff0c;欢迎在评论区提出指正&#xff0c;让我们共…

Spring Boot框架强大的事件驱动模型(ApplicationEvent)

文章目录 前言应用场景异步处理事务边界外的操作跨微服务通信系统监控与日志聚合UI更新生命周期管理工作流或业务流程缓存同步 小试牛刀定义事件实现事件处理器注册事件处理器发布事件测试事件 写在最后 前言 在Spring Boot应用中&#xff0c;事件处理器是指那些处理特定类型事…

实时采集麦克风并播放(springboot+webscoekt+webrtc)

项目技术 springbootwebscoektwebrtc 项目介绍 项目通过前端webrtc采集麦克风声音&#xff0c;通过websocket发送后台&#xff0c;然后处理成g711-alaw字节数据发生给广播UDP并播放。 后台处理项目使用线程池(5个线程)接受webrtc数据并处理g711-alaw字节数组放到Map容器中&…

将针孔模型相机 应用到3DGS

Motivation 3DGS 的 投影采用的是 CG系的投影矩阵 P P P, 默认相机的 principal point (相机光心) 位于图像的中点处。但是 实际应用的 绝大多数的 相机 并不满足这样一个设定&#xff0c; 因此我们 需要根据 f , c x , c y {f,c_x, c_y} f,cx​,cy​ 这几个参数重新构建3D …

Linux 安装 nvm,并使用 Jenkins 打包前端

文章目录 nvm是什么nvm下载nvm安装设置 nvm 环境变量设置 Jenkins 打包命令 nvm是什么 nvm全英文也叫node.js version management&#xff0c;是一个nodejs的版本管理工具。nvm和n都是node.js版本管理工具&#xff0c;为了解决node.js各种版本存在不兼容现象可以通过它可以安装…

电脑提示msvcp100.dll丢失的解决方法,多种有效的解决方法分享

在日常使用电脑进行工作的时候&#xff0c;我们常常依赖于各种高效软件来辅助完成任务&#xff0c;提升工作效率。然而&#xff0c;当你满怀期待地双击启动某个至关重要的办公软件时&#xff0c;屏幕上却弹出了一个令人措手不及的错误提示&#xff1a;“msvcp100.dll文件丢失”…

二. 搭建Nginx 直播流程服务器

目录 1. 前言 2. 安装 Nginx 依赖 3.下载源码 4. 编译安装 5.配置 rtmp 服务 6.验证配置 1. 前言 服务器由 NGINXRTMP 构成。 NGINX 是 HTTP 服务器&#xff0c; RTMP 是附加模块。 其中 NGINX 我选择的是用 源码编译方式 进行安装&#xff0c;因为这种方式可以自定义…

基于python语言气象水文数据处理及精美科研绘图实践技术

Python是功能强大、免费、开源&#xff0c;实现面向对象的编程语言&#xff0c;Python能够运行在Linux、Windows、Macintosh、AIX操作系统上及不同平台&#xff08;x86和arm&#xff09;&#xff0c;Python简洁的语法和对动态输入的支持&#xff0c;再加上解释性语言的本质&…

C语言中的三大循环

C语言中为我们提供了三种循环语句&#xff0c;今天我就来与诸君细谈其中之奥妙。循环这一板块总结的内容较多&#xff0c;而且&#xff0c;很重要&#xff01;&#xff08;敲黑板&#xff01;&#xff01;&#xff01;)&#xff0c;所以诸君一定要对此上心&#xff0c;耐住性子…

修复所有 bug 并不能解决所有问题

原文&#xff1a;jeffpsherman - 2024.04.08 在软件领域&#xff0c;如同在制造业&#xff0c;有些问题是由于 bug 或“特殊原因”引发的&#xff0c;而有些则是“常见原因”&#xff0c;这是由于系统设计和实现的性质所导致的。修复 bug 就是移除特殊原因&#xff0c;消除 bu…

go语言实现简单认证样例

目录 1、代码实现样例 2、postman调用 1、代码实现样例 package mainimport ("net/http""strings""github.com/dgrijalva/jwt-go""github.com/gin-gonic/gin" )var (// 密钥&#xff0c;用于验证 JWT 令牌signingKey []byte("…

上班太闲了,一坐就是一天,有没有什么副业可以干的?

一、别做兼职&#xff0c;做副业 兼职&#xff0c;仅仅是用时间换取报酬&#xff0c;短暂且有限&#xff0c;实质上仍是雇佣劳动。副业则不同&#xff0c;它依托你的独特价值换取长久回报&#xff0c;犹如你的第二事业。 或许你还不太清楚兼职的局限性&#xff0c;以下是一些…

上位机开发PyQt5(一)【创建窗口、窗口标题、气泡、显示图片和图标、显示文字】

目录 一、 第一个Qt窗口 二、PyQt模块简介 三、窗口标题和气泡 setWindowTitle resize setToolTip 四、标签QLabel显示图片和图标 setPixmap setWindowIcon resize(label.pixmap().size()) 五、标签QLabel显示文字 setText QFont setPointSize setFont set…

ios 打印选择纸张

问题描述&#xff1a; 手机App开发中的打印功能&#xff0c;在android中可以选择打印的纸张是A4 A5 等&#xff0c;但是在ios系统中不能选择纸张&#xff0c;一般情况下会只有一个纸类型。 原因解释&#xff1a; 因为在打印机的配置页中可以设置打印机的当前纸张大小&#xff…