Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 15th, 2005, 8:09 PM   #1
brokenhope
Hobbyist Programmer
 
Join Date: Apr 2005
Posts: 126
Rep Power: 4 brokenhope is on a distinguished road
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.
brokenhope is offline   Reply With Quote
Old Sep 16th, 2005, 12:18 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Sep 16th, 2005, 6:53 PM   #3
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
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
Dameon is offline   Reply With Quote
Old Sep 18th, 2005, 8:04 PM   #4
brokenhope
Hobbyist Programmer
 
Join Date: Apr 2005
Posts: 126
Rep Power: 4 brokenhope is on a distinguished road
Oh thanks, Ill try that out, by the way where/what is the documentation? because I havent seen any documentation.
brokenhope is offline   Reply With Quote
Old Sep 18th, 2005, 9:05 PM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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:
Originally Posted by 4GuysFromRolla
Dim lblMessage as New Label()

...

Pretty simple, eh? Next, we need to set the various Label properties we're interested in. For this example, let's set the Text and the Font.Bold property:

lblMessage.Text = "Hello, World!"
lblMessage.Font.Bold = True
__________________
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
DaWei is offline   Reply With Quote
Old Sep 18th, 2005, 9:14 PM   #6
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
In .Net 1.1 at least, the Bold property on the Font class is read only.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon is offline   Reply With Quote
Old Sep 18th, 2005, 9:39 PM   #7
brokenhope
Hobbyist Programmer
 
Join Date: Apr 2005
Posts: 126
Rep Power: 4 brokenhope is on a distinguished road
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.
brokenhope is offline   Reply With Quote
Old Sep 19th, 2005, 6:54 AM   #8
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Sep 19th, 2005, 10:18 PM   #9
brokenhope
Hobbyist Programmer
 
Join Date: Apr 2005
Posts: 126
Rep Power: 4 brokenhope is on a distinguished road
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)
        Next

And 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 Sub

That 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?
brokenhope is offline   Reply With Quote
Old Sep 19th, 2005, 10:48 PM   #10
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:46 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC