passing control name in function

  • Thread starter Thread starter billq
  • Start date Start date
B

billq

Hello,
I have two custom control which will share a similar graphing function.
The graphing function needs to communicate back to the calling control
to gather information. I would like to send the control name via an
event handler to the graphing function and use the control name to
communicate with the correct control. I tried the following code
without success. any help would be greatly appreciated.
thanks
bill


private void OnLinearChanged()
{
SetUpTheGraph(userLinearPanelControl);
}

private void OnSinChanged()
{
// SetUpTheGraph(userSinPanelControl);
}

private void SetUpTheGraph(Control s)
{
s.SetRect(myGraphingPanel.ClientRectangle);
s.SetQueue();
myGraphingPanel.SetQ(s.GetQueue());
myGraphingPanel.Invalidate();
}
 
I'm not 100% what is what here - i.e. which control holds which method,
but to me it sounds like you just want to make the SetUpTheGraph method
available to both classes; I would normally do this along the lines of:

abstract class GraphControl : Control { // note remove abstract if you
use the designer
protected void SetupGraph(Panel panel) { // whatever looks like
myPanel...
this.SetRect(panel.ClientRectangle);
this.SetQueue();
panel.SetQ(s.GetQueue());
panel.Invalidate();
}
}
class SomeControl1 : GraphControl {
// ...
private void OnLinearChanged() {
SetupGraph();
}
}
class SomeControl2 : GraphControl {
// ...
private void OnLinearChanged() {
SetupGraph();
}
}

You could also achieve similar via a public static GraphUtils class
with a method that accepts a GraphControl as well, or an interface.
Could also make the panel available on the interface / base class (as
virtual to be overridden) to remove the panel param from the method.

Does this help? Or have I misunderstood things? (it would help if it
was clear what was where...)

Marc
 
Oops; I missed the panel from the calls to SetupGraph() [the danger of
pre-caffeine posting]; you could also consider (if feasible) putting the
panel iteslef on the base-class, accessible to the sub-classes (via a
protected property); then they wouldn't even need this.

Marc
 
Marc said:
Oops; I missed the panel from the calls to SetupGraph() [the danger of
pre-caffeine posting]; you could also consider (if feasible) putting the
panel iteslef on the base-class, accessible to the sub-classes (via a
protected property); then they wouldn't even need this.

Marc
Thanks Marc

I did come up with a solution. I was not comfortable with how I
explained the situation. The queue data resides in the linear and sin
class. I needed to copy that data to the graphing panel class in order
to draw the graph. that way each different type of graph is responsible
for calculating its own data and, they all use the panel code in order
to draw the graph.
thanks
bill
 

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

Back
Top