Mike_R Posted November 8, 2004 Posted November 8, 2004 Hi, sorry for the ridiculously Newbie question... But I'm first getting my feet wet with C#... I can't seem to find how to create the Form Events in C#. In VB.Net I would choose 'Form1' from the 'Class Name' Drop Down box and then find the Event I wanted within the 'Method Name' Drop Down. But it does not seem to work the same in C#.Net. I couldn't find any of the Form's events and could only create the Form1_Load() Event by double-clicking the Form within the Designer View. I tried typing in manually:private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { MessageBox.Show("Form1_Closing() was called."); } But it did not actually fire... This must be easy but something eludes me. :( Much thanks in advance... Quote Posting Guidelines Avatar by Lebb
Joe Mamma Posted November 8, 2004 Posted November 8, 2004 events are on a tab in the properties window in the IDE. . . Select the control for which you want to create an event handler. Click the lightning bolt and double click in the event you want to handle. BTW, this is the way it is done in virtually ever other OO IDE I have seen. VB is the odd man out. Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Mike_R Posted November 8, 2004 Author Posted November 8, 2004 Huh, interesting... So I have to choose the Events within the Design View. Feels a bit odd, but, since, as you say, it is really VB that's "odd", I'll just have to get used to it! :) I thank you very much... Quote Posting Guidelines Avatar by Lebb
*Experts* Nerseus Posted November 9, 2004 *Experts* Posted November 9, 2004 You can add events in code if you want. If you want them recognized in the Designer, add them in the InitializeComponent method. If you type something like: this.textBox1.Click += You can then press Tab twice to add the rest of the line and the default function itself. It's not quite as "easy" as VB6, but I still like it. I mostly use the designer to add events as there aren't generally that many to add (maybe 2 dozen on one form and that's only a one time thing). As with VB, you can double click a control in the designer to add a default event (button's get a click event, textbox gets TextChanged, etc.). -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Joe Mamma Posted November 9, 2004 Posted November 9, 2004 You can add events in code if you want. If you want them recognized in the Designer, add them in the InitializeComponent method. If you type something like: this.textBox1.Click += -ner actually the syntax is: SomeClass.SomeEvent += new SomeEventHandler(SomeDelegate); in the case of Textbox.Click, it world be: aTextBox.Click += new EventHandler(MyDelegate); where my delegate is protoyped: void MyDelegate(void sender EventArgs e) There are more event handler definitions other than the simple EventHandler. Get Lowy's Programming .NET Components (O'Rielly) Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Mike_R Posted November 9, 2004 Author Posted November 9, 2004 Thank you both for that... Testing it out, typing in this.textBox1.Click += and then two <Tab> hits works perfectly, as IntelliSense/AutoComplete fills in the rest for you. (Is this called "IntelliSense" still or is "AutoComplete" the new terminology now?) Thanks a lot guys... very neat. :cool: Quote Posting Guidelines Avatar by Lebb
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.