当前位置:网站首页>C# ListBox用法
C# ListBox用法
2022-06-09 13:21:00 【熊思雨】
在Winform中,ListBox用来显示日志还不错,如图:

用法:
/// <summary>
/// 添加普通日志
/// </summary>
/// <param name="content">内容</param>
public void AddOrdinaryLog(string content)
{
if (this.InvokeRequired)
{
//切换到UI线程
this.Invoke(new MethodInvoker(delegate
{
AddOrdinaryLog_UI(content);
}));
}
else
{
AddOrdinaryLog_UI(content);
}
}
private void AddOrdinaryLog_UI(string content)
{
//读取当前ListBox列表长度
int len = ListBox_OrdinaryLogList.Items.Count;
//插入新的一行
ListBox_OrdinaryLogList.Items.Insert(len, content);
//列表长度大于30,那么就删除第1行的数据
if (len > 30)
ListBox_OrdinaryLogList.Items.RemoveAt(0);
//插入新的数据后,将滚动条移动到最下面
int visibleItems = ListBox_OrdinaryLogList.ClientSize.Height / ListBox_OrdinaryLogList.ItemHeight;
ListBox_OrdinaryLogList.TopIndex = Math.Max(ListBox_OrdinaryLogList.Items.Count - visibleItems + 1, 0);
}这里我加了一个线程的判断,不需要直接复制 AddOrdinaryLog_UI 这个方法即可。
end
边栏推荐
- 6000 + words to help you understand the evolution of Internet architecture!
- Viewing softmax loss function from an optimization perspective
- Like the brain, the nano magnet network can be used to perform AI like computing processing, which can reduce energy consumption
- MySQL数据库(25):外键 foreing key
- 在这些根技术里,读懂华为的“三观”
- HCIA datacom experiment IPv4 addressing and IPv4 routing basic experiment
- Cloud native essay kubernetes workload
- #云原生征文#Kubernetes工作负载
- ThreadLocal基础及高级使用
- #yyds干货盘点# 解决剑指offer:矩形覆盖
猜你喜欢

Weici technology completed a round of financing of more than 100 million yuan, and the core team graduated from Beijing Airlines

Understand Huawei's "Three Outlooks" in these root technologies

Cloud native essay kubernetes workload

#导入Word文档图片# VM虚拟机网络设置

CSDN音视频技术开发者在线调研

TCP/IP协议机制详解

6000 + words to help you understand the evolution of Internet architecture!
原型链?新的歪理解

【并查集】合根植物(连通块的数数量)

【数据库】期末复习:SQL语句、范式的定义和判断、ER图转关系模式
随机推荐
测试概念篇
Wincc中,如何利用C脚本对变量进行置位+复位+取反操作?
5分钟了解NFV
Basic use of canvas (obtain canvas, draw rectangle, clear screen content, animation, draw irregular graphics, circle, dotted line, draw text, color gradient, set shadow, render picture, deformation of
有损传输实例
虚拟消费引领新时尚 互融云NFT系统平台定制开发 助力企业打开“Z”时代
C语言 结构体 | 链表
#云原生征文#Kubernetes工作负载
MySQL数据库(25):外键 foreing key
【计网】思科 期末选择题复习
超越ReLU却鲜为人知,3年后被挖掘:BERT、GPT-2等都在用的激活函数
Hit the snake seven inches
Cloud native essay kubernetes workload
入职腾讯外包一个月,我离职了
How can minority majors solve the problem of "growth"?
Viewing softmax loss function from an optimization perspective
WSL 安装的最佳实践
5 minutes to learn about nfv
栈的基本方法及相关问题
谁说Redis不能存大key