473,378 Members | 1,426 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,378 software developers and data experts.

passing control name in function

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();
}
Aug 9 '06 #1
3 3560
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

Aug 10 '06 #2
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
Aug 10 '06 #3
Marc Gravell wrote:
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
Aug 10 '06 #4

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

Similar topics

58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
4
by: Darryl Kerkeslager | last post by:
Here's the function: Public Function SaveToServer(tableName As String, prefix As String, _ changed As Date, Optional recordID As Variant) As Boolean and here's the function call that doesn't...
1
by: sofakingfree | last post by:
I keep getting an invalid property assignment error when tring to reference a subform. All I am trying to do is substitute this: Forms!!.SetFocus for this: FormAndSubForm.SetFocus
3
by: carl.barrett | last post by:
Hi, I have a number of buttons on a form which run mailmerges. Next to each button is a text box/control that the user enters a date into when the letter was created/merged. When the user...
5
by: Ram | last post by:
Hi Friends I want to develope a custom control in .net which can be used with any project. I am writing a function in that class which I want to take any object as parameter. For that I have...
13
by: Deano | last post by:
Apparently you can only do this with one value i.e Call MyAssetLocationZoom(Me!txtLocation, "Amend data") This runs; Public Sub MyAssetLocationZoom(ctl As Control, formName As String) On...
12
by: Andrew Bullock | last post by:
Hi, I have two classes, A and B, B takes an A as an argument in its constructor: A a1 = new A(); B b = new B(a1);
5
by: glenn | last post by:
Hi folks, The problem I have is that a query string works if hard-coded but if I pass a variable to it, it does not work as shown here. This works: querystring="SELECT * FROM USERS WHERE...
8
by: S. | last post by:
Hi all, Can someone please help me with this? I have the following struct: typedef struct { char *name; int age; } Student;
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.