473,395 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Color properties of Controls

Hello All,

While it seems like it should be simple, I am having a problem finding an
answer for this one...

I am building a control where I want one property to be a color. I want the
property to work exactly as any other color property for the standard
controls. That is, I want to be able to put a color name (Red) or HTML/style
string (#FF0000) into the box, and have it persisted that way.

I want the property return type to be Color (rather than, say, string), so
the user can take advantage of using the standard Color pulldowns in the
Properties browser.

Please, show me that it's as simple as it sounds, and I'm just overlooking
something stupid....

Thanks,
PAGates

Oct 9 '06 #1
1 862
Hi Pagates,

Here's working example that should help you:

using System;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ExampleNamespace.WebControls
{
/// <summary>
///
/// </summary>
[ParseChildren(false)]
[ToolboxData("<{0}:ColorfulLabel runat=server></{0}:Menu>")]
public class ColorfulLabel : WebControl
{

#region Properties

[PersistenceMode(PersistenceMode.Attribute)]
public System.Drawing.Color TextColor
{
get
{
object value = ViewState["TextColor"];
return value == null ? System.Drawing.Color.Empty :
(System.Drawing.Color)value;
}
set
{
ViewState["TextColor"] = value;
}
}

public string Text
{
get
{
string value = (string) ViewState["Text"];
return value == null ? String.Empty : value;
}
set
{
ViewState["Text"] = value;
}
}
#endregion

/// <summary>
///
/// </summary>
protected override HtmlTextWriterTag TagKey
{
get
{
return HtmlTextWriterTag.Span;
}
}

/// <summary>
///
/// </summary>
/// <param name="output"></param>
protected override void RenderContents(HtmlTextWriter writer)
{
writer.AddAttribute("color", TextColor.ToString());
writer.RenderBeginTag(HtmlTextWriterTag.Font);
writer.Write(Text);
writer.RenderEndTag();
}
}
}

--
Milosz Skalecki
MCP, MCAD
"pagates" wrote:
Hello All,

While it seems like it should be simple, I am having a problem finding an
answer for this one...

I am building a control where I want one property to be a color. I want the
property to work exactly as any other color property for the standard
controls. That is, I want to be able to put a color name (Red) or HTML/style
string (#FF0000) into the box, and have it persisted that way.

I want the property return type to be Color (rather than, say, string), so
the user can take advantage of using the standard Color pulldowns in the
Properties browser.

Please, show me that it's as simple as it sounds, and I'm just overlooking
something stupid....

Thanks,
PAGates
Oct 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Johann Blake | last post by:
I am creating PictureBox controls at runtime in code and not at design time. These controls do get created and appear. These controls have a form as their container. Not all of the controls I...
1
by: Thanks | last post by:
I have a routine that is called on Page_Init. It retrieves folder records from a database which I display as Link Buttons in a table cell. I set the table cell's bgcolor to a default color (say...
2
by: Rubble | last post by:
Hello, Ive searched all over the net trying to find an answer to this...so anybody with some expertise in this area would be greatly appreciated. Background: I have a webform that loads a...
2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
1
by: Jeff Smith | last post by:
Can I load custom web user controls dynamically and access the properties and methods without having to explicitly define custom control types (example 2 below). I have custom web control named...
4
by: Hugh O | last post by:
Hi, I have been able to use the following kinds of code to access basic information on the individual controls that would be in any Web page. ?Me.Controls(1).Controls(56).GetType.Name ' ...
1
by: Christophe Peillet | last post by:
I have a CompositeControl with two types of properties: 1.) Mapped Properties that map directly to a child control's properties (ex.: this.TextboxText = m_txt.Text). These properties are handled...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
3
by: shapper | last post by:
Hello, I would like some confirmation on events. Should controls be added to page or to their parent controls in Page.Load event wrapped by "If Not PostBack"? And in which event should the...
10
by: Derek Hart | last post by:
I am going in circles trying to loop through properties on 3rd party controls. For example, I have a textbox that has its maximum length located at MyTextBox.Properties.MaxLength - instead of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.