有哪位高手知道Combobox文本怎么居中。。急。。

fengzhifengyi 2009-01-07 04:35:26
combobox文本居中。。高手指教。
...全文
1709 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zgke 2009-01-07
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 h_w_king 的回复:]
private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
string s = this.comboBox1.Items[e.Index].ToString();
SizeF ss = e.Graphics.MeasureString(s, e.Font);

float l = (float)(e.Bounds.Width - ss.Width) / 2;
if (l < 0) l = 0f;
float t = (float)(e.Bounds.Height - ss.Height) / 2;
if (t < 0)…
[/Quote]

学习了
yao991118 2009-01-07
  • 打赏
  • 举报
回复
前面加空格不知道可以不?
h_w_king 2009-01-07
  • 打赏
  • 举报
回复
private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
string s = this.comboBox1.Items[e.Index].ToString();
SizeF ss = e.Graphics.MeasureString(s, e.Font);

float l = (float)(e.Bounds.Width - ss.Width) / 2;
if (l < 0) l = 0f;
float t = (float)(e.Bounds.Height - ss.Height) / 2;
if (t < 0) t = 0f;
t = t + this.comboBox1.ItemHeight*e.Index;
e.DrawBackground();
e.DrawFocusRectangle();
e.Graphics.DrawString(s, e.Font, new SolidBrush(e.ForeColor), l, t);
}
设置:
 this.comboBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
gtiroy 2009-01-07
  • 打赏
  • 举报
回复
你可以自己写一个combobox继承于Combobox
gtiroy 2009-01-07
  • 打赏
  • 举报
回复
这个也要居中?文字不一样长多难看啊
优途科技 2009-01-07
  • 打赏
  • 举报
回复
?

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