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. same code in menus and button

same code in menus and button

Scheduled Pinned Locked Moved C#
databasequestion
4 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.
  • C Offline
    C Offline
    cishi_us
    wrote on last edited by
    #1

    i have a some lines of code in the button which is providing a functionality of saving data into database.I like to do the same funtionality(saving data into database),what i have to do.,write the same code in menu item ???? or any shortcut way to complete this task.

    D W 2 Replies Last reply
    0
    • C cishi_us

      i have a some lines of code in the button which is providing a functionality of saving data into database.I like to do the same funtionality(saving data into database),what i have to do.,write the same code in menu item ???? or any shortcut way to complete this task.

      D Offline
      D Offline
      DavidNohejl
      wrote on last edited by
      #2

      hi, of course you should have this code only once! you can call same handler for button (e.g btnSave_Click) from menu handler (miSave_Click) as

      void miSave_Click(object sender, EventArgs args )
      {
      btnSave_Click(this, null);
      }

      or you can have method, say OnSave() with code for saving and both in menu and button hanlder call this function. David Never forget: "Stay kul and happy" (I.A.)
      David's thoughts / dnhsoftware.org / MyHTMLTidy

      1 Reply Last reply
      0
      • C cishi_us

        i have a some lines of code in the button which is providing a functionality of saving data into database.I like to do the same funtionality(saving data into database),what i have to do.,write the same code in menu item ???? or any shortcut way to complete this task.

        W Offline
        W Offline
        WujekSamoZlo
        wrote on last edited by
        #3

        You can write a separate method and call it from button and menu events. It's called code centralization (I think). At least I do that.

        D 1 Reply Last reply
        0
        • W WujekSamoZlo

          You can write a separate method and call it from button and menu events. It's called code centralization (I think). At least I do that.

          D Offline
          D Offline
          DavidNohejl
          wrote on last edited by
          #4

          WujekSamoZlo wrote: It's called code centralization (I think). I stand corrected. David Never forget: "Stay kul and happy" (I.A.)
          David's thoughts / dnhsoftware.org / MyHTMLTidy

          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