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

来源:互联网 发布:o2o软件开发 编辑:程序博客网 时间:2024/05/17 04:22

先简单介绍一下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);//设置字体为斜体


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

0 0
原创粉丝点击