The GenerateMember property will be set to true by default, that is not the problem.
The problem is that Font objects are immutable: you cannot change them after you created them, because all their properties (Size, Bold, etc) are read-only.
To change the font, you can create a new Font and use one of the many overloads of the constructor. GaryMazzone showed you one:
However, this will create the font as Arial, regardless of what it was before.Code:lblId.Font = New Font("Arial", 10, FontStyle.Bold)
If you want to keep the font the same 'family' (arial, times new roman, etc) and the same size, but merely want to change the style, there is a better suited constructor overload. This one accepts another Font object and a FontStyle. It will then create a new font that has all properties the same as the Font you pass, except for the style, which it will set to whatever you specify as the second argument.
So, if you want to make a font bold, you can do this
Furthermore, you can use bitwise combinations for the FontStyle. For example, to set a font as Bold and Italic, you useCode:lblId.Font = New Font(lblId.Font, FontStyle.Bold)
If you want your font to be italic, but also keep all other styles (if it was bold, it has to stay bold), you simply 'Or' the Italic style to the existing style:Code:lblId.Font = New Font(lblId.Font, FontStyle.Bold Or FontStyle.Italic)
Similarly, if you want to ensure that your font is NOT bold, you can use the And Not (bitwise) operator to 'remove' the Bold style from the existing styleCode:lblId.Font = New Font(lblId.Font, lblId.Font.FontStyle Or FontStyle.Italic)
Finally, you can use the Xor operator to toggle a style. Let's say your font was underlined, it will then become not underlined (and vice versa)Code:lblId.Font = New Font(lblId.Font, lblId.Font.FontStyle And Not FontStyle.Bold)
These bitwise operations (Or, And, Not, Xor, etc) work because FontStyle is an enumeration. Basically, the Or operator 'adds' two styles together. The 'And Not' operator 'removes' one style. The Xor operator 'toggles' one style.Code:lblId.Font = New Font(lblId.Font, lblId.Font.FontStyle Xor FontStyles.Underline)




Reply With Quote