zoukankan      html  css  js  c++  java
  • 007. 自定义ListBox的item的宽高, 字体居中

     /// <summary>
            /// 自定义ListBox的item的宽高, 字体居中
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void lisB_DrawItem(object sender, DrawItemEventArgs e)
            {
                if (e.Index == -1)
                {
                    return;
                }
                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(lisB.Items[e.Index].ToString(), e.Font, new SolidBrush(Color.Black), rf);
            }
    
            private void lisB_MeasureItem(object sender, MeasureItemEventArgs e)
            {
              //if(e.Index==1)  指定某一行的高度
                    e.ItemHeight = 22;
            }
  • 相关阅读:
    响应式布局
    C# 基础复习 二 面向对象
    C# 基础复习 一 数据类型
    .net 面试题
    Unity5.X 创建基本的3D游戏场景
    Unity5.X 编辑器介绍
    Unity5.X 开发资源介绍
    SignalR
    vue-cli
    Vue.js
  • 原文地址:https://www.cnblogs.com/wxylog/p/6085275.html
Copyright © 2011-2022 走看看