|
Hi,
I am working on one winform using .NET 1.1. In My form Cancel Button is present. In cancel button code. i am using this.Close() method for closing the form.
if user clicks on top right side X button, Form Closing Event will fires.
how can i find weather a user clicked on Cancel button or X button???
experts any sounds.... ?
regards
GV Ramana
|
|
|
|
|
Hello,
In your CancelButton code (Click event handler), you could set the DialogResult property of the Form to DialogResult.Cancel.
So if the user Closes the Form over the 'X', the Default would be DialogResult.None.
private void CancelButton_Click(object sender, System.EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
protected override void OnClosing(CancelEventArgs e)
{
if(this.DialogResult == DialogResult.None)
{
}
else if(this.DialogResult == DialogResult.Cancel)
{
}
base.OnClosing (e);
}
Hope it helps!
All the best,
Martin
|
|
|
|
|
I am unable to add OnClosing Event.
Form is having only this.Closing event only
i.e., this.Closing += new System.ComponentModel.CancelEventHandler(From1_Closing);
plz tell me how to add OnClosing Event
regards
GV Ramana
|
|
|
|
|
You are wellcome!
All the best,
Martin
|
|
|
|
|
I am unable to add OnClosing Event.
Form is having only this.Closing event only
i.e., this.Closing += new System.ComponentModel.CancelEventHandler(From1_Closing);
plz tell me how to add OnClosing Event
regards
GV Ramana
|
|
|
|
|
OnClosing is th protected virtual method which fires the Closing event in the base Class (System.Windows.Forms.Form).
As you have your Form derived from Forms.Form, you don't have to handle the Event itselfe, you just can override the method.
Like I did!
All the best,
Martin
|
|
|
|
|
got it. & another problem.
everytime getting DialogResult as Cancel if i click on X button also. how do i get this?
regards
GV Ramana
|
|
|
|
|
Hello,
Now you also want DialogResult.Cancel set, if the user closes with 'X'.
Just set it in the Closing or Closed event.
All the best,
Martin
|
|
|
|
|
Hi Martin,
I dont think it will work your way. Windows already sets DialogResult to Cancel on
hitting the Close box.
This is why: Microsoft intends the Close Button to be identical to a Cancel
action; closing the dialog or pressing Cancel button both indicate "hey, I dont want this,
I am not interested". It is part of the overall GUI conventions that MS came up with.
And, we have had a difference of opinion on this before: one should not go against
such conventions.
|
|
|
|
|
Hello Luc,
Luc Pattyn wrote: I dont think it will work your way
Luc Pattyn wrote: Windows already sets DialogResult to Cancel on
hitting the Close box.
Have you tested it?
I did, with VS2003 .Net1.1!
Luc Pattyn wrote: And, we have had a difference of opinion on this before: one should not go against
such conventions.
Really?
Help me with long-term memory, when was that.
All the best,
Martin
|
|
|
|
|
Martin# wrote: Have you tested it?
Yes.
Martin# wrote: Help me with long-term memory, when was that
IIRC it was about changing the behavior of a group of radio buttons; my point was and is
if it looks like standard controls, it should behave like them too.
|
|
|
|
|
Luc Pattyn wrote: Yes.
So why do we have different results than?
Luc Pattyn wrote: IIRC it was about changing the behavior of a group of radio buttons;
Ahh, now I remember!
Luc Pattyn wrote: my point was and is
if it looks like standard controls, it should behave like them too.
That's also what I think, but I think the point was to modify the behavior in combination with the style.
All the best,
Martin
|
|
|
|
|
Martin# wrote: So why do we have different results than?
I see three possibilities:
- we have different systems
- there is a misunderstanding somewhere
- one of us is wrong (but who then?)
The last post from the OP seems to hint towards the third possibility, doesnt it ?
|
|
|
|
|
Luc Pattyn wrote: we have different systems
XP; VS2003; .Net1.1
Luc Pattyn wrote: there is a misunderstanding somewhere
If I test following code at my Form, it does what I wrote in the comments of the code:
private void CancelButton_Click(object sender, System.EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
protected override void OnClosing(CancelEventArgs e)
{
if(this.DialogResult == DialogResult.None)
{
}
else if(this.DialogResult == DialogResult.Cancel)
{
}
base.OnClosing (e);
}
Luc Pattyn wrote: one of us is wrong (but who then?)
It's maybe a lack of self confidence, but I would assume it's me who missed something!
Luc Pattyn wrote: The last post from the OP seems to hint towards the third possibility, doesnt it ?
I haven't understood this one!
All the best,
Martin
|
|
|
|
|
Hi Martin,
the OP posted: "everytime getting DialogResult as Cancel if i click on X button also"
hence he gets DialogResult.Cancel both for the Cancel button and for the Close Box,
so that does not help him.
Maybe/probably the "Close Box implies Cancel result" only applies to dialogs (forms shown with
ShowDialog) where it matters most, and not to regular forms, shown with Show() ?
If so, you probably did the wrong experiment...
|
|
|
|
|
Luc Pattyn wrote: Maybe/probably the "Close Box implies Cancel result" only applies to dialogs (forms shown with
ShowDialog) where it matters most, and not to regular forms, shown with Show() ?
Bingo!
Just tested it!
Luc Pattyn wrote: If so, you probably did the wrong experiment
Did I?
I think he was never speaking of ShowDialog!
But anyway, you found the problem!
Got my '5' for that!
All the best,
Martin
|
|
|
|
|
Furthermore, MSDN on Form.DialogResult says:
"clicking the Close button (the button with an X in the top-right corner of the form) causes the form to be hidden and the DialogResult property to be set to DialogResult.Cancel."
It does not say explicitly WHEN it does that, so I guess it is in base.OnClosing (e);
It does say "You can override the value assigned to the DialogResult property when the user clicks the Close button by setting the DialogResult property in an event handler for the Closing event of the form"
So I guess the base.OnClosing() does something like
if (DialogResult==None) DialogResult=Cancel
and hence your tip does not work, whereas setting it to something else
such as DialogResult=Yes; would work
(but it would then violate the GUI conventions, as I keep telling you).
|
|
|
|
|
Luc Pattyn wrote: and hence your tip does not work, whereas setting it to something else
such as DialogResult=Yes; would work
(but it would then violate the GUI conventions, as I keep telling you).
As it is only the case with ShowDialog and not with Show() and I tested it with show, I think it's not my fault.
I wouldn't have given such a suggestion if I knew that fact!
All the best,
Martin
|
|
|
|
|
And that's how we keep learning things every day.
"I think it's not my fault" Right, we all have a partial view on the whole thing,
every statement needs a lot of ifs and whens.
And the next question probably will be: when I hit the escape key, I want my form/dialog to
close, and I want to discriminate all three (ESC/CancelButton/CloseBox) ???
|
|
|
|
|
But only on Mondays!
Wait I think there is such a system allready on the market. YEP: "SAP"
All the best,
Martin
|
|
|
|
|
Indeed, they are the experts as to f*cking up a GUI.
Think thats part of their business model.
|
|
|
|
|
Hi all,
I have created a Page on which i want the user to be able to download files,
I want to display the name of the files and when the user clicks on the file name the save File dialog should be displayed so that the user can select the location of the file where it has to be saved.
Any sample code or links regarding this will be appreciated.
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|
|
The anchor tag will do this for you, depending. Where do the files live ? Are they on the server, or in the database ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
They are on a Sharepoint Server.
I get all the attachments from a list and display the names on the page by creating LinkButton for each of them.
now i want the display the save dialog box when the user clicks on the LinkButton and then the file should be saved on the location given by the user.
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|
|
how to build a glossary in c#.....with person names as hyperlinks.when hyperlink is clicked information regarding that person shoud be displayed.please help me ..its urgent.
|
|
|
|