Category Archives: Code

Fixing the default of the .Net Label’s AutoSize property


This is a story about creating form applications using Visual Basic and Visual C#.

Have you ever wished that the default for the AutoSize property of labels was False? While there might be cases where you create them with AutoSize = True, in my company, we use AutoSize = False. However, it’s cumbersome to set the property every time you paste a label. So, the idea behind this code is to create labels with the AutoSize default value set to False. This has been confirmed using Visual Studio 2010 and Visual Basic.

In Visual Studio Professional Edition, you can create inherited controls. In the Express Edition, you couldn’t create inherited controls from the start, as far as I recall. In that case, you first create an inherited class.

The class to inherit is System.Windows.Forms.Label. A common approach here is to use the property window of the control’s designer screen to set AutoSize to False (though nothing appears in the designer screen, the property window is usable). However, for the Label control, things get tricky, as it reverts to AutoSize = True when actually pasted onto a form. To tackle this, display the code and add the following snippet.

Continue reading Fixing the default of the .Net Label’s AutoSize property

How to Convert Numeric Dates to Date Format in Crystal Reports


This is a guide on how to convert numeric date values to a year-month-day format in CrypstalReports. This code is useful when you have date data stored as 8-digit numeric values representing the year, month, and day.

First, create a formula field. Within it, write the following expression. To edit the expression, right-click and select “Edit Formula.”

With this, you can convert the numeric value to a date. Replace {DBColumn} with the name of your database field.

However, this will still display in the format 1986/01/06. To change the date format, you’ll need to set the properties of this formula field.

For DateFirstSeparator, DateSecondSeparator, and DateSuffixSeparator, input “年” (for year), “月” (for month), and “日” (for day), respectively. This will display the date as 1986年01月06日.