Copying styles from one control to another

J

Josh Valino

Hi,

I'd like to take the style properties from one control and apply them all to
the properties of another control, where they relate. The situation is
this:

I have a TreeView control, and the SelectedNodeStyle has some things set.
In addition to the TreeView, I have a few LinkButton controls. A user can
select a node in the tree or one of the LinkButton. I'd like the
LinkButtons to have the same look that a selected node has when it's
selected in the tree. Right now, I'm doing this:

///CODE
private void SomeLinkButton_Click(object sender, EventArgs e)
{
if (this.Tree.SelectedNode != null)
{
this.Tree.SelectedNode.Selected = false;
this.FormTitle.Select(this.Tree.SelectedNodeStyle);
}
}


//extension method in a static class
public static void Select(this LinkButton linkButton, Style style)
{
linkButton.Font.Bold = true;
linkButton.Font.Bold = style.Font.Bold;
linkButton.BackColor = style.BackColor;
linkButton.ForeColor = style.ForeColor;
}
///END OF CODE

I'd like it such that if anyone comes along and specifies additional
properties to the SelectedNodeStyle, he won't have to update the extension
method. Is there a more efficient way than what I currently have? I could
just manually add all the property mappings in my extension method, or I
could reflect all the properties out. I'm not excited by either solution,
so I'm curious if anyone has any other ideas. Oh, and tragically, just
mapping the same CssClass property won't work because of insane political
reasons that it hurts to think about.

Thanks
 
H

HillBilly

Dippity-do easy using a Skin after choosing to use either
[Theme|StyleSheetTheme] as we then go to PreInit, find the control and
change its SkinID property to whatever we want and the predeclared
properties in the skin are bound to the control.

We can do the same thing without using skins and themes in PreInit by
binding the CssClass property to a control.
 

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

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top