Close window after MessageBox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • PawelR

    Close window after MessageBox

    Hello group,
    In my apps I connection to SQL database.
    try
    {
    //connect to db
    }
    catch
    {
    MessageBox("Err or Connect. Close Apps?","Sql
    Error",MessageB oxButtons.OKCan cel,MessageBoxI con.Error);

    }
    When db is connection error apps show messagebox with button OK and Cancel.
    My question: How close this application after OK, and continuue apps after
    Cancel?


    catch
    {
    MessageBox("Err or Connect","Sql
    Error",MessageB oxButtons.OK,Me ssageBoxIcon.Er ror);
    Close();
    }
    Not work.


    Thx PawelR
  • PawelR

    #2
    Re: Close window after MessageBox

    Hello,
    In my apps this code is before

    InitializeCompo nent();

    In article <MPG.19eb76e257 05e3c2989688@ne ws.tpi.pl>,
    pawelratajczak@ poczta.onet.pl says...[color=blue]
    > Hello group,
    > In my apps I connection to SQL database.
    > try
    > {
    > //connect to db
    > }
    > catch
    > {
    > MessageBox("Err or Connect. Close Apps?","Sql
    > Error",MessageB oxButtons.OKCan cel,MessageBoxI con.Error);
    >
    > }
    > When db is connection error apps show messagebox with button OK and Cancel.
    > My question: How close this application after OK, and continuue apps after
    > Cancel?
    >
    >
    > catch
    > {
    > MessageBox("Err or Connect","Sql
    > Error",MessageB oxButtons.OK,Me ssageBoxIcon.Er ror);
    > Close();
    > }
    > Not work.
    >
    >
    > Thx PawelR
    >[/color]

    Comment

    • Stefan

      #3
      Re: Close window after MessageBox

      hi Pawel
      use the dialogresult object
      DialogResult dlr = (Messagebox.Sho w("blablabla" ,
      MessageBoxButto ns.OkCancel)
      if (dlr == DialogResult.Ok )
      {
      close();
      }
      else
      {
      do...;
      }
      "PawelR" <pawelratajczak @poczta.onet.pl > wrote in message
      news:MPG.19eb76 e25705e3c298968 8@news.tpi.pl.. .[color=blue]
      > Hello group,
      > In my apps I connection to SQL database.
      > try
      > {
      > //connect to db
      > }
      > catch
      > {
      > MessageBox("Err or Connect. Close Apps?","Sql
      > Error",MessageB oxButtons.OKCan cel,MessageBoxI con.Error);
      >
      > }
      > When db is connection error apps show messagebox with button OK and[/color]
      Cancel.[color=blue]
      > My question: How close this application after OK, and continuue apps after
      > Cancel?
      >
      >
      > catch
      > {
      > MessageBox("Err or Connect","Sql
      > Error",MessageB oxButtons.OK,Me ssageBoxIcon.Er ror);
      > Close();
      > }
      > Not work.
      >
      >
      > Thx PawelR[/color]


      Comment

      • Nicholas Paldino [.NET/C# MVP]

        #4
        Re: Close window after MessageBox

        PawelR,

        I think that what you want is the static Quit method on the Application
        class. It should shut down your application, and as a result, all of the
        windows that go with it.

        Hope this helps.


        --
        - Nicholas Paldino [.NET/C# MVP]
        - nick(dot)paldin o=at=exisconsul ting<dot>com

        "PawelR" <pawelratajczak @poczta.onet.pl > wrote in message
        news:MPG.19eb76 e25705e3c298968 8@news.tpi.pl.. .[color=blue]
        > Hello group,
        > In my apps I connection to SQL database.
        > try
        > {
        > //connect to db
        > }
        > catch
        > {
        > MessageBox("Err or Connect. Close Apps?","Sql
        > Error",MessageB oxButtons.OKCan cel,MessageBoxI con.Error);
        >
        > }
        > When db is connection error apps show messagebox with button OK and[/color]
        Cancel.[color=blue]
        > My question: How close this application after OK, and continuue apps after
        > Cancel?
        >
        >
        > catch
        > {
        > MessageBox("Err or Connect","Sql
        > Error",MessageB oxButtons.OK,Me ssageBoxIcon.Er ror);
        > Close();
        > }
        > Not work.
        >
        >
        > Thx PawelR[/color]


        Comment

        • Morten Wennevik

          #5
          Re: Close window after MessageBox

          this.Close();

          should close the current thread(program) .
          However, if you connect to the database as a part of a startup procedure
          Close() will be ignored.

          A possible solution to this is to throw a new exception after showing the
          messagebox, and use a try/catch around Application.Run ();

          You put the messagebox in an if statement and compare it with
          DialogResult.OK to check if OK was clicked.

          [STAThread]
          static void Main()
          {
          try
          {
          Application.Run (new Form1());
          }
          catch
          {
          }
          }

          (...)

          try
          {
          //connect to db
          }
          catch
          {
          if(MessageBox(" Error Connect. Close Apps?", "Sql Error",
          MessageBoxButto ns.OKCancel,Mes sageBoxIcon.Err or) == DialogResult.OK )
          {
          throw new Exception();
          }
          }

          --
          Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

          Comment

          Working...