-
October 25th, 2006, 12:14 PM
#1
Passing Data between Controls
I have a question. I created 2 custom controls which my application uses. For simplicity lets call them Ctrl1 and Ctrl2.
How do I pass data from Ctrl1 to Ctrl2.
For instance lets say Ctrl1 changes a color. That same color must be passed to Ctrl2.
OR:
Is it possible to raise an event in Ctrl1 (OnColorChange...for example). This event gets called in the main application. From the main application the color can be passed to Ctrl2.
I believe the Event is the way to do it. Any help would be appreciated
Thanks
-
October 25th, 2006, 05:52 PM
#2
Re: Passing Data between Controls
Well, event is correct idea, for example you created event on ColorChange, so to exchange data you need to create properties like
Code:
public Color MyColor
{
get{return this.color;}
set{this.color=value;}
}
// and event ofcourse
void OnColorChange(object Sender)
{
Ctrl1.MyColor=Ctrl2.SelectedColor;
}
Ofcourse you need to create properties and data fields to both controls
God could improve essentially a
human nature, but he
was too anxious with compatibility
with the monkey.
(Eugeny Goldberg)
-
October 25th, 2006, 08:05 PM
#3
Re: Passing Data between Controls
Thanks, Actually I thought it was more compilcated. I guess I did not explain myself well. But if you goto the help and type Raising Events, there is an example that deals w/ an alarm clock.
It does exactly what I wanted. raising an event that I created in one class and another class consumes the event!
Either way...Thanks for all the help
-
October 26th, 2006, 02:54 AM
#4
Re: Passing Data between Controls
There is a more simple way.
In the form Load event you just add one line of code:
Code:
private void Form1_Load(object sender, System.EventArgs e)
{
label2.DataBindings.Add("ForeColor",label1,"ForeColor");
}
This way whenever the ForeColor of label1 changes, the ForeColor of label2 changes to the same color. No need for events.
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
|