Click here to Skip to main content
15,887,596 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# Getting Responce From Form1 Pin
venomation21-Aug-10 3:33
venomation21-Aug-10 3:33 
AnswerRe: C# Getting Responce From Form1 Pin
DaveyM6921-Aug-10 6:14
professionalDaveyM6921-Aug-10 6:14 
GeneralRe: C# Getting Responce From Form1 Pin
Pete O'Hanlon21-Aug-10 7:59
mvePete O'Hanlon21-Aug-10 7:59 
GeneralRe: C# Getting Responce From Form1 Pin
C.CoderCreator21-Aug-10 14:00
C.CoderCreator21-Aug-10 14:00 
GeneralRe: C# Getting Responce From Form1 Pin
Pete O'Hanlon21-Aug-10 21:13
mvePete O'Hanlon21-Aug-10 21:13 
GeneralRe: C# Getting Responce From Form1 Pin
C.CoderCreator21-Aug-10 21:51
C.CoderCreator21-Aug-10 21:51 
GeneralRe: C# Getting Responce From Form1 Pin
Pete O'Hanlon22-Aug-10 3:17
mvePete O'Hanlon22-Aug-10 3:17 
GeneralRe: C# Getting Responce From Form1 Pin
DaveyM6922-Aug-10 4:32
professionalDaveyM6922-Aug-10 4:32 
Seriously, quit trying to access controls on Form1 from Form2. It's not any easier than doing things the correct way and ends up messy. Trust me, drop that idea now... really!

Consider the following - it may not apply right now, but if you continue with programming you can be sure it will one day very soon.

Imagine you are developing a new class/control that you want to reuse across applications, and maybe even sell. In your use of this class, depending on a result you want to disable certain controls.

You could pass the controls to your class in a constructor or via a property/method - sounds good? No! If you want to reuse your class elsewhere, or others (customers) use it - it just isn't going to work without those controls which may not be relevant to their useage. So your class is broken. It will end up having to be re-written, or in the case of customers - refunds given.

Worse still, you could attempt the method you are trying, and access public static fields/properties on the object that owns the controls. What if they don;t exist? Again, your class is just plain broken.

However, you could adopt the same principles used by MS and all the others. When they developed for example the Button control they had no idea what you would do with it and certainly had no knowledge of the classes/objects that you would use it with, but still it works perfectly without issues. They provided a few properties to control it's appearance etc, and the most important thing - a Click event. Now you handle that event easily and everything is good in the world, yet Button has no knowledge of your classes/objects that are using it and it never should have.

Do the same, Form2 should let the world and all their relatives/friends know that something has happened (an event) that they may want to react to. If they are interested they can opt to listen for this event by adding a handler and respond accordingly. In your case this is Form1 that should handle an event from Form2 and only Form1 should do the thing with the menu item.
Dave

If this helped, please vote & accept answer!


Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

GeneralRe: C# Getting Responce From Form1 Pin
DaveyM6922-Aug-10 5:14
professionalDaveyM6922-Aug-10 5:14 
GeneralRe: C# Getting Responce From Form1 Pin
Pete O'Hanlon22-Aug-10 5:28
mvePete O'Hanlon22-Aug-10 5:28 
GeneralRe: C# Getting Responce From Form1 Pin
DaveyM6922-Aug-10 5:45
professionalDaveyM6922-Aug-10 5:45 
QuestionWindows service cannot able to start Pin
sekannak21-Aug-10 1:18
sekannak21-Aug-10 1:18 
AnswerRe: Windows service cannot able to start Pin
OriginalGriff21-Aug-10 2:11
mveOriginalGriff21-Aug-10 2:11 
AnswerRe: Windows service cannot able to start Pin
PIEBALDconsult21-Aug-10 4:24
mvePIEBALDconsult21-Aug-10 4:24 
QuestionItems in ComboBox Pin
igalep13221-Aug-10 0:56
igalep13221-Aug-10 0:56 
AnswerRe: Items in ComboBox Pin
Dave Kerr21-Aug-10 1:17
mentorDave Kerr21-Aug-10 1:17 
GeneralRe: Items in ComboBox Pin
igalep13221-Aug-10 1:22
igalep13221-Aug-10 1:22 
QuestionPrintPreview WTF? Pin
Dr.Walt Fair, PE20-Aug-10 16:02
professionalDr.Walt Fair, PE20-Aug-10 16:02 
QuestionEvent Handling in Windows Services [modified] Pin
See_Sharp20-Aug-10 7:27
See_Sharp20-Aug-10 7:27 
AnswerRe: Event Handling in Windows Services PinPopular
Eddy Vluggen20-Aug-10 7:48
professionalEddy Vluggen20-Aug-10 7:48 
GeneralRe: Event Handling in Windows Services Pin
See_Sharp20-Aug-10 8:14
See_Sharp20-Aug-10 8:14 
GeneralRe: Event Handling in Windows Services Pin
Eddy Vluggen20-Aug-10 8:28
professionalEddy Vluggen20-Aug-10 8:28 
Questionwebpage popping out from iframe [modified] Pin
Hiren solanki20-Aug-10 3:36
Hiren solanki20-Aug-10 3:36 
AnswerRe: webpage popping out from iframe Pin
Łukasz Nowakowski20-Aug-10 3:47
Łukasz Nowakowski20-Aug-10 3:47 
AnswerRe: webpage popping out from iframe Pin
Ennis Ray Lynch, Jr.20-Aug-10 3:49
Ennis Ray Lynch, Jr.20-Aug-10 3:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.