如题,怎样做到?
解决方案 »
- datagridview 中,类型转换
- 如何在label中画直线?
- 【紧急求助】:如何检测串口DB9引脚的变化?DCD、DSR、CTS/DTR?◆
- 有接触eterm3进来帮帮忙
- 急求网友解惑,我想打印datagrid中显示的数据,出现了问题!(三根鸡毛,急)
- 当IamgeList大小改变之后,ToolBar里的图片显不出来了
- 谁有个日志管理系统呢,给我分享一下,非常感激!
- C#中如何快速将SQL_SERVER数据库中导出的数据导入到EXCEL里面???(要快速,一个一个CELL填太慢了)
- 如何让选定的子mdi窗体从到底层切换到最上层来? ——在线等待
- 谁有关于C#调用Windows API的资料,不胜感激!
- 求大神指教 这样插入数据 为什么插不进去呢 用的是vs2010和Access2010
- 自定义了一个登入控件,在其中放入验证码,点击图片怎么刷新更换?
居右解决了
GroupBox标题居中怎么做到?求解答!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace TestTemplate
{
public partial class grp : GroupBox
{
public grp()
{
InitializeComponent();
base.Text = "";
}
private string text;
public new string Text
{
get
{
return this.text;
}
set
{
base.Text = "";
this.text = value;
}
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
StringFormat s = new StringFormat();
s.LineAlignment = StringAlignment.Near;
s.Alignment = this.textAlignment;
e.Graphics.DrawString(this.text, this.Font, Brushes.Black, new RectangleF(0, 0, this.Width, this.Height), s);
}
private StringAlignment textAlignment = StringAlignment.Center; public StringAlignment TextAlignment
{
get { return textAlignment; }
set { textAlignment = value; }
} }
}
我又用背景色把文字压住的框线重画了一下,但是框线的凹凸感却消不掉,效果如图:GroupBox的框线是怎么画的?如何消除,请高手指点
在onpaint 事件里:
base.OnPaint(e);
StringFormat s = new StringFormat();
s.LineAlignment = StringAlignment.Near;
s.Alignment = this.textAlignment;
//新增如下代码段--------------------------------------------------------
SizeF textarea= e.Graphics.MeasureString(this.Text, this.Font);
Brush a = new SolidBrush(this.BackColor);
e.Graphics.FillRectangle(a, new RectangleF(5, 0, (this.Width - 10) * 1.0f, textarea.Height));
//--------------------------------------------------------------------
e.Graphics.DrawString(this.Text, this.Font, Brushes.Black, new RectangleF(0, 0, this.Width, this.Height), s);
e.Graphics.FillRectangle(a, new RectangleF(5, 0, (this.Width - 10) * 1.0f, textarea.Height));
把上面这句话改成:
e.Graphics.FillRectangle(a, new RectangleF((this.Width-textarea.Width)/2, 0, textarea.Width, textarea.Height));
这样的话文字的长短也没有限制了