473,508 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Copying styles from one control to another

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

Aug 22 '08 #1
2 1156
themes ?
"Josh Valino" <no spam pleasewrote in message
news:Ok**************@TK2MSFTNGP02.phx.gbl...
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

Aug 22 '08 #2
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.

"Josh Valino" <no spam pleasewrote in message
news:Ok**************@TK2MSFTNGP02.phx.gbl...
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
Aug 23 '08 #3

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

Similar topics

0
1975
by: Quinton | last post by:
I'm running a website that uses CSS to format the text and a CGI program Coranto that icludes news updates via SSI. My problem is that some parts of the CSS don't seem to take effect on the...
2
1602
by: Praveen | last post by:
Hi, Is there a way to copy over a table's properties and styles (NOT it's child elements like tbody, trs, etc) into another table, besides doing them manually, one by one? Thanks Praveen
12
2539
by: dan.vendel | last post by:
Hi, I know nothing about javascript, but quite a lot about regulat html and CSS. Have bumped into a problem that people in this fine congregation perhaps can help me with. I'm making a...
3
1464
by: JezB | last post by:
What's the generally accepted approach for using Styles and Stylesheets in a web application based on .aspx files, Web Controls, User Controls, and code-behind modules (c# in my case)? Most style...
3
1779
by: Chris | last post by:
Hi I have another style sheet question: We effectively have a page that has two text boxes on it. We would like one text box to be in one style and the other text box to be in another style....
5
1274
by: Bernie Yaeger | last post by:
When you use xp styles Application.EnableVisualStyles() Application.DoEvents() and you change a control's flat style to 'system', you then are not able to set the control's forecolor,...
10
3776
by: jon | last post by:
I'm trying to use a hidden iframe to print the contents of one div seamlessly. Currently I can create the hidden iframe, copy the contents of the div to the iframe, and print it. I even have a...
0
962
by: matt urbanowski | last post by:
Hi, I have a calendar control on a form in VS2003 and have applied some styles to it. I have separate styles for all of the groups e.g. DayHeaderStyle, DayStyle, NextPrevStyle etc. and one for the...
13
10567
by: writeson | last post by:
Hi all, I'm writing some code that monitors a directory for the appearance of files from a workflow. When those files appear I write a command file to a device that tells the device how to...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7114
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...
1
7034
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
7488
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...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.