h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

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;
        }

Adjust width of DateTimepicker

Today , we will discuss about How to adjust width of DateTimepicker in C#.Net.
Now, let’s start:
Create Project in VS 2008 .
Open your form
Drag and Drop DateTimePicker from Toolbar into Form
Go To Code Section .
Copy and Paste the following code in the Code section .

private void dateTimePickerwidth(DateTimePicker dtp,string format)
        {
         System.Drawing.Graphics g = dtp.CreateGraphics();
            float maxwidth = 0f;
            float w = g.MeasureString(Convert.ToString(dtp), dtp.Font).Width;
               if (w < maxwidth)
                    maxwidth = w;
             g.Dispose();
            switch (format)
            {
                case "Long":
                    dtp.Width = (int)maxwidth + 220;
                    break;
                case "Short":
                    dtp.Width = (int)maxwidth + 100;
                    break;
                case "Time":
                    dtp.Width = (int)maxwidth + 100;
                    break;
                case "Custom":
                    dtp.Width = (int)maxwidth + 105;
                    break;
         }
       }

private void Form1_Load(object sender, EventArgs e)
        {
            dateTimePickerwidth(dateTimePicker1, dateTimePicker1.Format.ToString());
        }



Run the Application and See the Result.
Happy Coding!


Get week number of the Day using C#

int noofweek = DateTime.Today.DayOfYear;
            noofweek = noofweek/7;
            MessageBox.Show(noofweek.ToString());