Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Can you please solve the problem ?

kishore_peddikishore_peddi Member Posts: 176
Hi,

I have the following Syntax :

Panel1.Contros.Add(Button1);

I want to make it as generic, not specific to Panel1 (It may be Panel1, Panel2...etc...).During runtime i can pass either "Panel1" or "Panel2" or etc... Is there any way to do that ?

Here are the ways I think so

1. Pointer Technique
2. Object reference
3. Handle

Can you give me sample example on each of them how to use them ?

Advance ThanX for your time & patience.

Cheers,
Kishore

Comments

  • Alex81Alex81 Member Posts: 2
    : Hi...
    : Well, you can do something like this:
    :
    : You can add a method called AddControlToPanel to the Form class as follows:
    :
    : private void AddControlToPanel(Control c, Panel p)
    : {
    : // You should initialize the properties of c before adding it to p
    : p.Controls.Add(c);
    : }
    :
    : And you can add any object that inherits from Control to any panel from any place in your Form class body:
    :
    : AddControlToPanel(button1, panel1);
    : AddControlToPanel(button2, panel1);
    : AddControlToPanel(textBox1, panel2);
    : AddControlToPanel(textBox2, panel2);
    : AddControlToPanel(listView1, panel3);
    : AddControlToPanel(listView2, panel3);
    :
    :
    : I hope it will be helpful for you...
    : Bye...


    : Hi,
    :
    : I have the following Syntax :
    :
    : Panel1.Contros.Add(Button1);
    :
    : I want to make it as generic, not specific to Panel1 (It may be Panel1, Panel2...etc...).During runtime i can pass either "Panel1" or "Panel2" or etc... Is there any way to do that ?
    :
    : Here are the ways I think so
    :
    : 1. Pointer Technique
    : 2. Object reference
    : 3. Handle
    :
    : Can you give me sample example on each of them how to use them ?
    :
    : Advance ThanX for your time & patience.
    :
    : Cheers,
    : Kishore
    :

Sign In or Register to comment.