C# forms query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • moorcroft
    New Member
    • Mar 2008
    • 57

    C# forms query

    Hi i'm pretty new to using Visual Studio C#. I am creating an EPOS system for an off license and at the moment I am climatizing myself to using Windows Forms.

    This is how I plan for it to be set up:

    I have created a main form. On the left hand side there are two group boxes one on top of the other. On the right hand side I am leaving it as a big blank square. The top left box lists the items scanned in with their prices. The bottom left box has buttons for example 'Total', 'Void Sale', 'No Sale' etc. What I am planning is that every screen on the EPOS uses this main form and has its own separate controls in the big blank square on the right.

    The stage I am at now is creating the log in screen and so I have hit Add New Item and chosen 'Inherited Form' (choosing the default main form to inherit from). This inherited form is called Login and has the same layout as the main form as I had hoped. Now I have added my log in controls into the big blank square on the right but when I hit run to test the app, all it shows is the original main form with the big blank square and not the log in controls.

    Can someone please point me out where I have gone wrong. Maybe I'm not understanding the inherited form option correctly?

    Thanks
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    In your Program.cs file, there will be a section with the line Application.Run (...)
    Whatever form is in that ( ) will be the form that runs at program startup. It's probably your "template" form since it was the first one added to the project.

    Comment

    • moorcroft
      New Member
      • Mar 2008
      • 57

      #3
      Yeh that's what it shows, but my login form has the following setup:

      Code:
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Text;
      using System.Windows.Forms;
      using System.Data.SqlClient;
      using System.Configuration;
      
      namespace EposSystem
      {
          public partial class Login : EposSystem.Form1
          {
              public Login()
              {
                  InitializeComponent();
              }
      
              private void btnLogin_Click(object sender, EventArgs e)
              {
                  //login script.....
              }
      }
      How do I get the form to display the user controls and login button

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        So if you make the line be this:
        Application.Run (new Login());

        It still does not work?

        Comment

        • moorcroft
          New Member
          • Mar 2008
          • 57

          #5
          For some reason it now displays the main form with the blank grey square on the right, and then when I hit close, it closes it and opens the login form, can you think of why that may be?

          Should I be just use one form for the whole application and just change the visiblity settings for the controls for the user to change between screens?

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            That sounds like you have this in your Program.cs file:
            Code:
            Application.Run(new Form1());//get rid of this line
            Application.Run(new Login());

            Comment

            • moorcroft
              New Member
              • Mar 2008
              • 57

              #7
              lol sorry just realised that id been playing about with the login procedure and forgot to take a line out, thanks for the help, for now......

              Comment

              • moorcroft
                New Member
                • Mar 2008
                • 57

                #8
                ok, i've kinda hit a brick wall here. Do you think it's best to use just one form for this whole application and have containers which contain user controls and just hide them and make them visible according to user selection? For example a user logs in, and the login container becomes hidden and the main categories screen becomes visible?

                This would be hard to design as I would be creating a large number of containers on top of each other. Would there be any other way round this?

                Thanks

                Comment

                • Plater
                  Recognized Expert Expert
                  • Apr 2007
                  • 7872

                  #9
                  You can add a Form to another Form, that might make it more usefull to you?

                  Comment

                  • moorcroft
                    New Member
                    • Mar 2008
                    • 57

                    #10
                    how do I do that? Do I just create a form the size of the blank space ? How do I insert it into the parent form

                    Comment

                    • Plater
                      Recognized Expert Expert
                      • Apr 2007
                      • 7872

                      #11
                      Originally posted by moorcroft
                      how do I do that? Do I just create a form the size of the blank space ? How do I insert it into the parent form
                      There's a setting or two that has to be done on the forms that I can't think of off hand. but it's roughly the same as adding a control to the form (since Form inherits from Control as well)

                      Comment

                      • moorcroft
                        New Member
                        • Mar 2008
                        • 57

                        #12
                        still havent managed to work out what to do here. Am trying to embed a form within a form and can see no way of doing it - Please help!

                        Comment

                        • r035198x
                          MVP
                          • Sep 2006
                          • 13225

                          #13
                          Originally posted by moorcroft
                          still havent managed to work out what to do here. Am trying to embed a form within a form and can see no way of doing it - Please help!
                          Step back a bit and start designing your interface again. Draw some flow diagrams if you have to. Each control you put should ideally have a well defined and specific job. If you have to put things on top of another control, use a panel rather than a form.

                          Comment

                          • moorcroft
                            New Member
                            • Mar 2008
                            • 57

                            #14
                            Thats the problem that I am having. I have one main form and on the right half of it is where new controls appear. The left half stays static and data appears on it as users navigate through the panels on the right. I'm just wondering how I am meant to design multiple panels for one blank space on the form.

                            The idea is that the user login panel appears in the blank space, and then when a successfull login happens, this login panel dissappears and the main category buttons appear in a panel in its place. I am wondering how to design multiple panels that are going into the same spot.

                            Comment

                            • r035198x
                              MVP
                              • Sep 2006
                              • 13225

                              #15
                              CardLayout is what you want. There are several implementations for it like the one I gave there.
                              I'd keep the Log in screens separate from the rest of the application screens though.

                              Comment

                              Working...