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

Help please with a function

Im trying the following code: (pardon the indentations...weird newsreader)

The obvious problem here is that the editPanel object is defined within the
blocks, and out of scope outside of the switch statement where I want to set
some basic parameters before diplaying it (Its a usercontrol).

Anyway, Im trying to avoid creating a "base" object to inherit from in order
to use this code, and I cant cast the object since the later code has no
idea what type it is. Any suggestions?

Thanks

David

private void ShowEditPanel(string editPanelName)

{

switch (editPanelName)

{

case "General":

{

Vortex.UC_AccountGeneral editPanel;

editPanel = new UC_AccountGeneral();

break;

}

case "Numbers":

{

Vortex.UC_AccountNumbers editPanel;

editPanel = new UC_AccountNumbers();

break;

}

case "Address":

{

Vortex.UC_AccountAddress editPanel;

editPanel = new UC_AccountAddress();

break;

}

}

// Set location of panel

editPanel.Account = this.Account;

editPanel.Location = new System.Drawing.Point(128, 64);

editPanel.Width = this.Width - panel2.Width - 35;

editPanel.Height = this.Height - 110;

editPanel.Anchor =

(((

System.Windows.Forms.AnchorStyles.Top |

System.Windows.Forms.AnchorStyles.Bottom)|

System.Windows.Forms.AnchorStyles.Left) |

System.Windows.Forms.AnchorStyles.Right);

Controls.Add(editPanel);

editPanel.Show();

editPanel.BringToFront();

}

Nov 15 '05 #1
1 1607
It does not seem to be a very good approach. The problem that you mentioned
can be dealt with though. You will need to iterate through all the controls
on your form and try to cast all three types, if you do not hit the error,
then it is the one that you need. But this is very cumbersome and will slow
down your code. You also can use Tag property or Name property of this
custom control to catch it. But again, you will have to iterate through
controls on your form.
I think that better way would be to declare all three of them using
different names and make them available in your form. Then you can create a
function that will check wich one of them is not null, and use it
accordingly.

"David Smith" <no****@here.net> wrote in message
news:3f**********@news.athenanews.com...
Im trying the following code: (pardon the indentations...weird newsreader)
The obvious problem here is that the editPanel object is defined within the blocks, and out of scope outside of the switch statement where I want to set some basic parameters before diplaying it (Its a usercontrol).

Anyway, Im trying to avoid creating a "base" object to inherit from in order to use this code, and I cant cast the object since the later code has no
idea what type it is. Any suggestions?

Thanks

David

private void ShowEditPanel(string editPanelName)

{

switch (editPanelName)

{

case "General":

{

Vortex.UC_AccountGeneral editPanel;

editPanel = new UC_AccountGeneral();

break;

}

case "Numbers":

{

Vortex.UC_AccountNumbers editPanel;

editPanel = new UC_AccountNumbers();

break;

}

case "Address":

{

Vortex.UC_AccountAddress editPanel;

editPanel = new UC_AccountAddress();

break;

}

}

// Set location of panel

editPanel.Account = this.Account;

editPanel.Location = new System.Drawing.Point(128, 64);

editPanel.Width = this.Width - panel2.Width - 35;

editPanel.Height = this.Height - 110;

editPanel.Anchor =

(((

System.Windows.Forms.AnchorStyles.Top |

System.Windows.Forms.AnchorStyles.Bottom)|

System.Windows.Forms.AnchorStyles.Left) |

System.Windows.Forms.AnchorStyles.Right);

Controls.Add(editPanel);

editPanel.Show();

editPanel.BringToFront();

}

Nov 15 '05 #2

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

Similar topics

3
by: laurie | last post by:
Hi all, I'm trying to help out a friend who has inherited a client with a PHP shopping cart application. Neither of us know PHP, but I've been muddling my way through, trying to get these old...
6
by: James Walker | last post by:
Can some one help I get an error of 'checkIndate' is null or not an object can someone please help. I can't work out why Thanks in advance James <form> <td height="24" colspan="7"...
7
by: Alan Bashy | last post by:
Please, guys, In need help with this. It is due in the next week. Please, help me to implement the functions in this programm especially the first three constructor. I need them guys. Please, help...
5
by: TrvlOrm | last post by:
Can any one please help me...I am new to JavaScript and I have been struggling with this code for days now and can't figure it out. I would like to get the Buttons to correspond with the action...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
5
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
1
by: al2004 | last post by:
Write a program that reads information about youth soccer teams from a file, calculates the average score for each team and prints the averages in a neatly formatted table along with the team name....
22
by: Amali | last post by:
I'm newdie in c programming. this is my first project in programming. I have to write a program for a airline reservation. this is what i have done yet. but when it runs it shows the number of...
6
by: jenipriya | last post by:
Hi all... its very urgent.. please........i m a beginner in oracle.... Anyone please help me wit dese codes i hv tried... and correct the errors... The table structures i hav Employee (EmpID,...
3
by: gmdune | last post by:
Hi All, I have written a program that doesn't seem to work and I can't figure out why it's not working. It compiles correctly, but when I run it I get prompted by the first couple of printf...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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
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,...

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.