C# winfrom设置textbox字体大小和样式并结合GridView使用

本文介绍了如何在C# WinForm应用中设置TextBox的字体大小和样式。同时,通过示例展示了在GridControl中如何根据条件动态改变行的背景色和字体格式,实现特定行的高亮显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

先简单介绍一下winfrom设置textbox字体大小和样式:

private void radioButton1_CheckedChanged(object sender, System.EventArgs e)

   {
    //设置字体为宋体
    textBox1.Font=new Font("宋体",textBox1.Font.Size,textBox1.Font.Style);
   }

   private void radioButton4_CheckedChanged(object sender, System.EventArgs e)
   {
    //设置字体的大小为12
    textBox1.Font=new Font(textBox1.Font.FontFamily,12,textBox1.Font.Style);
   }

   private void checkBox1_CheckedChanged(object sender, System.EventArgs e)
   {
    //设置字体的风格为加粗
    if(checkBox1.Checked)
    textBox1.Font=new Font(textBox1.Font,textBox1.Font.Style|FontStyle.Bold);
    else
    textBox1.Font=new Font(textBox1.Font,textBox1.Font.Style^FontStyle.Bold);
   }

   private void checkBox2_CheckedChanged(object sender, System.EventArgs e)
   {
    //设置字体的风格为倾斜
if(checkBox2.Checked)
   textBox1.Font=new Font(textBox1.Font,textBox1.Font.Style|FontStyle.Italic);
else
   textBox1.Font=new Font(textBox1.Font,textBox1.Font.Style^FontStyle.Italic);

   }


下面来说一下

在gridcontrol中如何实现对满足条件的某一行进行涂色和改变字体格式

private void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
        {
            int handle = e.RowHandle;          
            if (handle < 0) return;
            DataRow dr = gridView1.GetDataRow(handle);
            if (dr == null) return;
            if (gridView1.GetRowCellValue(handle, "StudentNo").ToString().Equals("20111717"))
                {
                    e.Appearance.BackColor = Color.Gray;//颜色设置
                    e.Appearance.Font = new Font(e.Appearance.Font, e.Appearance.Font.Style^FontStyle.Italic);//设置字体为斜体


                     //.......根据自己的需求
                }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值