|
Hi Guys,
I am working on a Windows Form where I have placed a Button control (Button text: Exit). In the Button1_Click event Handler, I have added this code:
//Code begins here
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Are you sure to exit the application! Selct Ok to Exit now or Cancel to stay in the current form", "Sample App", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
if (MessageBox.Show("Are you sure to exit the application! Selct Ok to Exit now or Cancel to stay in the current form", "Sample App", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK)
{
Close();
}
else
{
return;
}
}
//Code ends here
However, when I debug the solution and click on the Exit button, the Message Box is displayed asking for confirmation. Then, when I click on the Ok button, instead of closing the application, the same Message Box pops up again! Then, again I have to click on Ok and this time the Click Event executtes and the application closes. Similar is the case with the Cancel Button. Why does the MessageBox display the same message twice? Help me Please....
Your help will be appreciated. Thanx....
|
|
|
|
|
youve now posted te same question again a mere 10 minutes later.
READ THE CODE. STEP THROUGH THE CODE. IT IS OBVIOUS WHY YOU GET TWO MESSAGE BOXES.
I thought you might be hard-of-reading so i shouted that in the typical englishman manner of just talking louder and slower to foreigners in english.
|
|
|
|
|
|
Kwagga wrote: Newby and Hoemwork
Newbie and Homework
"Don't worry if it doesn't work right. If everything did, you'd be out of a job." (Mosher's Law of Software Engineering)
|
|
|
|
|
Hello there,
Plz dont shout at me! I am only a newbie here. If I'm finding something difficult to understand, then its your sole responsibility to help me out. I know that there's some mistake with the code, but am unable to mark it out..... Please give me a hint.
Your help will be appreciated...
thanx
|
|
|
|
|
Rajdeep.NET wrote: Please give me a hint.
You're kidding, right? You've had so many hints already that if you cant work it out now its time to hand back your textbooks, cancel your account with your college computer centre, and go get a job flipping burgers.
|
|
|
|
|
J4amieC wrote: and go get a job flipping burgerscow patties .
Fixed that for you.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
Rajdeep.NET wrote: its your sole responsibility to help me out
It will be Jamie's responsibility to help you out when you pay him for it.
|
|
|
|
|
Vikram A Punathambekar wrote: Carpe Diem.
When it comes to threads like this I really am thinking more along the lines of Carpe Jugulum
|
|
|
|
|
Rajdeep.NET wrote: then its your sole responsibility to help me out.
What ????? What do you think we are ? Your mother,your parents ? Why is my f**king sole responsibility to answer to your questions ?
Get real asap and decide to start studying more than talking.
|
|
|
|
|
I think, as with many posts on here, that certain phrases get lost in translation.
Obviously the guy is a beginner coder, possibly a beginner in English too
|
|
|
|
|
By the way its quite obvious moron. Read your (???) code
|
|
|
|
|
Clearly, you didn't do a very good job of it. You should have separated the letters with spaces l i k e t h i s to mimic the effect of talking slower.
|
|
|
|
|
You're right. very good point.
|
|
|
|
|
Raj check the answer which is already given....
BTW why did you delete the previous post and re-posted the same content here...????
Have a Happy Coding.....
|
|
|
|
|
Sorry for deleting the previous post,
there was a mistake in it. Instead of writing
Button1_Click, I wrote Button3_Click. It wouldn't have affected the
program too much, but I did so, to make u people understand the code better such that it doesn't affect the main motive of the program.
plz help
|
|
|
|
|
Rajdeep.NET wrote: there was a mistake in it. Instead of writing
Button1_Click, I wrote Button3_Click
That made me really chuckle.
|
|
|
|
|
You seem to read every message except the ones that give you the solution. Did you even try what 8kelvin suggested below?
|
|
|
|
|
In the interest of killing this question I will now provide you with the answer. Ready? Concentrate now...
you have told the computer to show you two message boxes.. look...
MessageBox.Show("Are you sure to exit the application! Selct Ok to Exit now or Cancel to stay in the current form", "Sample App", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
if (MessageBox.Show("Are you sure to exit the application! Selct Ok to Exit now or Cancel to stay in the current form", "Sample App", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK)
The first one you show the message box and discard the user's response.
The second one is within an if(..) construct. This does a boolean check on the contents of the (..) and if that returns true then the code directly after fires. Otherwise the code inside the else part executes. You would have learnty this had you have sat in on lecture "programming 101".
Your if(..) checks that the users response is equal to DialogResult.OK (or, more simply the user clicks trhe OK button) and if they do then the app closes. The part in your else is irrelevant.
Good luck with the rest of your career, mine'll be a big mac with fries please.
|
|
|
|
|
EDIT: The post above messed up not showing half the text. I have reposted here without the long code blocks
In the interest of killing this question I will now provide you with the answer. Ready? Concentrate now...
you have told the computer to show you two message boxes.. look...
MessageBox.Show("Are you sure to exit the application!....
if (MessageBox.Show("Are you sure to exit the application! ....
The first one you show the message box and discard the user's response.
The second one is within an if(..) construct. This does a boolean check on the contents of the (..) and if that returns true then the code directly after fires. Otherwise the code inside the else part executes. You would have learnty this had you have sat in on lecture "programming 101".
Your if(..) checks that the users response is equal to DialogResult.OK (or, more simply the user clicks trhe OK button) and if they do then the app closes. The part in your else is irrelevant.
Good luck with the rest of your career, mine'll be a big mac with fries please.
|
|
|
|
|
J4amieC wrote:
Good luck with the rest of your career, mine'll be a big mac with fries please.
I think he might not be able to do this as well... you're probably end up with 2 chicken burger's instead!
|
|
|
|
|
If you want to edit a post that scrolls off the side, you can do it. Click the body of the message and then press tab. The Reply link should get focus - then all you need to do is press tab to cycle between the links. Note that the edit link is the one you'll tab onto immediately after the bookmark link.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
ignore those jokers....
its because you need to put in another MessageBox.Show to handle the cancel button. if you dont then windows will auto create another one to make up for it... try the following...
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Are you sure to exit the application! Selct Ok to Exit now or Cancel to stay in the current form", "Sample App", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
if (MessageBox.Show("Are you sure to exit the application! Selct Ok to Exit now or Cancel to stay in the current form", "Sample App", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK && MessageBox.Show("Are you sure to exit the application! Selct Ok to Exit now or Cancel to stay in the current form", "Sample App", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.Cancel)
{
Close();
}
else
{
return;
}
}
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
DialogResult messageBoxResult = MessageBox.Show(...);
if(messageBoxResult == DialogResult.Ok)
{
}
else if(messageBoxResult == DialogResult.Cancel)
{
}
You may want to note that MessageBox.Show only gets invoked once. Incidentally, the first exclamation point passed to your method should be a question mark, and "selct" should be "select"
|
|
|
|
|
Hii All
i am working with datagridview in windows application. I hav one problem with datagridview DataPropertyName. I hav given same datatable column name as DataPropertyName to two gridview fields(RealPL and unrealPL)but i want to show ont field as 0(zero)based on some condition.
Example:
for (int n = 0; n <= dtclose.Rows.Count - 1; n++)
{
if (dtclose.Rows[n]["Status"].ToString() == "LIVE")
{
dtgrdv.Rows[n].Cells["RealPL"].Value = "0";
}
else if (dtclose.Rows[n]["Status"].ToString() == "CLOSE")
{
dtgrdv.Rows[n].Cells["UnrealPL"].Value = "0";
}
}
but both the field showing zero or showing same value..what should i do?
where I am doing wrong?..plz help me
Thank You in advance
|
|
|
|