vb.net - Set Font.Bold on inherited label -


I have to set. Transforms on labels. Style) I delete it for the form. Use the property from the designer's form file.

Now I have to set the text of this label to be bold without defining the font name, size, etc. of this label.

> I try:

  label6.Font.Bold = true   

but this does not work (property.fold) .bould is read only).
If I set the font for this label:

  label6.font = new font (myfontname, 10, FontStyle.Bold, GraphicsUnit.Point)   

Then I get bold text, but the label does not inherit the font size of the form again.

Is it possible to put the font legacy on the label, but will there be bold text on such labels?

No, as you already searched for the property of font.bold The only font to read is that the font objects are irreversible, which means that once they are created their properties can not be changed. The only way to modify this property is to create a new font object.

When creating this new font, you can definitely copy the properties of an existing font object (such as those used by your form), but the two font items are dynamically created simultaneously There is no way to be connected. If the font size changes by changing your form, a new font object will be created with that new size for the form, but your custom bold font object will not be updated.

The only thing that is confusing is that if you have not set a custom font for hair control, then there is little magic on it. They automatically receive the font of their parents (a container control, such as a form). Such properties which retrieve their value from their origin, when they are not explicitly set, they are called ambient qualities, as explained in the ambient properties where applicable. But the result is that the environment goes to the point where you clearly set up the property. So forget about it

To get what you want, we have to change the font size of the format and get a notification in the response, you can create a new bold font object with the new size of your label control. . Fortunately, there is such a mechanism as such. Handle the fontchange event for your form, and in response, create a new font object for your label control. For example:

  Private sub myForm_FontChanged (ByVal Sender as the object, ByVal and EventArgs as MyForm.FontChanged Dim as the old font = myLabel.Font myLabel.Font = New font (myForm.Font, MyForm.Font.Style or FontStyle.Bold) oldFont.Dispose () end sub   

However, I'm not sure if this is really important why It is rare that the font size of a form changes when the application is running. Generally it is only on creation, in that case when you retrieve the value to create a custom font object for your label control, it will already be set correctly.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -