|
Hello, when I press the X in the top right hand corner of the application, I get a messagebox. The messagebox ask me a Yes/No question. If I press YES, all is good and the application closes. When I press NO, I can continue to use the application. Now the problem. If I press NO, then I can never press the X in the top right hand corner. It's as if the NO answer disables the ability to ever close the application again. How can I say NO and be able to press the X again when I want to close the application later?
Code:
private void DXWindow_Closing(object sender, CancelEventArgs e)
{
var result =
MessageBox.Show(
Properties.Resources.MainWindowMsgBox3 + Environment.NewLine +
Properties.Resources.MainWindowMsgBox4 + Environment.NewLine + Environment.NewLine +
Properties.Resources.MainWindowMsgBox5,
Properties.Resources.MainWindowMsgBox6, MessageBoxButton.YesNo, MessageBoxImage.Question,
MessageBoxResult.No);
Log.Info("User engaged Application Closure Event");
switch (result)
{
case MessageBoxResult.Yes:
Log.Info("Main Window Closed");
OnClosed(e);
Application.Current.Shutdown();
break;
case MessageBoxResult.No:
e.Cancel = true;
break;
}
}
|
|
|
|
|
First, I think you should call the base OnClosing method, not the OnClosed as you do. Second, you should call this base handler in both cases, as it will take care with proper action, whether or not event has been cancelled:
var result =
MessageBox.Show(
Properties.Resources.MainWindowMsgBox3 + Environment.NewLine +
Properties.Resources.MainWindowMsgBox4 + Environment.NewLine + Environment.NewLine +
Properties.Resources.MainWindowMsgBox5,
Properties.Resources.MainWindowMsgBox6, MessageBoxButton.YesNo, MessageBoxImage.Question,
MessageBoxResult.No);
Log.Info("User engaged Application Closure Event");
switch (result)
{
case MessageBoxResult.Yes:
Log.Info("Main Window Closing");
break;
case MessageBoxResult.No:
e.Cancel = true;
break;
}
base.OnClosing(e);
The whole point of setting the Cancel property is to let the base handler know which action to take (close or cancel).
Hope this helps.
"I'm neither for nor against, on the contrary." John Middle
|
|
|
|
|
That's not working either. All it does is ask over and over again if I want to close the application. Did I mention this was inside a Closing event on the window?
private void DXWindow_Closing(object sender, CancelEventArgs e)
|
|
|
|
|
Oups, I misread; yes you're right, you did not override the base handler, so there is no point calling it. What happens if you comment off the base.OnClosing(e); line?
"I'm neither for nor against, on the contrary." John Middle
|
|
|
|
|
Commenting out the line pops the message when the X is clicked. If I say YES, the app closes. If I say NO, I return to the application; however, the X is dead. I can no longer close the application.
|
|
|
|
|
I want to apologize for not catching this the first time. I reviewed the issue with DevExpress and they reported that the Closing Event is only being raised once and this defect will be fixed in the next release. Article. thanks for your help! 
|
|
|
|
|
You're welcome. Thanks for the update. I don't feel like I was of great help, though.
"I'm neither for nor against, on the contrary." John Middle
|
|
|
|
|
What I mean by...
Moveable elements: index cards, scrabble tiles, etc.
move: 'grab' and drag with LMB to another part of the window
I'm new to C# and WFC, etc. but have years of experience in PHP, C and other languages.
What I'm looking to know is:
- which element(s) (if element is the right word; checkbox? text entry field? what-have-you?) to use to create a scrabble tile or index card (whatever; the moveable object/thing)
- how movement is handled
Either a general sort-of pseudo code explanation or actual code is fine.
I don't know the terminology used in WFC (if WFC is even the right acronym) so maybe this question doesn't even make sense.
|
|
|
|
|
Member 13588277 wrote: if WFC is even the right acronym For what?
And if you want to know the answers to he other questions then take a look in the Articles section[^] where you will find lots of useful information.
|
|
|
|
|
For game "pieces" I'd use either a Panel for rectangular pieces, or a UserControl for custom shaped pieces.
Search CodeProject for articles on drag and drop, and/or creating custom shaped Controls.
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
The elements you refer to are from WinForms, and that's not a great engine to build games with. Ever heard of Rimworld? Might not have, as it is still in beta, but it is available on Steam.
Engine Used?[^]
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Upvote for a Rimworld reference.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Thanks for all the replies, guys.
Eddy Vluggen wrote: The elements you refer to are from WinForms, and that's not a great engine to build games with
Eddy: What do you use instead of WinForms? And which specific element (or whatever it's called) would you use for (for instance) an index card that can be dragged around and dropped somewhere else within a window?
|
|
|
|
|
Unity
It has a learning curve, but not a terrible one.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Member 13588277 wrote: And which specific element (or whatever it's called) would you use for (for instance) an index card that can be dragged around and dropped somewhere else within a window? It's hard to say it, I hate to say it, but probably WinForms. It has got built-in support for drag and drop, and there's an article on CodeProject showing how to use any bitmap in that drag-and-drop operation.
If you are into creating games, I'd strongly suggest to look at Unity. If you're looking for beta-testers, I'm here
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You're probably thinking of WPF (Windows Presentation Foundation); and not WFC.
I would consider the WPF "Canvas" control as a starting point for an "absolute positioning" project:
How to: Create and Use a Canvas | Microsoft Docs
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Is this WPF thing out of beta yet?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
It paid off my mortgage last year ...
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Yes, so will IoT, AI and blockchain
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
My (enterprise) WPF is using AI to program and control IOT's using TCP over wired and wireless ...
Current web development reminds me of developing client applications in assembler.
Block chain; another type of "ledger"; mostly looking for a problem to solve. The "currency" model became a vehicle for speculation and tax avoidance; mostly of interest to the same sorts.
Most don't understand "block chain"; that's why they get so excited. They think it's all about "getting coin".
Kodak has just released their own "currency"?! Tulip geld.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Gerry Schmitz wrote: The "currency" model became a vehicle for speculation and tax avoidance If that were the case, more companies would be investing in BitCoin
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Sorry, I meant tax "evasion".
Oh, wait ...
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
How to insert this XML file in SQL Server? I have done one but cannot output. The error said "String was not recognized as a valid DateTime"
Here the code that I done:
SqlDataAdapter adpter = new SqlDataAdapter();
DataSet ds = new DataSet();
int appointment_ID = 0;
string nric = null;
string client_Name = null;
DateTime? appointment_Date = null;
DateTime? start_Time = null;
SqlConnection conn = new SqlConnection(@"Data Source=USER1-PC\SQLEXPRESS;Integrated Security=true;Database=ProductDB");
XmlReader xmlFile = XmlReader.Create("G://appointment.xml", new XmlReaderSettings());
ds.ReadXml(xmlFile);
int i = 0;
conn.Open();
for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
appointment_ID = Convert.ToInt32(ds.Tables[0].Rows[i].ItemArray[0]);
appointment_Date = DateTime.Parse(ds.Tables[0].Rows[i].ItemArray[1].ToString());
start_Time = DateTime.Parse(ds.Tables[0].Rows[i].ItemArray[2].ToString());
nric = ds.Tables[0].Rows[i].ItemArray[3].ToString();
client_Name = ds.Tables[0].Rows[i].ItemArray[4].ToString();
SqlCommand command = new SqlCommand("insert into Appointment values(" + appointment_ID + ",'" + appointment_Date + "'," + start_Time + "'," + nric + "'," + client_Name + ")", conn);
adpter.InsertCommand = command;
adpter.InsertCommand.ExecuteNonQuery();
}
conn.Close();
MessageBox.Show("Done .. ");
Here is appointment.xml:
<interface>
<appointment>
<appointment_id> 000000087508
<appointment_date>2018-01-25
<appointment_start_time>13:15:00
<client>
<nric>456987123
<client_name>JAMES
<appointment>
<appointment_id>000000087501
<appointment_date>2018-01-25
<appointment_start_time>14:30:00
<client>
<nric>963258741
<client_name>Bill Tan
<client>
<nric>123456789
<client_name>David Ang
<checksum>2
|
|
|
|
|
Don't do it like that! Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
When you concatenate strings, you cause problems because SQL receives commands like:
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood' The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable; Which SQL sees as three separate commands:
SELECT * FROM MyTable WHERE StreetAddress = 'x'; A perfectly valid SELECT
DROP TABLE MyTable; A perfectly valid "delete the table" command
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.
So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?
Chances are, when you fix that throughout your application, the problem you have noticed will vanish at the same time.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Just noting that SQL server can process XML directly.
Jieha Lee wrote: The error said "String was not recognized as a valid DateTime"
Print out your SQL - don't guess, actually print it.
Then you can take that SQL and try it directly on the database.
As a guess as to the error, SQL expects a very specific form for a timestamp (not a 'date') and you have not created that form.
|
|
|
|