none
Menu system and sub-menu in C#. Need help with coding buttons and forms RRS feed

  • Question

  • I am working on a menu system in C#. It has buttons on Form 1 and sub-menu buttons on form 2. I have buttons to help me move to the next sub-menu on form 2. I am trying to return to the main menu on form 1 and delete form 2, from sight are hide it. I am a little lost on how to code this. Any help will be grateful.


    Thursday, March 5, 2020 5:44 AM

All replies

  • hello friend

    Whether it is window app or web app .Why two forms used not panels

    Thursday, March 5, 2020 7:25 AM
  • I never heard of a menu being without using a form. I am glad the next level in my understanding C# is greater rewarding than the basics. I need the basics first then the complex insight. Thanks for bring my attention to this.

    Thursday, March 5, 2020 7:32 AM
  • This forum is for C#-specific questions only. Please clarify what UI framework (winforms, WPF, XAML, ASP.NET, etc) you're using so we can move your code to the appropriate forum.

    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, March 5, 2020 9:53 PM
    Moderator
  • This forum is for C#-specific questions only. Please clarify what UI framework (winforms, WPF, XAML, ASP.NET, etc) you're using so we can move your code to the appropriate forum.

    Michael Taylor http://www.michaeltaylorp3.net

    OP is asking specifically for technique and programming help as well as UI Design.  The reference to Form1 explicitly denotes a Windows Forms Application.  MS evidently needs to review moderator skills a lot more often.
    Thursday, March 5, 2020 10:02 PM
  • Andrew, your comment is unprofessional and incorrect. Xamarin Forms uses the term forms in its terminology. Legacy web forms do as well. Furthermore if you review many of the posts in this forum you will see people referring to WPF and ASP.NET as "forms". Clarification of the OP's technology is appropriate here.

    If you are unable to provide any guidance to the OP on this topic then please do not bother commenting. The forums is for helping others. Further comments down this path will result in the thread being locked and the post being reported appropriately.


    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, March 5, 2020 10:09 PM
    Moderator
  • Andrew, your comment is unprofessional and incorrect. Xamarin Forms uses the term forms in its terminology. Legacy web forms do as well. Furthermore if you review many of the posts in this forum you will see people referring to WPF and ASP.NET as "forms". Clarification of the OP's technology is appropriate here.

    If you are unable to provide any guidance to the OP on this topic then please do not bother commenting. The forums is for helping others. Further comments down this path will result in the thread being locked and the post being reported appropriately.


    Michael Taylor http://www.michaeltaylorp3.net

    Correction:  You work here.  I'm a volunteer.  eg Your behavior is unprofessional, my behavior is amateurish.

    In reference to the rest of this gibberish:  Form1 is how a Windows Forms application in C# names the default-created Form in a Windows Forms Application.  While the terminology "form" appears in a number of irrelevant and off-topic languages as you so unprofessionally, irrelevantly, and off-topically point out, there would not be an explicit reference such as "Form1" in tandem with C# in the context of the OP.

    I really don't know if your problem, CoolDadTx, is that you're taking drugs you shouldn't be or if you're off drugs you should be taking, but you've been targeting people with this exact kind of BS since at least early last year.  You did it to me in some petulant rant about whether "using" was better than instantiation with manual disposal later, then you locked the thread when proven wrong.

    So yeah.  Make a few more irrelevant posts, make sure to include some more threats of what you'll do if I don't quit pointing out your mistakes, and then lock the thread after slipping in the last word you giant manbaby.

    Or, hey, I dunno, maybe let the OP get help instead of berating them that they're in the wrong Forum for questions about design and workflow in C#.
    Thursday, March 5, 2020 10:16 PM
  • I am working on a menu system in C#. It has buttons on Form 1 and sub-menu buttons on form 2. I have buttons to help me move to the next sub-menu on form 2. I am trying to return to the main menu on form 1 and delete form 2, from sight are hide it. I am a little lost on how to code this. Any help will be grateful.

    This example is the codebehind a single Form. Nothing is added by Designer, just created and destroyed here. Hopefully it will demonstrate the procedure you're looking for.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace csWinForms
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            // These are your billboard or wizard-style panels
            Panel panel0 = new Panel();
            Panel panel1 = new Panel();
            Panel panel2 = new Panel();
    
            // To save on processing time with lots of if-else 
            // to see which panel is visible at any given time, 
            // just use a reference panel to keep track.  You 
            // still have to if-else but it winds up a little 
            // cleaner
            Panel curPanel = null;
    
            // This is a panel that would contain your forward and 
            // back buttons
            Panel buttonsPanel = new Panel();
    
            // These are the forward and next buttons
            Button nextButton = new Button();
            Button prevButton = new Button();
    
            private void Form1_Load(object sender, EventArgs e)
            {
                this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
    
                // For demo purposes I'm just setting each billboard panel to 
                // a different color
                this.panel0.BackColor = Color.Green;
                this.panel1.BackColor = Color.Blue;
                this.panel2.BackColor = Color.Red;
    
                this.curPanel = panel0;
                this.panel0.Visible = true;
                this.panel1.Visible = false;
                this.panel2.Visible = false;
    
                this.panel0.Dock = DockStyle.Fill;
                this.panel1.Dock = DockStyle.Fill;
                this.panel2.Dock = DockStyle.Fill;
    
                this.buttonsPanel.Dock = DockStyle.Bottom;
    
                this.nextButton.Text = @"Next";
                this.nextButton.Dock = DockStyle.Right;
                this.prevButton.Text = @"Previous";
                this.prevButton.Dock = DockStyle.Left;
                // We're starting out on the first panel, 
                // so we can't go further back anyway
                this.prevButton.Enabled = false;
    
                this.buttonsPanel.Controls.Add(nextButton);
                this.buttonsPanel.Controls.Add(prevButton);
    
                this.Controls.Add(buttonsPanel);
    
                // Because they're set to FILL, never add the billboard panels 
                // before the control panels.  This should automagically 
                // arrange the Z-Order correctly.
                this.Controls.Add(panel2);
                this.Controls.Add(panel1);
                this.Controls.Add(panel0);
    
                this.nextButton.Click += new EventHandler(nextButton_Click);
                this.prevButton.Click += new EventHandler(prevButton_Click);
            }
    
            void prevButton_Click(object sender, EventArgs e)
            {
                if (object.ReferenceEquals(this.curPanel, this.panel1))
                {
                    this.panel1.Visible = false;
                    this.panel0.Visible = true;
                    this.curPanel = panel0;
    
                    // Just switched to the first panel so we can't 
                    // go back any further.  Make sure the user 
                    // can see that intuitively
                    this.prevButton.Enabled = false;
                }
                else if (object.ReferenceEquals(this.curPanel, this.panel2))
                {
                    this.panel2.Visible = false;
                    this.panel1.Visible = true;
                    this.curPanel = panel1;
    
                    // Just moved off the last panel so make sure the Next 
                    // button is available
                    this.nextButton.Enabled = true;
                }
                else
                {
                    // You should never even hit this.  We'll just disable 
                    // the prev button whenever we're at panel0
                    MessageBox.Show(@"Can't go any further back!");
                }
            }
    
            void nextButton_Click(object sender, EventArgs e)
            {
                if (object.ReferenceEquals(this.curPanel, this.panel0))
                {
                    this.panel0.Visible = false;
                    this.panel1.Visible = true;
                    this.curPanel = panel1;
    
                    // We just moved off the first panel so make sure the prev 
                    // button is available
                    this.prevButton.Enabled = true;
                }
                else if (object.ReferenceEquals(this.curPanel, this.panel1))
                {
                    this.panel1.Visible = false;
                    this.panel2.Visible = true;
                    this.curPanel = panel2;
    
                    // We just moved into the last panel so make sure the 
                    // next button is disabled
                    this.nextButton.Enabled = false;
                }
                else if (object.ReferenceEquals(this.curPanel, this.panel2))
                {
                    // You should never even hit this.  We'll just disable 
                    // the next button whenever we're at panel2
                    MessageBox.Show(@"Can't go any further forward!");
                }
            }
    
            void Form1_FormClosing(object sender, FormClosingEventArgs e)
            {
                this.prevButton.Click -= this.prevButton_Click;
                this.nextButton.Click -= this.nextButton_Click;
    
                this.prevButton.Dispose();
                this.nextButton.Dispose();
    
                this.buttonsPanel.Dispose();
    
                this.panel2.Dispose();
                this.panel1.Dispose();
                this.panel0.Dispose();
                
            }
        }
    }
    


    Saturday, March 7, 2020 12:58 AM