CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2006
    Posts
    306

    [RESOLVED] Error With Input Dialog

    All variables are defined.
    Code:
            static void GetUserInput(string Text)
            {
                FormInput IForm = new FormInput();
                IForm.LabelQuestion.Text = Text;
                IForm.ButtonAccept.Click += new EventHandler(ButtonAccept_Click);
            }
    
            static void ButtonAccept_Click(object sender, EventArgs e)
            {
                Button B = (Button)sender;
                FormInput F = (FormInput)B.FindForm();
                Input = F.TextBoxAnswer.Text;
                F.Close();
                F.Dispose();
            }
    Gives me this. It's in a static class.

    Code:
    An object reference is required for the non-static field, method, or property 'W4MAdvancedTweakLoaderB2.Program.Input'
    Do you know why it's giving me this error?

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Error With Input Dialog

    You are trying to access a non-static object "Input" from a static method. For obvious reasons that cannot work because the static method can be called before the non-static object exists. There is no reason for those methods to be static anyway, so just make it an instance method.

  3. #3
    Join Date
    May 2006
    Posts
    306

    Re: Error With Input Dialog

    Silly me, I fixed it, "Input" was not static.

    Also, when it pops up, even if TopMost is set to true, it will not be above like an actual dialog. How do I fix this?
    Last edited by code?; October 17th, 2009 at 04:16 PM.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Error With Input Dialog

    The structure of your code seems a bit complicated, maybe we can help organize it a bit better. Can you tell me what class the methods GetUserInput and ButtonAccept_Click are from? Are they part of another form class?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured