|
-
May 23rd, 2007, 10:49 PM
#1
Thread Starter
Hyperactive Member
[2005] Custom Property Default Value for fonts
How would I set a Font Properties DefaultValue.
I am currently using:
Dim f as Font = New Font("Tahoma", 8.25!)
then in the property:
<DefaultValue(GetType(Font), "f")>
But the property defaults to "Franklin Gothic Medium" when I rightclick it and select Reset.
What am I doing wrong?
Prefix has no suffix, but suffix has a prefix.
-
May 24th, 2007, 12:19 AM
#2
Re: [2005] Custom Property Default Value for fonts
It's important to differentiate between an initial value and a default value and also to identify what each is for and what each can do. The initial value of a property is the value that property has when the instance is first created. That is what I believe you want. The default value, as set by the DefaultValue attribute, is not necessarily the same as the initial value. The default value exists for a very specific purpose: to allow you to right-click a property in the designer and select "Reset". The initial value and the default value may be completely different.
Also, it is not possible to set the default value to a variable. A properties default value must be a constant, which means it can only be one of the inbuilt VB.NET data types, e.g. String, Char, Integer, Boolean, Date, etc. It is not possible to set a default value for a property of type Font.
-
May 24th, 2007, 11:32 AM
#3
Thread Starter
Hyperactive Member
Re: [2005] Custom Property Default Value for fonts
It is not possible to set a default value for a property of type Font.
I figured it out. The reason it was showing "Franklin Gothic Medium" is because that is the only font on my system that starts with F.
Here is the code that works:
Code:
<DefaultValue(GetType(Font), "Lucida Console")>
That will make Lucida Console the default font for that property.
That is what I believe you want.
Sorry If I confused you. I do want the DefaultValue and not the initial value. I set all my initial values in Sub New. Is that the correct way to do it?
So, I could only set the family of the DefaultValue and not the rest of the font properties. Any idea how those are set?
Thank you again.
Prefix has no suffix, but suffix has a prefix.
-
May 24th, 2007, 06:24 PM
#4
Re: [2005] Custom Property Default Value for fonts
Like I said, you can only set default values using constants. You can only pass literal values or declared constants to the DefaultValueAttribute constructor. There is no way to specify a literal Font and thus there's also no way to create a constant of type Font. Your other code was working because you were specifying the literal string "f". That literal had no connection whatsoever with your variable 'f'.
-
Nov 6th, 2010, 06:12 AM
#5
Member
Re: [2005] Custom Property Default Value for fonts
Yes, there is!
At least in my VS2008 it works!
Code:
Private _MyFont As New Font("Times New Roman", 18, FontStyle.Bold)
<CategoryAttribute("Application"), Browsable(True), _
DescriptionAttribute("Application Font"), DefaultValue(GetType(Font), "Times New Roman,18,Bold")> _
Public Property MyFont() As Font
Get
Return _MyFont
End Get
Set(ByVal value As Font)
_MyFont = value
Me.Invalidate()
End Set
End Property
Work perfectly!
-
Nov 6th, 2010, 07:20 AM
#6
Re: [2005] Custom Property Default Value for fonts
 Originally Posted by Tomazas
Yes, there is!
At least in my VS2008 it works!
Code:
Private _MyFont As New Font("Times New Roman", 18, FontStyle.Bold)
<CategoryAttribute("Application"), Browsable(True), _
DescriptionAttribute("Application Font"), DefaultValue(GetType(Font), "Times New Roman,18,Bold")> _
Public Property MyFont() As Font
Get
Return _MyFont
End Get
Set(ByVal value As Font)
_MyFont = value
Me.Invalidate()
End Set
End Property
Work perfectly! 
Nice. I stand corrected.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|