• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
成为自己最想成为的那种人
博客园    首页    新随笔    联系   管理    订阅  订阅
控件重绘

1. 设置控件DrawMode属性为OwnerDrawFixed,编辑控件DrawItem事件

 

重绘tabControl——选项卡控件

    string text = ((TabControl)sender).TabPages[e.Index].Text;
    SolidBrush brush = new SolidBrush(Color.Black);
    StringFormat sf = new StringFormat(StringFormatFlags.DirectionRightToLeft);
    sf.LineAlignment = StringAlignment.Center;
    sf.Alignment = StringAlignment.Center;
    e.Graphics.DrawString(text, SystemInformation.MenuFont, brush, e.Bounds, sf);

重绘listBox控件(注意修改涉及控件名的地方)

    e.DrawBackground();
    e.DrawFocusRectangle();

    //让文字位于Item的中间
    float difH = (e.Bounds.Height - e.Font.Height) / 2;    //字体垂直方向居中
    RectangleF rf = new RectangleF(e.Bounds.X, e.Bounds.Y + difH, e.Bounds.Width, e.Font.Height);
    e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), rf);

posted on 2017-05-08 08:22  遇见未来  阅读(460)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3