05 November 2012

Adjust Width CheckBoxList using C#.net

 private void checkBoxlistWidht(CheckedListBox chk)
        {
            System.Drawing.Graphics g = chk.CreateGraphics();
            float maxwidth = 0f;
            foreach (object o in chk.Items)
            {
                float w = g.MeasureString(o.ToString(), chk.Font).Width;
                if (w > maxwidth)
                    maxwidth = w;
            }
            g.Dispose();
            chk.Width = (int)maxwidth + 30;
        }

No comments: