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

    [RESOLVED] C# Windows Form Project

    I have my entire project coded, my form setup and it debugs perfect. But when I run the processes my form displays as a gray box, like I never set anything up on the form?

    I attached my project as a zip so you can look it over, and show me my errors.
    Attached Files Attached Files

  2. #2
    Join Date
    Nov 2010
    Posts
    42

    Re: C# Windows Form Project

    Your definitelly missing some code:

    Code:
     
    public Form1()
    {
    InitializeComponent();
    }
    That needs to be added to Form1. After that the compiler brings up an argumentexeption based on a null delegate instance in your mtxtHour event handler, I dont no what is going on there but I commented it out and it the GUI shows up.

  3. #3
    Join Date
    Jul 2011
    Posts
    6

    Re: C# Windows Form Project

    It's not that you're necessarily missing that code, you just have it incorrectly typed in. You need to name your form frmTime, or name "public void frmTime()" to "public void Form1()". My attachment might explain this better.

    Depending on which version of Visual Studio you're using (mine is 2008), if you name your form from the properties panel, then Visual Studio will automatically update everything for you.
    Attached Images Attached Images  

  4. #4
    Join Date
    May 2011
    Posts
    44

    Re: C# Windows Form Project

    AGLion: I am using VS 2010. I renamed my form, frmTime from the properties view (the box that displays in the bottom right corner of my VS when I single click on the form) and still same result as before. It will only display a gray form with no buttons, txtbox or labels? If I change frmTime to Form1, I get a debug error that says "Form1: Member names can not be the same as there enclosing type"


    MasterMosley: specifically which line of code are you referring to that you commented out and now the project will display the form as needed?
    Last edited by jo15765; July 29th, 2011 at 02:44 AM.

  5. #5
    Join Date
    Jun 2011
    Location
    .NET4.0 / VS 2010
    Posts
    70

    Re: C# Windows Form Project

    Look at Mastermosleys code closely it is named after the main form and doesn't contain void in it. Once you run the main form it will throw the exception Mastermosley mentioned.

  6. #6
    Join Date
    May 2011
    Posts
    44

    Re: C# Windows Form Project

    AH, I just had to remove the void from it! Sorry, I woke up at 3 a.m. (Eastern Time) because I had forgotten to turn the volume off of my computer, so when the e-mail came in, I woke up. I then was trying to work on it after being in a deep deep sleep, which I do believe I was not even completely co-herent.

    Let me play with all the options this afternoon, and see if everything else is working as needed, if it is, I will mark this thread as solved!

  7. #7
    Join Date
    May 2011
    Posts
    44

    Re: C# Windows Form Project

    I want to add a message box that displays as the form loads that says something like "Welcome to the Form" and then in the same message box and directly under that message display something like "Creation Date: 07/29/11" and then directly under that "Creator: "" or some junk like that, and you have to click a button "OK" to close that message box, and enter data on the form.

    How would I set that up, I can see how to do it with each message displaying in one message box, but I want each message in the same message box aligning under one another?
    Last edited by jo15765; July 29th, 2011 at 08:55 PM.

  8. #8
    Join Date
    Jun 2011
    Location
    .NET4.0 / VS 2010
    Posts
    70

    Re: C# Windows Form Project

    Hmm I don't know too much so my method may not be right but what about making an about box and modifying the properties to fit your needs. Then you can make the form popup when the program starts up.

    Code:
    public Form1()
    {
        InitializeComponent();
    
        //Launch modified about form
        AboutBox1 message = new AboutBox1();
        message.ShowDialog();
    }
    Then in the about box form you can modify it to display the information you want displayed. I'm sure if my method is not effective one of the more knowledgeable members will provide you with the correct method of accomplishing this.

  9. #9
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: C# Windows Form Project

    To display the messages all at once on different lines using a message box you would just need to concanonate them together with a crlf in between each.
    Always use [code][/code] tags when posting code.

  10. #10
    Join Date
    May 2011
    Posts
    44

    Re: C# Windows Form Project

    Data Miser ----- I used + System.Environment.NewLine + after some googling it appears to do the same thing as the CrLF?

    Ubiquitous --- I get the concept of creating a seperate form, and putting a label on it with the data, and adding a button to close the form, whcih then would display my main form. But what would be the code to call the "secondary form" on the load of my primary form?
    Last edited by jo15765; July 29th, 2011 at 11:04 PM.

  11. #11
    Join Date
    Jun 2011
    Location
    .NET4.0 / VS 2010
    Posts
    70

    Re: C# Windows Form Project

    Not sure what a crlf but I'm guessing stuff like \n for new line and such.

    The code to call up the form is in the code I posted above. First you create an instance of the form you want to call up.
    Code:
        // Create instance of the form
        AboutBox1 message = new AboutBox1();
    
        // Display the form as a form that must be closed before main form can be interacted with
        message.ShowDialog();
    Where AboutBox1 is the name of your form containing your information. You can place that code into your form_Load event so that it will bring it up at the start up of your application.

    I hope DataMiser post what crlf means as I am curious now if its something I know and just don't know the terminology to or something I should learn

  12. #12
    Join Date
    May 2011
    Posts
    44

    Re: C# Windows Form Project

    CrLF stands for Carriage Return Line Feed -- I just can't seem to get the syntax right in C# for calling it, thats why I used + System.Environment.NewLine + which does the same thing.
    Last edited by jo15765; July 29th, 2011 at 11:16 PM.

  13. #13
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: C# Windows Form Project

    I do little in C# so am not sure, If memory serves the \n is correct. There is a constant that can be used.

    Constants.vbCrLf

    as well as string functions

    Strings.Chr(13)+Strings.Chr(10)
    Always use [code][/code] tags when posting code.

  14. #14
    Join Date
    May 2011
    Posts
    44

    Re: C# Windows Form Project

    DataMiser --- that an interesting feature in C#, I will have to explore more next week. All, thanks for your help!!

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