views:

70

answers:

5

How do I send the form to the class?

You are making some object?

for example :

       class Myform
{
    public void Myf(Form)
    {
        Form f = new Form();//error        
    }
}




  private void Form1_Load(object sender, EventArgs e)
        {
            Myform mf = new Myform();

            mf.Myf(Form1);//error
        }
+1  A: 

How about

private void Form1_Load(object sender, EventArgs e) 
{ 
    Myform mf = new Myform(); 

    mf.Myf(this);
}

But what exactly are you trying to do? This seems like all kinds of wrong.

Maybe if you tell us what you intend to do, we can help a little better...

astander
Not so many objects made of the form
textBox
Im sorry, say what?
astander
A: 

To define parameters you declare the type, then the parameters itself so on your method you have the type but are missing the parameter name. Fix it by adding changing it to something like this:

public void Myf(Form myVariable)

then in the method, you already have an instance of the type you declared, so you don't need to create a new instance

public void Myf(Form myVariable)
{
    myVariable.... // do stuff with it        
}

And the problem with the second section is that you;re trying to pass the type through, when it requires an instance of the type. And in your case your instance is the Form you ar currently in, so to pass that into it you use this, ie

Myform mf = new Myform();
mf.Myf(this);

Although the way you seem to be trying to do things doesn't seem right, and I think will cause a lot of problems for you in the future. If you can explain exactly what you;re trying to do maybe we can suggest a better way to do it?

Hope that makes some sense!

w69rdy
Not so many objects made of the form
textBox
That's because all of your form are belong to us... ;)
w69rdy
A: 

Not so many objects made of the form؟

      //  public void Myf(Form f,Form f2)
 //   {
       // Form f = new Form();
       // Form f2 = new Form();
   // }

I just want to do some object

    public void Myf(Form)
    {
        Form myform1 = new Form();
        Form myform2 = new Form();

        myform1.Name="form1";
        myform2.Name="form1";


        MessageBox.Show(myform1.Name);
        MessageBox.Show(myform2.Name);
    }
textBox
A: 

This is true

But the class has two input

        public void Myf(Form f,Form f2)
        {
               //
        }
textBox
If you have something to add to your question you should edit your question instead of new answers (this is different from how it works in most forums, but thats the difference between postings in a forum and questions and answers here), so anyone looking at the topic will directly see all the information about the problem. However you still haven't anwered what you are really trying to do (at least I can't figure it out, and I assume that several others face the same problem).
Grizzly
+1  A: 

Sorry, but I don't understand what you're saying.

English seems to be a bit of a problem. To make it easier for us to understand the question, you could try this:

  1. Write your question in your native language (where are you from?)
  2. Go to http://translate.google.com and translate your question into English
  3. Include your question in both languages.

This way, if someone else understands your native language, they might be able to answer. Also, Google Translate might help us in understanding the question a bit better.

PS: FYI, I'm not trying to be rude. I'm not a native English speaker myself and I've had this type of problem in the past. I'm just trying to offer some way to make it easier for everybody to answer the question.

Rafa