How to change font properties from code

Problem:

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;

Reason:

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.

Solution:

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