Results 1 to 5 of 5

Thread: [RESOLVED] Why do I have to manually setup form events?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Resolved [RESOLVED] Why do I have to manually setup form events?

    I am learning c# (finally) and am using VC# 2010 Express. Why do I have to manually declare events for them to trigger?? I have created my own form that I want to use as a Splash screen (see code below).
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace LotusAnalyzer
    {
        public partial class frmSplash : Form
        {
            public frmSplash()
            {
                InitializeComponent();
                this.MouseDown += new MouseEventHandler(frmSplash_MouseDown);
            }
    
            private void frmSplash_Load(object sender, EventArgs e)
            {
            }
    
            private void frmSplash_KeyDown(object sender, KeyEventArgs e)
            {
                switch(e.ToString())
                {
                    case "enter":
                        this.Close();
                        break;
                 }
            }
    
            private void frmSplash_MouseDown(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Left)
                {
                    this.Close();
                }
            }
        }
    }
    I have a breakpoint at both the mousedown and keydown events. When I press a key they key event will not trigger, however if I mousedown it will (after I added the eventhandler part). Is this inherent to c# or the express version of 2010 or what??

    Thanks in advance!!

    D
    Last edited by dminder; Feb 29th, 2012 at 04:04 PM. Reason: I put this in the wrong forum. Please move.
    Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP

    Please Rate If I helped you.
    Please remember to mark threads as closed if your issue has been resolved.

    Reserved Words in Access | Connection Strings

  2. #2
    Addicted Member
    Join Date
    Jan 2012
    Location
    Athens, Greece
    Posts
    143

    Re: Why do I have to manually setup form events?

    Strange VB syntax...

    This is the way c# works...you have to declare the event handler. If you do it using the properties window in VS it's autogenerated in designer.cs file.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Re: Why do I have to manually setup form events?

    Yeah i realized i was in the VB forum (old habits die hard) after I hit submit. That is why I put the edit on there.

    I am not sure that I am following you there, where in the properties window do you define it??

    Thanks for the quick reply btw

    D
    Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP

    Please Rate If I helped you.
    Please remember to mark threads as closed if your issue has been resolved.

    Reserved Words in Access | Connection Strings

  4. #4
    Addicted Member
    Join Date
    Jan 2012
    Location
    Athens, Greece
    Posts
    143

    Re: Why do I have to manually setup form events?

    There is a "thunder" on the upper side of the Properties Window.

    ps. Old habits are not bad Use VB.Net
    Last edited by pkarvou; Feb 29th, 2012 at 04:28 PM.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Re: Why do I have to manually setup form events?

    AHA!! got it!! Thank you so much!! You earned your creds today.

    Oh and as for VB, I never stop using it. But looking at the jobs that pay something decent, need to be more "Agile".

    D
    Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP

    Please Rate If I helped you.
    Please remember to mark threads as closed if your issue has been resolved.

    Reserved Words in Access | Connection Strings

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width