Font style
-
I have a label and I want to change the font style to bold or italic programmically.Can anybody tell me the code? Mazy Don't Marry a Person You Can Live With... Marry Someone You Can Not Live Without
Based on ASP.net work (it may not be the same) Object.Font.Bold = true; Object.Font.Italic = true; Object.Font.Name = "verdana"; etc. // Rock
-
Based on ASP.net work (it may not be the same) Object.Font.Bold = true; Object.Font.Italic = true; Object.Font.Name = "verdana"; etc. // Rock
I used this code but there is an error return for it: E:\....(106): Property or indexer 'System.Drawing.Font.Bold' cannot be assigned to -- it is read only Any suggestion? Mazy Don't Marry a Person You Can Live With... Marry Someone You Can Not Live Without
-
I used this code but there is an error return for it: E:\....(106): Property or indexer 'System.Drawing.Font.Bold' cannot be assigned to -- it is read only Any suggestion? Mazy Don't Marry a Person You Can Live With... Marry Someone You Can Not Live Without
ok, I fired up a winforms project and I have no idea. The property is listed as get only in code, but is settable in the designer. // Rock
-
I used this code but there is an error return for it: E:\....(106): Property or indexer 'System.Drawing.Font.Bold' cannot be assigned to -- it is read only Any suggestion? Mazy Don't Marry a Person You Can Live With... Marry Someone You Can Not Live Without
Most of the properties on a Font are read-only; you have to create a new font object and assign it to one you wanted to change. James Sonork ID: 100.11138 - Hasaki "My words but a whisper -- your deafness a SHOUT. I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
-
Most of the properties on a Font are read-only; you have to create a new font object and assign it to one you wanted to change. James Sonork ID: 100.11138 - Hasaki "My words but a whisper -- your deafness a SHOUT. I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
-
Sorry James,Could you give an example?:-O Mazy Don't Marry a Person You Can Live With... Marry Someone You Can Not Live Without
Mazdak wrote: Sorry James,Could you give an example? Certainly :)
Font newFont = new Font(myLabel.Font, // base it off the old font
FontStyles.Bold | FontStyles.Italic // Make it bold and italic
);
myLabel.Font = newFont;If you want to change more than the font style you'll have to extract all of the needed properties from your old font and pass them to the constructor to the Font class. ms-help://MS.NETFrameworkSDK/cpref/html/frlrfsystemdrawingfontclassctortopic.htm The url above is for the .NET documentation; putting you right at the constructor list; since there's way too many for me to want to type :) James Sonork ID: 100.11138 - Hasaki "My words but a whisper -- your deafness a SHOUT. I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
-
Mazdak wrote: Sorry James,Could you give an example? Certainly :)
Font newFont = new Font(myLabel.Font, // base it off the old font
FontStyles.Bold | FontStyles.Italic // Make it bold and italic
);
myLabel.Font = newFont;If you want to change more than the font style you'll have to extract all of the needed properties from your old font and pass them to the constructor to the Font class. ms-help://MS.NETFrameworkSDK/cpref/html/frlrfsystemdrawingfontclassctortopic.htm The url above is for the .NET documentation; putting you right at the constructor list; since there's way too many for me to want to type :) James Sonork ID: 100.11138 - Hasaki "My words but a whisper -- your deafness a SHOUT. I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
-
Mazdak wrote: Sorry James,Could you give an example? Certainly :)
Font newFont = new Font(myLabel.Font, // base it off the old font
FontStyles.Bold | FontStyles.Italic // Make it bold and italic
);
myLabel.Font = newFont;If you want to change more than the font style you'll have to extract all of the needed properties from your old font and pass them to the constructor to the Font class. ms-help://MS.NETFrameworkSDK/cpref/html/frlrfsystemdrawingfontclassctortopic.htm The url above is for the .NET documentation; putting you right at the constructor list; since there's way too many for me to want to type :) James Sonork ID: 100.11138 - Hasaki "My words but a whisper -- your deafness a SHOUT. I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
-
There is a little mistake here James,you should use singular 'FontStyle';) Thanks again:) Mazy Don't Marry a Person You Can Live With... Marry Someone You Can Not Live Without
Mazdak wrote: you should use singular 'FontStyle' Oh man, today isn't my day! Earlier this morning I made another mistake in the data class thread. Maybe thats a sign that I should go to sleep! :) James Sonork ID: 100.11138 - Hasaki "My words but a whisper -- your deafness a SHOUT. I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972