Passing a TabPage as a parameter

D

Dom

I have 5 TabPages, and I pass one of them to a procedure. How do I
know which page I have?

All I can think of is using the Name property of the TabPage.

void SetPage (TabPage t)
{
if (t.Name = "tabFirst") {...}
else if (t.Name = "tabSecond") {...}
}
 
N

Nicholas Paldino [.NET/C# MVP]

Dom,

You already are passing a TabPage to the procedure. It appears though
that you want to have separate logic depending on a property of the page (in
this case, the Name property). In situations like these, you have to have
conditional statements (like you have now) or have separate methods which
you call for different values on the property you are switching on.

Hope this helps.
 
D

Dom

Maybe I didn't explain myself well. I am passing one of the TabPages
to a procedure. How do I know, *within the procedure*, which TabPage
has been sent. Should I branch on the Name property, or on the Text
Property, or set the Tag property and branch on that, etc? Is there a
best practive here?
 
N

Nicholas Paldino [.NET/C# MVP]

Dom,

That's completely up to you and what you are doing with the TabPage.
There can't be a best practice because the domain is so unique. It all
depends on what the rules are. For example, if know know that the Name
property is going to be unique and keyed to a certain tab page, then use
that. Or the Text property, or the Tag property. It's completely up to
you.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Dom said:
Maybe I didn't explain myself well. I am passing one of the TabPages
to a procedure. How do I know, *within the procedure*, which TabPage
has been sent. Should I branch on the Name property, or on the Text
Property, or set the Tag property and branch on that, etc? Is there a
best practive here?

Why is important for you to know that?

In any case, you could pass another parameter that indicate which tab you
are dealing with, it could be either the index or a descriptive name, or
even an enum.
 

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

Top