![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Apr 2005
Posts: 126
Rep Power: 4
![]() |
Cant Change Font Properties, Urgent
Im using VB .NET, and it will not let me change the font of a label or a textbox at all.
lblMessage.Font.Bold = True I get an error, that the .Bold propertie is readonly. Is there anyway I can override that so I can change the properties? This is urgent because it is part of my project in my computer science class (to enhance a simple text application), and I can not get this thing to work, this is the last thing I really have until im done. |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
There's nothing wrong with the basic premise of that statement. Your problem must be in the surrounding circumstances.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
You create a new instance of Font and assign it to the control's Font property. Such as
MyControl.Font = New Font(MyControl.Font, _ MyControl.Font.Style Or FontStyle.Bold) ...from the documentation :/
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Apr 2005
Posts: 126
Rep Power: 4
![]() |
Oh thanks, Ill try that out, by the way where/what is the documentation? because I havent seen any documentation.
|
|
|
|
|
|
#5 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
I don't have VB docs, but there are a number examples on the net with your exact syntax. Perhaps there's a constraint if it isn't instantiated with the right constructor....
Quote:
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
|
#6 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
In .Net 1.1 at least, the Bold property on the Font class is read only.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 |
|
|
|
|
|
#7 |
|
Hobbyist Programmer
Join Date: Apr 2005
Posts: 126
Rep Power: 4
![]() |
Yes that is what I have, DaWei, I infact did try that, and of course it didn't work, because it is readonly. Is there any reason they made it read-only?
Edit The above code worked, is there anyway to turn the style off though? lblFontPreview.Font = New Font(lblFontPreview.Font, lblFontPreview.Font.Style Or Not FontStyle.Bold) I cant figure out the logic and its really screwing me up. That right there applys all properties to the label, instead of just leaving out FontStyle.Bold, the logic in my mind says, apply all lblFontPreview.Font.Style properties, and not bold... I dont even understand this Or crap, Or should mean either or, not be a transition between what to apply... Last edited by brokenhope; Sep 18th, 2005 at 10:00 PM. |
|
|
|
|
|
#8 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Say that a bit pattern, Style, is 00111, and Bold is 00001. If you "not" Bold, it becomes 11110. If you OR that with Style, Style becomes 11111. That isn't removing Bold. Is that the thrust of your question? If so, you say, Style AND NOT Bold, which even sounds logical, right? Delve into some boolean algebra.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#9 |
|
Hobbyist Programmer
Join Date: Apr 2005
Posts: 126
Rep Power: 4
![]() |
Ah, thanks a lot, I understand now, I actually did get close to that, but I tried OR NOT Bold, not And Not bold... but I get it now, its all working now. I think this is the last question I have to do with fonts. I have a listbox that adds all fonts on the system to a listbox:
For Each fntFont As FontFamily In FontFamily.Families
cmbFontFace.Items.Add(fntFont.Name)
NextAnd then I have it so whenever something changes the font preview changes, but theres a problem. Private Sub cmbFontFace_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbFontFace.SelectedIndexChanged
lblFontPreview.Font = New Font(cmbFontFace.Text, lblFontPreview.Font.Size, lblFontPreview.Font.Style, GraphicsUnit.Point)
End SubThat runs fine, but there are a few fonts that when I select them, they dont support regular style, or bold style, or italic style, or whatever, and the program closes. I could not figure out how to do any checking in that last bit of code to see if not only the font exists, but what styles it supports, and if its generaly useable at all, I looked through the fontfamily. properties and couldnt find anything of help, so do you know of a way I can check what it supports? |
|
|
|
|
|
#10 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Truthfully, I have no clue. Is there not some set of capabilities you can query? Or perhaps a special value of the return or a status function you can ask or an invalid handle you can check? There has to be something to save your butt from a termination. Maybe check the Font constructor docs.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|