|
You should look at redesigning the code a little. You should not call one event handler from another, IMO.
You should create a method that performs the actions for the event, and then call that action from the two separate event handlers. That way your code is cleaner and if you ever decide to add functionality to one of the events but not the other you can change it more easily.
For example:
private void DoCloseAction()
{
}
private void SomeForm_Closed(object sender, EventArgs e)
{
DoCloseAction();
}
private void CloseButton_Click(object sender, EventArgs e)
{
DoCloseAction();
}
Does this help?
Do you want to know more?
WDevs.com - Member's Software Directories, Blogs, FTP, Mail and Forums
|
|
|
|
|
Form Closing EVent
---------------
this.Closing += new
System.ComponentModel.CancelEventHandler(this.evtclosapp);
private void evtclosapp(object sender, System.ComponentModel.CancelEventArgs e)
{
DialogResult key = MessageBox.Show("Do you realy want to exit?",
"Muhammad Waqas Butt [Confirmation]",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
e.Cancel=(key == DialogResult.No);
}
I want to call it in this method
Buttom Click Event
------------------
private void evtappexit(object sender, System.EventArgs e)
{
//What code here....
}
Muhammad Waqas Butt
|
|
|
|
|
|
Form Closing EVent
---------------
this.Closing += new
System.ComponentModel.CancelEventHandler(this.evtclosapp);
private void evtclosapp(object sender, System.ComponentModel.CancelEventArgs e)
{
DialogResult key = MessageBox.Show("Do you realy want to exit?",
"Muhammad Waqas Butt [Confirmation]",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
e.Cancel=(key == DialogResult.No);
}
I want to call it in this method
Buttom Click Event
------------------
private void evtappexit(object sender, System.EventArgs e)
{
//What code here....
}
Muhammad Waqas Butt
|
|
|
|
|
I have a messagebox show on the exit event of my app. it has the options of "OK", or "Cancel." How do I let the program keep going if they press cancel?
|
|
|
|
|
|
how do you overried the OnClosing method? and where does CancelEventArgs.Cancel = true go? (I'm a newbie sorta)
|
|
|
|
|
I think he meant you have to handle the Closing Event on the form. In the desiner click once on the form. Press F4 (or select the properties tab from the sidebar) then press the events button at the top of the properties side bar. You will see somewhere in the list events Closed and Closing (pay attention to the verb tense).
Closing occurs as the form is in the process of closing at this point you still have time to abort the action. You will find that the event arguments for this event include a property called Cancel , set that to true .
Does this help?
Do you want to know more?
WDevs.com - Member's Software Directories, Blogs, FTP, Mail and Forums
|
|
|
|
|
I guess I don't quite understand how arguements work. (thanks for the help by the way!)
|
|
|
|
|
|
so I have this "private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)".
{
//what goes here to keep it from closing?
//I've tried "Form1_Closing(true)"
//that didn't work
//so what's the correct way of doing this?
}
thanks so much,
Stephen
|
|
|
|
|
You don't call this method directly. The event fires and the Framework will call the method. The important thing here is the parameter e , which is of type CancelEventArgs (See MSDN[^] for details. This has a Cancel property, which you can set to true to stop the form from closing.
Your code will look something like:
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (testToSeeIfClosingShouldBeCancelled)
{
e.Cancel = true;
}
}
Does this help?
Do you want to know more?
WDevs.com - Member's Software Directories, Blogs, FTP, Mail and Forums
|
|
|
|
|
that's it!!!!! thank you so much! I feel bad to ask for any more help than you have already given me. but, do you know how to make any text the resides within a richTextBox, within the < and > tags (including the tags themselves) change to, say, blue?
thanks again,
Stephen
|
|
|
|
|
Hi,
just use the if loop for 'OK' option and use (applicationname).close(); in it orelse do nothin...
the program will be keep running if u press 'cancel'
hope this helps.
Pavan.
Suman
|
|
|
|
|
basically, I have a richTextBox, and I want to be able to highlight anything inside between "<" and ">", with the color blue. And anything between "<" and ">" that is surrounded in quotation marks green. if you could provide any code, that would be very helpful.
thanks a bunch,
Stephen
|
|
|
|
|
Well, I couldn't find out how Rich Text is saved but maybe you could do that with some Regexps
(http://msdn.microsoft.com/library/en-us/cpguide/html/cpconRegularExpressionExamples.asp)
|
|
|
|
|
orelse u can use text.color option while outputting text onto the textbox between those symbols.
Suman
|
|
|
|
|
Hello World!
I am stuck with a big algorithmic application I had developed. There is a StackOverflowException is thrown when I try to extend the program a bit more. Is there a way to expand the Stack depth of the system ? Couldn't find any in MSDN...
I am also suspecting that other heavy routines, when return, somehow stack isn't released by them, so when I add after them in a root line, an additonal routine (doing small recursion) - not in parallel, the program falls when the recursion first entered, like if I am dancing on the edge of the stack limit most of the program time.
Another thing. Checked the Stack class. Couldn't quite understand if possible to attach some processes to a new stack handle I create with this class, and with that, to split program to use more than one stack. Is it possible??!
A note: all my routines run inside a timer tick, when in the beginning of each tick, I stop the timer, do all the stuff and start it in the end....
Thanks ahead.
FioFio
|
|
|
|
|
|
Hey, thanks for the response.
But I have tested the recursive function, it depth is max. 10 in all cases and I pass 2 integers each time. And important of all, it is running OK when I shut down all nonrecursive heavy routines running before it.
Somehow, there are pending methods left, raising the program proximity to the stack limit. Anyway, do you know how can I raise the stack limit ? Is it possible ?
FioFio
|
|
|
|
|
Hello and merry christmas
I want to convert my localtime (I'm living in Belgium) Format : DD/MM/YYYY HH:MM:SS with time of ntp server (Format : MM/DD/YYYY HH:MM:SS no AM/PM)
Can you help me ?
My best wishes.
Frédéric
|
|
|
|
|
I haven't tested this or anything, but I'm pretty sure all you need to do is use the ToString() method. For instance...
DateTime time = DateTime.Now;
string formattedTime = time.ToString("MM/dd/yyyy hh:mm:ss");
For more information, check out MSDN's custom DateTime format strings[^].
Michael Flanakin
Web Log
|
|
|
|
|
Hi,
Is there anyway I can set a timeout for an asynchronous call in remoting. The intention is that if the method takes a long time and it is not worth waiting that long, the execution should proceed. Kind of taking off the blocking aspect of EndInvoke call.
.kausthubh
|
|
|
|
|
Hi,
Ftp artical.I have a two questions
1: How to take backup of SQL Server 2000 Database in c# programm what
we write such that kind of code which run and take backup from db. You
understand what i mean to say.
2: We have a winform application in datagrid we show some data from sql
server 2000 database i need that when we change some thing in datagrid
the changing save into XML format and throuh ftp or mail we send this
file to remote computer and on the computer a other application runs
which take XML data and insert in the Sql Server 2000 Database which is running on remote PC.
Muhammad Waqas Butt
|
|
|
|
|
WaqasButt wrote:
1: How to take backup of SQL Server 2000 Database in c# programm what
we write such that kind of code which run and take backup from db. You
understand what i mean to say.
What was wrong with the answer[^] that I gave to you a few days ago? If you didn't understand it then I am more than happy to clarify anything. I did make some assumptions that you knew your way around the SqlConnection and SqlCommand objects well enough to perform a normal query (SELECT, INSERT, DELETE, UPDATE) so maybe that was incorrect.
Do you want to know more?
WDevs.com - Member's Software Directories, Blogs, FTP, Mail and Forums
|
|
|
|