C# Notify Icon

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 1273 Views - Last Post: 15 August 2010 - 04:29 AM Rate Topic: -----

#1 systemerror  Icon User is offline

  • D.I.C Head

Reputation: -19
  • View blog
  • Posts: 205
  • Joined: 15-August 09

C# Notify Icon

Posted 12 August 2010 - 01:17 AM

Can anyone help me with the Notify Icon because this is in form2 this is my code

private void Alarm_Load(object sender, EventArgs e)
        {
            Form1 newform1 = new Form1();
            newform1.contextMenuStrip1.AlarmToolStripMenuItem.Checked = true;
}


This is my error

Error	1	'System.Windows.Forms.ContextMenuStrip' does not contain a definition for 'AlarmToolStripMenuItem' and no extension method 'AlarmToolStripMenuItem' accepting a first argument of type 'System.Windows.Forms.ContextMenuStrip' could be found (are you missing a using directive or an assembly reference?)	C:\Users\Kyle\documents\visual studio 2010\Projects\Gadgets\Gadgets\Alarm.cs	69	40	Gadgets


Is This A Good Question/Topic? 0
  • +

Replies To: C# Notify Icon

#2 Imdsm  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 103
  • View blog
  • Posts: 362
  • Joined: 21-March 09

Re: C# Notify Icon

Posted 12 August 2010 - 04:28 AM

View Postsystemerror, on 12 August 2010 - 12:17 AM, said:

Can anyone help me with the Notify Icon because this is in form2 this is my code

private void Alarm_Load(object sender, EventArgs e)
        {
            Form1 newform1 = new Form1();
            newform1.contextMenuStrip1.AlarmToolStripMenuItem.Checked = true;
}


This is my error

Error	1	'System.Windows.Forms.ContextMenuStrip' does not contain a definition for 'AlarmToolStripMenuItem' and no extension method 'AlarmToolStripMenuItem' accepting a first argument of type 'System.Windows.Forms.ContextMenuStrip' could be found (are you missing a using directive or an assembly reference?)	C:\Users\Kyle\documents\visual studio 2010\Projects\Gadgets\Gadgets\Alarm.cs	69	40	Gadgets


The problem you have here is that the compiler isn't recognising "AlarmToolStripMenuItem" ..neither am I though. Make sure it is referenced properly if it's an external control.

Also, as for your signature, use parenthasis and two equals signs for comparison operators ;)
Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5631
  • View blog
  • Posts: 12,078
  • Joined: 02-June 10

Re: C# Notify Icon

Posted 12 August 2010 - 11:03 AM

This code is in your Form2 you say.
But Form2 is make a new instance of Form1.
It doesn't matter what you do with checking the menu option because you are doing it in the NEW INSTANCE of a NEW Form1 object. It isn't taking place in the the Form1 you already have open.

Forms are just like buttons... you can make 10 different instances of a Button and they are all different. You can make 10 different instances of a Form1 and they all will look alike, but be different forms.

Instead of your NotifyIcon trying to directly affect the menu item of a form (bad, bad bad) your alarm should do nothing more than raise an event that basically says "My alarm is ringing." Any other forms/classes that subscribe to that event can then react as they are meant to.

Try going through these tutorials to get a better grasp on the concepts of events vs. directly affecting controls in other forms.


Quick and easy custom events
Bulding an application - Part 1

This code is in your Form2 you say.
But Form2 is make a new instance of Form1.
It doesn't matter what you do with checking the menu option because you are doing it in the NEW INSTANCE of a NEW Form1 object. It isn't taking place in the the Form1 you already have open.

Forms are just like buttons... you can make 10 different instances of a Button and they are all different. You can make 10 different instances of a Form1 and they all will look alike, but be different forms.

Instead of your NotifyIcon trying to directly affect the menu item of a form (bad, bad bad) your alarm should do nothing more than raise an event that basically says "My alarm is ringing." Any other forms/classes that subscribe to that event can then react as they are meant to.

Try going through these tutorials to get a better grasp on the concepts of events vs. directly affecting controls in other forms.


Quick and easy custom events
Bulding an application - Part 1
Was This Post Helpful? 0
  • +
  • -

#4 systemerror  Icon User is offline

  • D.I.C Head

Reputation: -19
  • View blog
  • Posts: 205
  • Joined: 15-August 09

Re: C# Notify Icon

Posted 13 August 2010 - 02:39 AM

View PostImdsm, on 12 August 2010 - 03:28 AM, said:

View Postsystemerror, on 12 August 2010 - 12:17 AM, said:

Can anyone help me with the Notify Icon because this is in form2 this is my code

private void Alarm_Load(object sender, EventArgs e)
        {
            Form1 newform1 = new Form1();
            newform1.contextMenuStrip1.AlarmToolStripMenuItem.Checked = true;
}


This is my error

Error	1	'System.Windows.Forms.ContextMenuStrip' does not contain a definition for 'AlarmToolStripMenuItem' and no extension method 'AlarmToolStripMenuItem' accepting a first argument of type 'System.Windows.Forms.ContextMenuStrip' could be found (are you missing a using directive or an assembly reference?)	C:\Users\Kyle\documents\visual studio 2010\Projects\Gadgets\Gadgets\Alarm.cs	69	40	Gadgets


The problem you have here is that the compiler isn't recognising "AlarmToolStripMenuItem" ..neither am I though. Make sure it is referenced properly if it's an external control.

Also, as for your signature, use parenthasis and two equals signs for comparison operators ;)



Ive edited is now its

 Form1 first;
            first.alarmToolStripMenuItem.Checked = false;


now I get
Error	1	Use of unassigned local variable 'first'	C:\Users\Kyle\documents\visual studio 2010\Projects\Gadgets\Gadgets\Alarm.cs	70	13	Gadgets

Was This Post Helpful? 0
  • +
  • -

#5 Imdsm  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 103
  • View blog
  • Posts: 362
  • Joined: 21-March 09

Re: C# Notify Icon

Posted 13 August 2010 - 05:56 AM

Error 1 Use of unassigned local variable 'first'

Form1 first; // <-- nothing is assigned to it :-)
first.alarmToolStripMenuItem.Checked = false;
Was This Post Helpful? 0
  • +
  • -

#6 systemerror  Icon User is offline

  • D.I.C Head

Reputation: -19
  • View blog
  • Posts: 205
  • Joined: 15-August 09

Re: C# Notify Icon

Posted 13 August 2010 - 06:16 AM

View PostImdsm, on 13 August 2010 - 04:56 AM, said:

Error 1 Use of unassigned local variable 'first'

Form1 first; // <-- nothing is assigned to it :-)
first.alarmToolStripMenuItem.Checked = false;



So its more like

Form1 first = new form1();


If its that it doesn't work
Was This Post Helpful? 0
  • +
  • -

#7 Robin19  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 272
  • View blog
  • Posts: 552
  • Joined: 07-July 10

Re: C# Notify Icon

Posted 13 August 2010 - 06:52 AM

Form1 already exists. Saying "Form1 first" creates a reference to a form. "= new Form1()" makes that reference a new form. What you want to do is to reference the Form1 that already exists. There are several ways to do this. My preference is to pass a reference in the constructor. How that is accomplished depends on how Form1 and Form2 are created.

Also, you should not access alarmToolStripMenuItem on Form1 from Form2. You should create a function or property that handles this. Then Form2 just needs to access the function or property.
Was This Post Helpful? 0
  • +
  • -

#8 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5631
  • View blog
  • Posts: 12,078
  • Joined: 02-June 10

Re: C# Notify Icon

Posted 13 August 2010 - 07:55 AM

View PostRobin19, on 13 August 2010 - 05:52 AM, said:

Form1 already exists. Saying "Form1 first" creates a reference to a form. "= new Form1()" makes that reference a new form. What you want to do is to reference the Form1 that already exists. There are several ways to do this. My preference is to pass a reference in the constructor. How that is accomplished depends on how Form1 and Form2 are created.

Also, you should not access alarmToolStripMenuItem on Form1 from Form2. You should create a function or property that handles this. Then Form2 just needs to access the function or property.


Read back a few responses. This was already described to the OP. Apparently they believe that making a new form SOMEPLACE ELSE in their code is going to change the fact that they are still making a new instance of the form1.

POSTER: Did you bother to do the tutorial that you were given a link for? You can either learn by doing or continue on your present course of only working your own project and keep struggling. It's your choice.
Was This Post Helpful? 2
  • +
  • -

#9 systemerror  Icon User is offline

  • D.I.C Head

Reputation: -19
  • View blog
  • Posts: 205
  • Joined: 15-August 09

Re: C# Notify Icon

Posted 13 August 2010 - 05:40 PM

View PosttlhIn, on 13 August 2010 - 06:55 AM, said:

View PostRobin19, on 13 August 2010 - 05:52 AM, said:

Form1 already exists. Saying "Form1 first" creates a reference to a form. "= new Form1()" makes that reference a new form. What you want to do is to reference the Form1 that already exists. There are several ways to do this. My preference is to pass a reference in the constructor. How that is accomplished depends on how Form1 and Form2 are created.

Also, you should not access alarmToolStripMenuItem on Form1 from Form2. You should create a function or property that handles this. Then Form2 just needs to access the function or property.


