|
theRealCondor wrote: implementing a callback is part of the process
Not necessarily, if you have two events for example (or overridable functions, or both) one which is OnClosing and one that is OnClosed then if you have your method which closes the program, e.g. the method Close then something like this may work
public void Close()
{
CancelEventArgs e = new CancelEventArgs();
this.OnCancelling(e);
if (e.Cancel == false)
{
this.OnClosed(new EventArgs());
}
this.InternalShutdown();
} So basically you fire the OnCancelling event (which should be done through an overridable method like in the framework classes). If cancel in the event args is true then you stop, if it's false then you can continue and close the program.
As of how to accomplish this I wouldn't have a clue at the moment and I'm too lazy to google it
|
|
|
|
|
Thanks. I had found some references to CancelEventArgs() and I've been just too swamped to think of the simplest approach...to inherit the CancelEventArgs. It's in place and my team is testing it this week. Thanks much for you help.
Michael
|
|
|
|
|
Glad to be of some help.
As of how to accomplish this I wouldn't have a clue at the moment and I'm too lazy to google it
|
|
|
|
|
Hello community,
I´ve several textboxes. If I change a textbox, a method will be called by the "event-property" of the textbox. Now in the method I want the name of the textBox which was calling. I tried to get the name by the "object sender" paramter. There is the value and so on but no name. Is there any possibility to get the name of the method which was calling?
Thank you very much for your help!
|
|
|
|
|
((TextBox) sender).Name
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
It works! Thank you very much! I didn´t believe that I can use "TextBox" but now I know it.
|
|
|
|
|
A better way might be to do this:
Textbox TempTB = sender as Textbox;<br />
if (TempTB != null)<br />
{<br />
}
the extra layer of protection might prevent errors
|
|
|
|
|
private void button1_Click(object sender, EventArgs e) {
if (sender as Control != null)
MessageBox.Show(((Control)sender).Name);
}
if quite compact
1 line of code equals many bugs. So don't write any!!
|
|
|
|
|
Aha, I thouhgt that less code is better. But I think you mean that you can more specify the code and so it it less vulnerable for errors. Have I understood it correctly?
-- modified at 2:28 Tuesday 25th July, 2006
|
|
|
|
|
Well my code does the exact same thing that Drews code did.
The only difference is:
I am not creating an Extra variable to store the reference.
There is less code to manage, making it easier to read for faster debugging and still remains clear for its intent.
The One line of code equals many bugs refers to a staement in to TAO of programming article easily found on google.
The basically is saying write as few lines as possible. They will always have to be maintained. And the fewer lines written, the less maintenance needed in the future.
Nick
1 line of code equals many bugs. So don't write any!!
|
|
|
|
|
Now I understand. Very funny this TAO of programming.
Thanks!
|
|
|
|
|
Hi all,
I guess all have used the Babylon software
One of the feature of Babylon is if we click on any word in any window
it reads that word and displays the meaning of that word.
I also want to read the word when the mouse is clicked on it.
The word can be on any window, IE or desktop i.e. anywhere.
Any pointers or references to the same will be appreciated.
Thanks & Regards,
Pramod
|
|
|
|
|
the functionality is easy, just use a httpwebrequest to google and use define: {word}
but the only way I think it could be done without some magical code is to watch the clipboard and run code on it when ever it changes to get the definition.
Unless anyone else comes up with something more interesting?
Gav
|
|
|
|
|
Hey everybody!
I'm writing automation using the webbrowser controller. I already wrote this kind of automation in c# 2003, but this time I'm encountering a silly problem that I just can't find an answer to.
I'm getting a button as an HtmlElement from the HtmlDocument using the button's ID, and all I want is to click that button. for some reason I don't find any way to push the button!
can anyone help me with silly problem ???
THANKS!
|
|
|
|
|
You might get a faster answer if you post it in the ASP.NET forum.
|
|
|
|
|
Hey all!
Id like to write a piece of code which would display some text in directx.
But Id like it to display it while playing an online game (so that why playing in a corner
there would popup a halftransparent text about some statistics, for more details:
the online game is called America's Army ;]). But Im now quite sure how to do it, so
that the game wont minimize itself, like the communicator: xfire does.
Have anyone already tried that ? I would appreciate for any help or example code
in C#.
With regards,
Pawel
|
|
|
|
|
no real need for using directx, you can use a simple windowless form and set the transparency color the same of your background, tip: I usually use Magenta.
Now you can position your form where ever you want, and it will display the text as required.
Just make sure what ever you want to show isn't the same color as the transparency color.
Gav
|
|
|
|
|
sorry Im quite new to C#.. what do you mean by windowless form ? how to achiev it ?
|
|
|
|
|
Hi,
If the current day is anything less than 10, I want to save it to a string variable as 01, 02, 03, 04, etc. How does one do it like this?
I tried the follwoing, but it prints out as dd:
string strYY = String.Format("{0:dd}", objDateTime.Year);
Is this correct? If so, why is it not working?
Regards,
ma se
|
|
|
|
|
string strYY = objDateTime.Year.ToString("D2");
|
|
|
|
|
Thanks for the help.
Where did you get D2 from, what I mean is, what else can a person use?
|
|
|
|
|
From MSDN. See this:
http://msdn2.microsoft.com/en-us/library/dwhawy9k.aspx
|
|
|
|
|
Can you please elaborate a bit more on D2?
|
|
|
|
|
See the description in MSDN.
--------------------------------------------------------------------------------------------------
This format is supported only for integral types. The number is converted to a string of decimal digits (0-9), prefixed by a minus sign if the number is negative.
The precision specifier indicates the minimum number of digits desired in the resulting string. If required, the number is padded with zeros to its left to produce the number of digits given by the precision specifier.
--------------------------------------------------------------------------------------------------
|
|
|
|
|