tags:

views:

45

answers:

1

hi

i made a class that make registration to my WinCE program.

how i can from the class draw pannel + textbox, and catch the enter press

from the textbox ?

i try to do this:

   TextBox tb=new TextBox();
tb.Location=new Point(10,10);

Panel pn=new Panel();
pn.Dock=DockStyle.Fill;
pn.Controls.Add(tb);

this.Controls.Add(pn);



 but i got error in: this.Controls.Add(pn);

is there any simple sample code for this ?

thank's in advance

A: 

Your question is missing some important context. I built a simple form using your code and it ran just fine. Form1 is just the default form that shows up when you create the new device application.

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        AddMyHardcodedAdditions();
    }

    void AddMyHardcodedAdditions()
    {
        TextBox tb = new TextBox();
        tb.Location = new Point(10, 10);

        Panel pn = new Panel();
        pn.Dock = DockStyle.Fill;
        pn.Controls.Add(tb);

        this.Controls.Add(pn);
    }
}

EDIT To address your comment.

I believe you are misunderstanding the this keyword. If you're building this from MyClass and it has no Controls collection, you cannot call this.Controls ... anywhere with MyClass without a compilation error.

You could add an InsertControl method on your Form or Control class like so:

public void InsertControl(Control control)
{
    this.Controls.Add(control);
}

... and call it from your MyClass code like so:

MyForm myForm = ...; //set by you at some point

...

void AddMyHardcodedAdditions()
{
    ...

    myForm.InsertControl(pn);
}
Austin Salonen
i got this Error: Error 1 'DllGUI.MyClass' does not contain a definition for 'Controls' and no extension method 'Controls' accepting a first argument of type 'DllGUI.MyClass' could be found (are you missing a using directive or an assembly reference?) D:\C#-test\Class_GUI\DllGUI\DllGUI\MyClass.cs 21 18 DllGUI
Gold