MessageBox.Show Closes after function ends?

  • Thread starter msnews.microsoft.com
  • Start date
M

msnews.microsoft.com

Greetings,

I can't seem to keep the messagebox on screen until the user clicks the ok
button. I had this problem in the past and thought I found that the
messagebox.show() method had to go at the very end of the function in order
for the box to display and stay till clicked. Now that I've restarted work
on the application, it's back to the same old behaviour: as soon as the
function ends the box is automatically closed.

Any Help?
Thanks!
Don
..Button1);
 
M

MuZZy

msnews.microsoft.com said:
Greetings,

I can't seem to keep the messagebox on screen until the user clicks the ok
button. I had this problem in the past and thought I found that the
messagebox.show() method had to go at the very end of the function in order
for the box to display and stay till clicked. Now that I've restarted work
on the application, it's back to the same old behaviour: as soon as the
function ends the box is automatically closed.

Any Help?
Thanks!
Don
.Button1);

Well, MessageBox.Show() is showing a modal dialog, execution process
waits for it to return a value of type DialogResult, so there is no way
your function would exit until you close the box.

Can you post a piece of your code here?

MuZZy
 
D

Don Miller

Yea, that's how I understand it -- modal dialog. The funky thing is that the
exact code below used to work (i.e. the dialog box would display modally)
but now doesn't, so I gotta figure that there's some setting in the
emulator/PPC that is causing the "problem". Below is the entire
function--note that the MessageBox.Show() is at the end of the routine and
trust me when I step through the code it shows the message box and keeps
right on stepping through, closing the box at the end of the routine. I
tried this in debug mode on the actual PPC device.

private void txtTicketNo_TextChanged(object sender, EventArgs e)
{
bool errorOccurred = false;

if (txtTicketNo.Text.Length > 0)
{
//verify that only numbers can be entered
char[] digit = txtTicketNo.Text.ToCharArray();
string numberList = "1234567890";
string tmpTicketNo = "";
int pos = 0;

for (int i = 0; i <= digit.GetUpperBound(0); i++)
{
pos = numberList.IndexOf(digit);
if (pos > -1)
{
tmpTicketNo += digit;
}
}
txtTicketNo.Text = tmpTicketNo;
}

//test whether we're at 18 characters yet
if (txtTicketNo.Text.Length == 18)
{
showConnecting();
if (!dTito.payTicket(currentCashierUserID,
currentCashierPassword, txtTicketNo.Text.ToString()))
{
txtTicketNo.Text = "";
txtTicketNo.Focus();
showLoggedIn();
errorOccurred = true;
}
else
{
addTicketToGrid(txtTicketNo.Text, dTito.TicketValue);
txtTicketNo.Text = "";
totalval += Convert.ToDouble(dTito.TicketValue);
//lastTotalVal += totalval;
string displayValue = String.Format("{0:c}", totalval);
txtTotal.Text = displayValue;
dTito.TicketValue = 0; //clear's Tito's ticket
value.
txtTicketNo.Focus();
}
showLoggedIn();

if (errorOccurred)
{
MessageBox.Show("Unable to verify ticket. Please take
ticket to Casino Cage for redemption. Thanks!", "Pay Ticket",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
}

}

}//end of tctTicketNo_TextChanged()




Thanks for having a look!
Don
 
M

msnews.microsoft.com

The modal box works fine in the emulator in both release and debug builds,
however does not work on the actual device.


Don Miller said:
Yea, that's how I understand it -- modal dialog. The funky thing is that
the exact code below used to work (i.e. the dialog box would display
modally) but now doesn't, so I gotta figure that there's some setting in
the emulator/PPC that is causing the "problem". Below is the entire
function--note that the MessageBox.Show() is at the end of the routine and
trust me when I step through the code it shows the message box and keeps
right on stepping through, closing the box at the end of the routine. I
tried this in debug mode on the actual PPC device.

private void txtTicketNo_TextChanged(object sender, EventArgs e)
{
bool errorOccurred = false;

if (txtTicketNo.Text.Length > 0)
{
//verify that only numbers can be entered
char[] digit = txtTicketNo.Text.ToCharArray();
string numberList = "1234567890";
string tmpTicketNo = "";
int pos = 0;

for (int i = 0; i <= digit.GetUpperBound(0); i++)
{
pos = numberList.IndexOf(digit);
if (pos > -1)
{
tmpTicketNo += digit;
}
}
txtTicketNo.Text = tmpTicketNo;
}

//test whether we're at 18 characters yet
if (txtTicketNo.Text.Length == 18)
{
showConnecting();
if (!dTito.payTicket(currentCashierUserID,
currentCashierPassword, txtTicketNo.Text.ToString()))
{
txtTicketNo.Text = "";
txtTicketNo.Focus();
showLoggedIn();
errorOccurred = true;
}
else
{
addTicketToGrid(txtTicketNo.Text, dTito.TicketValue);
txtTicketNo.Text = "";
totalval += Convert.ToDouble(dTito.TicketValue);
//lastTotalVal += totalval;
string displayValue = String.Format("{0:c}", totalval);
txtTotal.Text = displayValue;
dTito.TicketValue = 0; //clear's Tito's ticket
value.
txtTicketNo.Focus();
}
showLoggedIn();

if (errorOccurred)
{
MessageBox.Show("Unable to verify ticket. Please take
ticket to Casino Cage for redemption. Thanks!", "Pay Ticket",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
}

}

}//end of tctTicketNo_TextChanged()




Thanks for having a look!
Don



MuZZy said:
Well, MessageBox.Show() is showing a modal dialog, execution process
waits for it to return a value of type DialogResult, so there is no way
your function would exit until you close the box.

Can you post a piece of your code here?

MuZZy
 
M

msnews.microsoft.com

Turns out that the PPC device's setting for the bar code reader was set to
send a Return when the last symbol was read--it was that return that was
clearing the dialog box (duh!). I'm counting characters to execute the
routine and don't need that feature so I turned it off and it's fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top