Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. moving all an app's menus into menus.cs?

moving all an app's menus into menus.cs?

Scheduled Pinned Locked Moved C#
visual-studioquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TuringTest1
    wrote on last edited by
    #1

    the vs designer is ok for generating menus but the code gets quite bloaty. is there either a more compact way to generate menus and their click handlers, or alternatively some slick way of collecting them all in a separate "menus.cs" file? TIA ________________________________________ Gosh, it would be awful pleas'n, to reason out the reason, for things I can't explain. Then perhaps I'd deserve ya, and be even worthy of ya.. if I only had a brain!

    U H 2 Replies Last reply
    0
    • T TuringTest1

      the vs designer is ok for generating menus but the code gets quite bloaty. is there either a more compact way to generate menus and their click handlers, or alternatively some slick way of collecting them all in a separate "menus.cs" file? TIA ________________________________________ Gosh, it would be awful pleas'n, to reason out the reason, for things I can't explain. Then perhaps I'd deserve ya, and be even worthy of ya.. if I only had a brain!

      U Offline
      U Offline
      User 260964
      wrote on last edited by
      #2

      I solve this problem using #region directives:

      #region Menus
      private MenuItem mnuFile;
      private MenuItem mnuFileNew;
      private MenuItem mnuFileOpen;
      private MenuItem mnuFileLine1; // A separator.
      private MenuItem mnuFileSave;
      private MenuItem mnuFileSaveAs;
      private MenuItem mnuFileLine2; // Another separator.
      private MenuItem mnuFileExit;
      #endregion

      #region Menu events
      #region File
      private void mnuFileNew_Click(object sender, System.EventArgs e)
      {
      }

      private void mnuFileOpen_Click(object sender, System.EventArgs e)
      {
      }

      private void mnuFileSave_Click(object sender, System.EventArgs e)
      {
      }

      private void mnuFileSaveAs_Click(object sender, System.EventArgs e)
      {
      }

      private void mnuFileExit_Click(object sender, System.EventArgs e)
      {
      }
      #endregion
      #endregion

      Since you use Visual Studio, this would hide the menu code, and add more structure to your source file. - Daniël Pelsmaeker

      And if your dream is to care for your family, to put food on the table, to provide them with an education and a good home, then maybe suffering through an endless, pointless, boring job will seem to have purpose. And you will realize how even a rock can change the world, simply by remaining obstinately stationary. -Shog9

      1 Reply Last reply
      0
      • T TuringTest1

        the vs designer is ok for generating menus but the code gets quite bloaty. is there either a more compact way to generate menus and their click handlers, or alternatively some slick way of collecting them all in a separate "menus.cs" file? TIA ________________________________________ Gosh, it would be awful pleas'n, to reason out the reason, for things I can't explain. Then perhaps I'd deserve ya, and be even worthy of ya.. if I only had a brain!

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        You could just type everything manually. Using the designers isn't magic - they generate code. Instead of using the designer - just type it yourself. Write a class with your menus, instantiate it, and assign that as the menu for your application.

        -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups