6 Replies - 2901 Views - Last Post: 21 May 2010 - 04:26 PM Rate Topic: -----

#1 thebluebomberman   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-May 10

New to C#/Programming

Posted 20 May 2010 - 04:09 PM

Hi,

I am new to C# and have extremely limited experience in C++ and JS. I working a project for myself in MS Visual C# Express and I am hoping to be able to teach myself everything I need for my project. After going through some tutorials I have learned some basics on creating a GUI and have now come to my first road block.

I am looking to be able to track events, specifically I want to know whenever a new window is created and destroyed, as well as finding the string value associated with the window's title bar.

Is there a sort of event handler that I could use in my code that notifies the program of events happening in the Window's environment? Any help or a link discussing this topic would be very helpful,

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: New to C#/Programming

#2 elbielefeld   User is offline

  • D.I.C Head

Reputation: 70
  • View blog
  • Posts: 217
  • Joined: 18-May 10

Re: New to C#/Programming

Posted 20 May 2010 - 04:17 PM

Hi,

look for the Forms Load und FormClosed events. See
http://msdn.microsof...orm_events.aspx
Was This Post Helpful? 1
  • +
  • -

#3 Sergio Tapia   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1258
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: New to C#/Programming

Posted 20 May 2010 - 05:08 PM

You can use this to see the form's title.

//create a new Form!
Form thisIsMyForm = new Form();

//get it's string!
thisIsMyForm.Text;

Was This Post Helpful? 0
  • +
  • -

#4 FlashM   User is offline

  • D.I.C Lover
  • member icon

Reputation: 383
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: New to C#/Programming

Posted 20 May 2010 - 11:55 PM

There are also some static system level events that you can subscribe to. They are triggered for example when Display settings are changed, Installed fonts are changed, Palette is changed, Power mode is changed, etc... Find more info at: http://blogs.techrep...m/howdoi/?p=135
Was This Post Helpful? 0
  • +
  • -

#5 FlashM   User is offline

  • D.I.C Lover
  • member icon

Reputation: 383
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: New to C#/Programming

Posted 21 May 2010 - 12:23 AM

I would do this like this:


namespace WindowsEventsApp
{
    public enum FormsEnum
    {
        FIRST_FORM,
        SECOND_FORM
    }

    public partial class frmContainerForm : Form
    {
        public frmContainerForm()
        {
            InitializeComponent();
        }


        private Form CreateForm(FormsEnum form)
        {
            Form frm = null;

            switch (form)
            {
                case FormsEnum.FIRST_FORM:
                    frm = new frmFirstForm();
                    break;
                case FormsEnum.SECOND_FORM:
                    frm = new frmSecondForm();
                    break;
            }

            frm.Load += new EventHandler(FormLoad);
            frm.FormClosing += new FormClosingEventHandler(FormClosingEvent);
            frm.Disposed += new EventHandler(FormDisposed);

            return frm;
        }

        private void ShowForm(FormsEnum form)
        {
            Form frm = CreateForm(form);
            frm.Show();
        }

        private void btnCreateFirstForm_Click(object sender, EventArgs e)
        {
            ShowForm(FormsEnum.FIRST_FORM);
        }

        private void btnCreateSecondForm_Click(object sender, EventArgs e)
        {
            ShowForm(FormsEnum.SECOND_FORM);
        }

        private void FormLoad(object sender, EventArgs e)
        {
            Form sender_form = sender as Form;

            if (sender_form != null)
                Console.WriteLine("{0} has been loaded...", sender_form.Text);
        }

        void FormClosingEvent(object sender, FormClosingEventArgs e)
        {
            Form sender_form = sender as Form;

            if (sender_form != null)
                Console.WriteLine("{0} is in state of closing...", sender_form.Text);
        }

        private void FormDisposed(object sender, EventArgs e)
        {
            Console.WriteLine("Form has been successfully  disposed...");
        }
    }
}




If you need any additional info about this solution, feel free to ask...
Was This Post Helpful? 1
  • +
  • -

#6 thebluebomberman   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-May 10

Re: New to C#/Programming

Posted 21 May 2010 - 04:13 PM

Unfortunately I am finding that I can only follow around 20-30% of most of this code.

Does anyone know of a good online resource that discusses syntax of functions, variable declaration etc?

Also, void functionXX() void just means it doesn't return a value correct? so int functionXX() would return an integer, etc?

Thanks again for the help, hopefully I won't be too much of a pester as I try and learn all of this =)
Was This Post Helpful? 0
  • +
  • -

#7 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1660
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: New to C#/Programming

Posted 21 May 2010 - 04:26 PM

You are correct about void, it doesn't return a value. As far as syntax and such you can check out our C# Reference Guide (Cheat Sheet)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1