Override MessageBox.Show

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • developing
    New Member
    • Mar 2007
    • 110

    Override MessageBox.Show

    Anyone please provide me with sample code on how do i override the MessageBox class? or more specifically MessageBox.Show ()?

    Thanks a LOT


    Reason: I have a desktop app to which im adding a command line interface. I need to override MessageBox.Show () to not have popups based on certain conditions
  • joedeene
    Contributor
    • Jul 2008
    • 579

    #2
    I don't get what you're asking, what do you mean "Override"? Like make it whenever a messagebox is called not to show? This might be possible in your own form...If it's not what you're asking, please clarify, if you could...

    joedeene

    Edit: Could some mod delete this? i posted this before he added the reason, and i cant seem to delete this myself

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      Originally posted by joedeene
      Edit: Could some mod delete this? i posted this before he added the reason, and i cant seem to delete this myself
      No reason to delete, it'll be fine.

      As to the stopping of MessageBoxes, if its your code, just don't execute the code?
      If you want to stop all MessageBox calls from everyprogram, well if it *can* be done, you willd need to check in with the c++/windows guys for some win32_API to stop them. Possibly a "kiosk" mode type of thing?

      Comment

      • developing
        New Member
        • Mar 2007
        • 110

        #4
        Sorry about the 'edit' confusion because of lack of reason. I should have added the "EDITED" caption....

        Anyways, by 'override', I meant having the implementation of the override keyword. For example. ToString() is defined for every type, but you can still use the 'override' keyword and define a custom ToString() function.

        I was hoping for something like that (of course, it wouldnt be using the override keyword) for MessageBox.Show ()...

        So I have this GUI application with three seperate classes and I am adding a command line interface to it. Everything works fine. The app can figure out when it got called by GUI and when it called throuh CLI.

        I *COULD* have if statements everywhere where MessageBox.Show is used but that will get nasty in some places and seems like there has to be a better way to do it....any suggestions are appreciated

        Not really sure by "kiosk' mode, but I was hoping I could provide my own implementation of MessageBox.Show to the system...

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          You could be abstracting out the messagebox.show .

          Such as like:
          [code=c#]
          public static void DisplayMessage( string msg)
          {
          //some logic to determine if GUI or commandline
          //if gui:
          MessageBox.Show (msg);
          //if commandline:
          //whatever you want to do with the commandline.
          }
          [/code]

          then instead of calling MessageBox.Show (), you call DisplayMessage( )

          Comment

          • Curtis Rutland
            Recognized Expert Specialist
            • Apr 2008
            • 3264

            #6
            As to specifically overriding that method, you cant. You can't derive classes from static classes, so you wouldn't be able to create a child class that you could override the method in.

            Comment

            • developing
              New Member
              • Mar 2007
              • 110

              #7
              Yup, I was thinking about abstracting it out too. Except that I will have to go through the source and replace MessageBox.Show ()....worse comes to worse, thats what I am gonna do...

              I did realize that Show is a static method...so I guess abstraction is the best way to go.

              Thanks people

              Comment

              Working...