473,386 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Close window after MessageBox

Hello group,
In my apps I connection to SQL database.
try
{
//connect to db
}
catch
{
MessageBox("Error Connect. Close Apps?","Sql
Error",MessageBoxButtons.OKCancel,MessageBoxIcon.E rror);

}
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("Error Connect","Sql
Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
Close();
}
Not work.
Thx PawelR
Nov 15 '05 #1
4 10049
Hello,
In my apps this code is before

InitializeComponent();

In article <MP************************@news.tpi.pl>,
pa************@poczta.onet.pl says...
Hello group,
In my apps I connection to SQL database.
try
{
//connect to db
}
catch
{
MessageBox("Error Connect. Close Apps?","Sql
Error",MessageBoxButtons.OKCancel,MessageBoxIcon.E rror);

}
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("Error Connect","Sql
Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
Close();
}
Not work.
Thx PawelR

Nov 15 '05 #2
hi Pawel
use the dialogresult object
DialogResult dlr = (Messagebox.Show("blablabla",
MessageBoxButtons.OkCancel)
if (dlr == DialogResult.Ok)
{
close();
}
else
{
do...;
}
"PawelR" <pa************@poczta.onet.pl> wrote in message
news:MP************************@news.tpi.pl...
Hello group,
In my apps I connection to SQL database.
try
{
//connect to db
}
catch
{
MessageBox("Error Connect. Close Apps?","Sql
Error",MessageBoxButtons.OKCancel,MessageBoxIcon.E rror);

}
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("Error Connect","Sql
Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
Close();
}
Not work.
Thx PawelR

Nov 15 '05 #3
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)paldino=at=exisconsulting<dot>com

"PawelR" <pa************@poczta.onet.pl> wrote in message
news:MP************************@news.tpi.pl...
Hello group,
In my apps I connection to SQL database.
try
{
//connect to db
}
catch
{
MessageBox("Error Connect. Close Apps?","Sql
Error",MessageBoxButtons.OKCancel,MessageBoxIcon.E rror);

}
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("Error Connect","Sql
Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
Close();
}
Not work.
Thx PawelR

Nov 15 '05 #4
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",
MessageBoxButtons.OKCancel,MessageBoxIcon.Error) == DialogResult.OK)
{
throw new Exception();
}
}

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: William Gill | last post by:
I am trying to make a simple data editor in Tkinter where each data element has a corresponding Entry widget. I have tried to use the FocusIn/FocusOut events to set a 'hasChanged' flag (if a...
4
by: John H. | last post by:
Hello I have some trouble in closing a window, Here is the problem: I develop a asp.net website use client side valiation <asp:CustomValidator id="CustomValidator1"...
9
by: Steven Malcolm | last post by:
Hello there Is it possible to close a window without the messagebox coming up asking if you really want to close the window? Steven
1
by: Alpha | last post by:
I have a Window based application that shows up still running in the task manager when I close it. It reaches the "this.close" statement and then it stops at the "}" at the section of the...
2
by: John H. | last post by:
Hello I have some trouble in closing a window, Here is the problem: I develop a asp.net website use client side valiation <asp:CustomValidator id="CustomValidator1"...
7
by: mg | last post by:
Once opening WebForm2 from WebForm1 using Response.Write("<script language='javascript'>window.open ('WebForm2.aspx','two','menubar=no');</script>"); how can I close WebForm1?
5
by: Nicola Farina | last post by:
Hi all, I've a window form application with 3 forms. I want to catch the security exception when users run this application from a network share, thus I've made this code (I've notice that...
4
by: RSH | last post by:
I am trying to figure out how I can trap the Closing Event that occurs when a user attempts to close the window by clicking on the red"X". I tried this code which I found online but nothing...
6
by: Frank Rizzo | last post by:
I am trying to programmatically close a messagebox. I don't see any obvious managed choices. Back in the day, I remember using a combination of FindWindow and EndDialog apis(...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.