Exposing Font Name Property for Custom Control

D

Deep S.

Hi,

I've created a custom web control for using in my web application.
I want to expose some Font-Name Properties of the control
like i did for the Color and Boolean values, so that in the properties
pane, a proper list is displayed for user selection.
Like for picking up the color i've declared a property with data type
as System.Drawing.Color. This shows the Color Picker in the
Property Window.
For Font Name Picker with which data type should i declare the
property with ??

Thanks for your help in advance.
Regards
Deep S.
 
K

Karsten Lundsgaard

Hi You should use FontInfo, see the sourcecode below :


[
Category("TextBox"),
Description("Font of the textbox.")
]
public FontInfo TextBoxFont
{
get
{
object savedState = this.ViewState["TextBoxFont"];
if ( savedState == null )
{
return myTextBox.Font;
}
return (FontInfo)savedState;
}
set
{
myTextBox.Font.CopyFrom(value);
this.ViewState["TextBoxFont"] = value;
}
}
 
D

Deep S.

Hi Karsten,
Thanks for your reply, but i tried something like this by figuring out
the approach to be taken in my code.
But the property that is coming at the design time for the control
is coming with just one text box. I want to make it something
like we get when we edit the font properties for any other
control like textbox etc through which the user can select
Font Name, Bold, Italic etc properties for my control.

Dim _sysItemFontInfo As System.Web.UI.WebControls.FontInfo

<Bindable(True), Description("Font properties of the list items."),
Category ("ListOptions"), DefaultValue("")> Property [ItemFont]() As
System.Web.UI.WebControls.FontInfo
Get
Return _sysItemFontInfo
End Get
Set(ByVal Value As System.Web.UI.WebControls.FontInfo)
_sysItemFontInfo = Value
End Set
End Property

Maybe there is some problem with my code. But i got no sample/
help related to this issue on MSDN as well as some other sites i know.
Is there anything else i need to do apart from this code?

Thanks for your reply.

Regards
Deep S.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top