Read back a few responses. This was already described to the OP. Apparently they believe that making a new form SOMEPLACE ELSE in their code is going to change the fact that they are still making a new instance of the form1.

POSTER: Did you bother to do the tutorial that you were given a link for? You can either learn by doing or continue on your present course of only working your own project and keep struggling. It's your choice.


The tutorial has nothing to do with the subject
Was This Post Helpful? 0
  • +
  • -

#10 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5631
  • View blog
  • Posts: 12,078
  • Joined: 02-June 10

Re: C# Notify Icon

Posted 13 August 2010 - 06:27 PM

Quote

The tutorial has nothing to do with the subject

The tutorial is not written, targeted specifically for your need to work a NotifyIcon.

However the problem(s) you are running in to are because you are not understanding the concept of *instances* of controls. You obviously are not grasping that every time you make a new Form1 it is a different Form1 than the one you think you are trying to communicate with.

The tutorial does cover well the concepts of instances and class-to-class event based notification.

When you grasp the concepts you can apply them to your situation.


It's like carpentry. You can learn the concepts of wood working while creating a set of kitchen cabinets. You can then apply that knowledge and those skills to making a dog house and a bird feeder. But don't say you can't make a dog house because you've *only* built kitchen cabinets and nobody ran you through a course on building a dog house. Same skills applied slightly differently.
Was This Post Helpful? 2
  • +
  • -

#11 systemerror  Icon User is offline

  • D.I.C Head

Reputation: -19
  • View blog
  • Posts: 205
  • Joined: 15-August 09

Re: C# Notify Icon

Posted 13 August 2010 - 07:53 PM

View PosttlhIn, on 13 August 2010 - 05:27 PM, said:

Quote

The tutorial has nothing to do with the subject

The tutorial is not written, targeted specifically for your need to work a NotifyIcon.

However the problem(s) you are running in to are because you are not understanding the concept of *instances* of controls. You obviously are not grasping that every time you make a new Form1 it is a different Form1 than the one you think you are trying to communicate with.

The tutorial does cover well the concepts of instances and class-to-class event based notification.

When you grasp the concepts you can apply them to your situation.


It's like carpentry. You can learn the concepts of wood working while creating a set of kitchen cabinets. You can then apply that knowledge and those skills to making a dog house and a bird feeder. But don't say you can't make a dog house because you've *only* built kitchen cabinets and nobody ran you through a course on building a dog house. Same skills applied slightly differently.



I personally will rather a free E-book on C# for these thing so then i can download it to my pc and my ipod touch so then I can learn it much easier
Was This Post Helpful? 0
  • +
  • -

#12 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5631
  • View blog
  • Posts: 12,078
  • Joined: 02-June 10

Re: C# Notify Icon

Posted 14 August 2010 - 08:39 AM

Quote

I personally will rather a free E-book on C# for these thing so then i can download it to my pc and my ipod touch so then I can learn it much easier
A person after my own technology heart. I have about 50 C++ and C# textbooks as PDF on my iPad for this same reason.
Was This Post Helpful? 0
  • +
  • -

#13 systemerror  Icon User is offline

  • D.I.C Head

Reputation: -19
  • View blog
  • Posts: 205
  • Joined: 15-August 09

Re: C# Notify Icon

Posted 14 August 2010 - 05:04 PM

View PosttlhIn, on 14 August 2010 - 07:39 AM, said:

Quote

I personally will rather a free E-book on C# for these thing so then i can download it to my pc and my ipod touch so then I can learn it much easier
A person after my own technology heart. I have about 50 C++ and C# textbooks as PDF on my iPad for this same reason.


Can you please send me the C# books
Was This Post Helpful? -6
  • +
  • -

#14 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5631
  • View blog
  • Posts: 12,078
  • Joined: 02-June 10

Re: C# Notify Icon

Posted 14 August 2010 - 06:59 PM

Quote

Can you please send me the C# books
No I can't. I bought all my text books, at between $20-$90 each, with them I got PDF versions.

I consider them an investment in my career. So while I might have a couple grand in books, then have paid for themselves many times over.
Was This Post Helpful? 0
  • +
  • -

#15 systemerror  Icon User is offline

  • D.I.C Head

Reputation: -19
  • View blog
  • Posts: 205
  • Joined: 15-August 09

Re: C# Notify Icon

Posted 14 August 2010 - 11:45 PM

View PosttlhIn, on 14 August 2010 - 05:59 PM, said:

Quote

Can you please send me the C# books
No I can't. I bought all my text books, at between $20-$90 each, with them I got PDF versions.

I consider them an investment in my career. So while I might have a couple grand in books, then have paid for themselves many times over.



So whats wrong with sending me the PDF's?
Was This Post Helpful? -7
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2