How to change font properties from code


In SharpShooter Reports before version 6.5, the code that changes font properties directly did not work in all cases.

Sample of such code:

myTextBox.Font.Size = someValue;


The reason is that the TextBox does not have the pre-defined font by default, and when getting a value of the Font property it returns a copy of the style font or a copy of the default font. Thus, the specified expression will just change value of object copy property and this will not affect the source object.


The problem is solved in version 6.5 of the product.

The users of earlier product versions can use the following code for changing values of the font properties of the TextBox:

var font = new PerpetuumSoft.Framework.Drawing.FontDescriptor(myTextBox.Font);
font.Size = someValue;
myTextBox.Font = font;

Add Feedback