39【WinForm】WinForm中的TableLayoutPanel控件、PropertyGrid控件、PictureBox控件、ListView控件、DataGridView控件的使用

简介: TableLayoutPanel控件

前言


一、TableLayoutPanel控件

可以起到一个随着界面大小变化的效果。

1、效果

在这里插入图片描述

2、界面设计

界面上没有拖动窗体控件,而是在代码中new系统控件。
在这里插入图片描述

3、代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TableLayoutPanel控件
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            TableLayoutPanel tlp = new TableLayoutPanel();          //生成TableLayoutPanel控件
            tlp.Dock = DockStyle.Fill;
            tlp.RowCount = 4;
            tlp.RowStyles.Add(new RowStyle(SizeType.Percent, 25));
            tlp.RowStyles.Add(new RowStyle(SizeType.Percent, 25));
            tlp.RowStyles.Add(new RowStyle(SizeType.Percent, 25));
            tlp.RowStyles.Add(new RowStyle(SizeType.Percent, 25));
            tlp.ColumnCount = 4;
            tlp.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25));
            tlp.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25));
            tlp.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25));
            tlp.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 25));
            tlp.CellBorderStyle = TableLayoutPanelCellBorderStyle.OutsetDouble;

            this.Controls.Add(tlp);

            TextBox tb1 = new TextBox();
            tb1.Text = "TextBox1";
            tb1.Multiline = true;
            tb1.Dock = DockStyle.Fill;

            tlp.Controls.Add(tb1);
            tlp.SetCellPosition(tb1,new TableLayoutPanelCellPosition(0,0));
            tlp.SetColumnSpan(tb1,2);

            TextBox tb2 = new TextBox();
            tb2.Text = "TextBox2";
            tb2.Multiline = true;
            tb2.Dock = DockStyle.Fill;

            tlp.Controls.Add(tb2);
            tlp.SetCellPosition(tb2, new TableLayoutPanelCellPosition(2, 1));
            tlp.SetRowSpan(tb2, 2);
        }
    }
}

二、PropertyGrid控件

1、效果

类似于VS中控件的属性栏。
在这里插入图片描述

2、界面设计

在这里插入图片描述

3、代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PropertyGrid
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.propertyGrid1.SelectedObject = new Emplyee();
        }
    }

    public class Emplyee
    {
        private string _name = "Name1";
        private string _sex = "1";

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        public string Sex
        {
            get { return _sex; }
            set { _sex = value; }
        }

    }
}

三、PictureBox

1、效果

使用PictureBox加载了一张动图。
在这里插入图片描述

2、界面设计

在这里插入图片描述
在这里插入图片描述

3、代码

就看加了图的效果,没啥代码。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PictureBox
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    }
}

四、ListView

1、效果

在这里插入图片描述

2、界面设计

在这里插入图片描述
在这里插入图片描述

3、代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ListView
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            /// <summary>
            /// 代码生成
            /// </summary>
            //ListViewItem List1 = new ListViewItem("List1");                                     
            //List1.SubItems.AddRange(new string[] { "1", "11", "111" });
            //ListViewItem List2 = new ListViewItem("List2");
            //List2.SubItems.AddRange(new string[] { "2", "22", "222" });

            //listView1.Items.AddRange(new ListViewItem[] { List1, List2 });
        }
    }
}

五、DataGridView

1、效果

在这里插入图片描述

2、界面设计

在这里插入图片描述

3、代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DataGridView控件增强性
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“北风贸易DataSet.自行车产品”中。您可以根据需要移动或删除它。
            this.自行车产品TableAdapter.Fill(this.北风贸易DataSet.自行车产品);
            // TODO: 这行代码将数据加载到表“北风贸易DataSet.自行车产品次分类”中。您可以根据需要移动或删除它。
            this.自行车产品次分类TableAdapter.Fill(this.北风贸易DataSet.自行车产品次分类);
            // TODO: 这行代码将数据加载到表“北风贸易DataSet.自行车产品分类”中。您可以根据需要移动或删除它。
            this.自行车产品分类TableAdapter.Fill(this.北风贸易DataSet.自行车产品分类);

        }
    }
}

总结

对这些控件的再一次熟悉。

目录
相关文章
|
C# 索引 Windows
Winform控件优化之TabControl控件的使用和常用功能
TabControl是一个分页切换(tab)控件,不同的页框内可以呈现不同的内容,将主要介绍调整tab的左右侧显示、设置多行tab、禁用或删除tabpage、隐藏TabControl头部的选项卡等
8766 0
Winform控件优化之TabControl控件的使用和常用功能
|
4月前
|
C# 数据库 Windows
C# WinForms数据绑定详解(手把手教你将数据源绑定到WinForms控件)
本教程带你快速掌握C# WinForms数据绑定,通过定义员工模型并绑定到ListBox和DataGridView,实现数据自动展示。介绍DataSource、DisplayMember及BindingSource的使用,帮助新手减少重复代码,提升开发效率,是WinForms入门必备技能。(238字)
|
API C#
C#实现Winform程序右下角弹窗消息提示
C#实现Winform程序右下角弹窗消息提示
1077 1
C#或Winform中的消息通知之自定义优雅漂亮的通知效果
Custom Notification自定义通知提示,一款非常优雅漂亮的自定义通知效果,主要介绍其实现思路、调整和优化...
1897 0
C#或Winform中的消息通知之自定义优雅漂亮的通知效果
|
敏捷开发 监控 数据可视化
一文带你了解:六款适合PC端的工时管理工具
在项目管理中,工时管理软件能实时反映项目各任务的进展情况。管理者可以通过查看员工在每个任务上的工时投入,判断任务是否按计划推进。若发现某个任务工时投入远超预期但进度缓慢,就可以及时介入调查原因,是遇到技术难题、资源不足还是人员协作问题等,进而采取相应措施加以解决,确保项目能按时交付。
|
C# Windows
WPF中值转换器的使用
WPF中值转换器的使用
475 1
|
API C# Windows
【C#】在winform中如何实现嵌入第三方软件窗体
【C#】在winform中如何实现嵌入第三方软件窗体
1081 0
|
C# Windows
49.c#:StatusStrip 控件
49.c#:StatusStrip 控件
541 1
49.c#:StatusStrip 控件
|
运维 安全 网络协议
盘点一款强大的网络工具集:Netwox
盘点一款强大的网络工具集:Netwox
423 0
|
XML 数据格式 C++
WPF-疑难问题-xaml编码导致中文字符编译无效
WPF-疑难问题-xaml编码导致中文字符编译无效
606 0

热门文章

最新文章