winforms界面小技巧1

简介: winforms界面小技巧1

1、去掉button的边框线:设置FlatStyle=Flat,以及FlatAppearance的BorderSize=0


2、重绘groupbox的边界线


private void groupBox1_Paint(object sender, PaintEventArgs e)
{
     e.Graphics.Clear(groupBox1.BackColor);
     e.Graphics.DrawString(groupBox1.Text, groupBox1.Font, Brushes.Black, 10, 1);
     e.Graphics.DrawLine(Pens.Black, 1, 7, 8, 7);
     e.Graphics.DrawLine(Pens.Black, e.Graphics.MeasureString(groupBox1.Text, groupBox1.Font).Width + 8, 7, groupBox1.Width - 2, 7);
     e.Graphics.DrawLine(Pens.Black, 1, 7, 1, groupBox1.Height - 2);
     e.Graphics.DrawLine(Pens.Black, 1, groupBox1.Height - 2, groupBox1.Width - 2, groupBox1.Height - 2);
     e.Graphics.DrawLine(Pens.Black, groupBox1.Width - 2, groupBox1.Height - 2, groupBox1.Width - 2, 7);
}

3、重回渐变背景

private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Color FColor = System.Drawing.Color.FromArgb(((int)(((byte)(184)))), ((int)(((byte)(147)))), ((int)(((byte)(201)))));
            Color TColor = System.Drawing.Color.FromArgb(((int)(((byte)(84)))), ((int)(((byte)(42)))), ((int)(((byte)(113)))));
            Brush b = new LinearGradientBrush(this.tableLayoutPanel1.ClientRectangle, FColor, TColor, LinearGradientMode.Vertical);// .ForwardDiagonal);
            g.FillRectangle(b, this.tableLayoutPanel1.ClientRectangle);
        }
        private void btn_status_Paint(object sender, PaintEventArgs e)
        {
            Bitmap backimg = new Bitmap(btn_status.Width, btn_status.Height);
            Graphics g = Graphics.FromImage(backimg); ;
            Color FColor = System.Drawing.Color.Lavender;
            Color TColor = System.Drawing.Color.FromArgb(((int)(((byte)(184)))), ((int)(((byte)(147)))), ((int)(((byte)(201)))));
            Brush b = new LinearGradientBrush(this.btn_status.ClientRectangle, FColor, TColor, LinearGradientMode.Vertical);// .ForwardDiagonal);
            g.FillRectangle(b, this.btn_status.ClientRectangle);
            btn_status.BackgroundImage = backimg;
            //Graphics g = e.Graphics;
            //LinearGradientBrush myBrush = new LinearGradientBrush(this.btn_status.ClientRectangle, Color.White, Color.Blue, LinearGradientMode.Vertical);
            //g.FillRectangle(myBrush, this.btn_status.ClientRectangle);
        }

4、更改listview的某个cell的背景,并消除横向滑动条


ListViewItem item = new ListViewItem();
item.SubItems[0].Text = DateTime.Now.ToString("yyyy-MM-dd hh:MM:ss");
item.SubItems.Add(attention[i]);
item.UseItemStyleForSubItems = false;
item.SubItems[1].BackColor = Color.CornflowerBlue;
listView1.Items.Add(item);
// 第一列宽度 + 第二列宽度 = 工作区宽度
listView1.Columns[1].Width = listView1.ClientSize.Width - listView1.Columns[0].Width;



 


相关文章
|
搜索推荐 BI API
ZoomEye-python工具使用详解(一)
ZoomEye-python工具使用详解(一)
323 0
|
SQL 关系型数据库 MySQL
用批处理实现自动备份和清理mysql数据库
转自博客 http://blog.csdn.net/fanfanjin/article/details/6284016 有网友问我在win2003下如何自动备份MySQL数据库,既然是自动备份,那肯定得写脚本。
1319 0
|
4天前
|
弹性计算 运维 搜索推荐
三翼鸟携手阿里云ECS g9i:智慧家庭场景的效能革命与未来生活新范式
三翼鸟是海尔智家旗下全球首个智慧家庭场景品牌,致力于提供覆盖衣、食、住、娱的一站式全场景解决方案。截至2025年,服务近1亿家庭,连接设备超5000万台。面对高并发、低延迟与稳定性挑战,全面升级为阿里云ECS g9i实例,实现连接能力提升40%、故障率下降90%、响应速度提升至120ms以内,成本降低20%,推动智慧家庭体验全面跃迁。
|
4天前
|
数据采集 人工智能 自然语言处理
3分钟采集134篇AI文章!深度解析如何通过云无影AgentBay实现25倍并发 + LlamaIndex智能推荐
结合阿里云无影 AgentBay 云端并发采集与 LlamaIndex 智能分析,3分钟高效抓取134篇 AI Agent 文章,实现 AI 推荐、智能问答与知识沉淀,打造从数据获取到价值提炼的完整闭环。
375 92
|
5天前
|
域名解析 人工智能
【实操攻略】手把手教学,免费领取.CN域名
即日起至2025年12月31日,购买万小智AI建站或云·企业官网,每单可免费领1个.CN域名首年!跟我了解领取攻略吧~
|
5天前
|
SQL 人工智能 自然语言处理
Geo优化SOP标准化:于磊老师的“人性化Geo”体系如何助力企业获客提效46%
随着生成式AI的普及,Geo优化(Generative Engine Optimization)已成为企业获客的新战场。然而,缺乏标准化流程(Geo优化sop)导致优化效果参差不齐。本文将深入探讨Geo专家于磊老师提出的“人性化Geo”优化体系,并展示Geo优化sop标准化如何帮助企业实现获客效率提升46%的惊人效果,为企业在AI时代构建稳定的流量护城河。
385 156
Geo优化SOP标准化:于磊老师的“人性化Geo”体系如何助力企业获客提效46%
|
4天前
|
数据采集 缓存 数据可视化
Android 无侵入式数据采集:从手动埋点到字节码插桩的演进之路
本文深入探讨Android无侵入式埋点技术,通过AOP与字节码插桩(如ASM)实现数据采集自动化,彻底解耦业务代码与埋点逻辑。涵盖页面浏览、点击事件自动追踪及注解驱动的半自动化方案,提升数据质量与研发效率,助力团队迈向高效、稳定的智能化埋点体系。(238字)
268 158