Click here to Skip to main content
15,915,501 members
Home / Discussions / C#
   

C#

 
AnswerRe: Winforms Update form label from a class library Pin
Luc Pattyn9-Jan-12 8:15
sitebuilderLuc Pattyn9-Jan-12 8:15 
GeneralRe: Winforms Update form label from a class library Pin
DaveyM699-Jan-12 8:43
professionalDaveyM699-Jan-12 8:43 
AnswerRe: Winforms Update form label from a class library Pin
BillWoodruff10-Jan-12 6:17
professionalBillWoodruff10-Jan-12 6:17 
QuestionHow to access the control of a form from diffrent form? Pin
Paramu19739-Jan-12 4:08
Paramu19739-Jan-12 4:08 
AnswerRe: How to access the control of a form from diffrent form? Pin
Ravi Bhavnani9-Jan-12 4:15
professionalRavi Bhavnani9-Jan-12 4:15 
AnswerRe: How to access the control of a form from diffrent form? Pin
RexGrammer9-Jan-12 8:09
RexGrammer9-Jan-12 8:09 
AnswerRe: How to access the control of a form from diffrent form? Pin
DaveyM699-Jan-12 9:07
professionalDaveyM699-Jan-12 9:07 
AnswerRe: How to access the control of a form from diffrent form? Pin
BillWoodruff10-Jan-12 6:55
professionalBillWoodruff10-Jan-12 6:55 
1. This code as-is will not compile: the new Form 'MyAppFrm' is created inside the Load event: outside of the scope of the Load event it will not exist: thus you cannot 'refer' to it inside the button1 Click EventHandler.

The "fix" for that is easy enough: make MyAppFrm a class-scoped variable defined outside the Load Event:
private Form MyAppForm;
//
private void Form1_Load(object sender, EventArgs e)
{
    Form MyAppFrm = new Form();
    MyAppFrm.Closing += new CancelEventHandler(MyAppFrm_Closing);
}
2. In your original code you can "get away with" accessing MyAppFrm in the MouseLeave event handler: because that EventHandler had a valid reference to the instance of MyAppFrm <i>when it was added in the Load event of Form2</i>. And, after all, you reference it only indirectly by calling 'GetType() on the 'sender parameter of the EventHandler.

3. Note that in the example above I changed the Event in MyAppForm to 'FormClosing, not 'MouseLeave: if you use 'MouseLeave you'll get an initial trigger of that Event just by the call to ShowDialog ... and, as explained below: showing modally excludes "leaving."

There are good reasons, at times, to show a Form using 'ShowDialog: but in your code I can't detect any reason why are you using 'ShowDialog.

When you use 'ShowDialog: the reason to use it is to prevent any "moving away from it," to block the user from changing focus until the user does something that closes/dismisses the modally shown Form.

Suggest you sit down and try and think through and outline your design goals here: what's going to be inside the new Form created (which is just a blank, "vanilla" Form, now).

If this is a homework question that really does ask "How to access the control of a form from diffrent form?:" then you should be pre-defining ... at Design-Time probably ... the new Form that is created in Form2, and put some Control on it, and focus on the issue of how you get access to that Control from Form2 ?

good luck, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle


modified 10-Jan-12 14:23pm.

GeneralRe: How to access the control of a form from diffrent form? Pin
Paramu197310-Jan-12 19:03
Paramu197310-Jan-12 19:03 
Questiondesktop sharing Pin
Member 38923438-Jan-12 21:24
Member 38923438-Jan-12 21:24 
AnswerRe: desktop sharing Pin
RexGrammer9-Jan-12 1:56
RexGrammer9-Jan-12 1:56 
AnswerRe: desktop sharing Pin
Ravi Bhavnani9-Jan-12 2:06
professionalRavi Bhavnani9-Jan-12 2:06 
QuestionReading an image from an array of data on disk Pin
Subterranean8-Jan-12 1:36
Subterranean8-Jan-12 1:36 
AnswerRe: Reading an image from an array of data on disk Pin
Luc Pattyn8-Jan-12 1:46
sitebuilderLuc Pattyn8-Jan-12 1:46 
GeneralRe: Reading an image from an array of data on disk Pin
harold aptroot8-Jan-12 4:06
harold aptroot8-Jan-12 4:06 
AnswerRe: Reading an image from an array of data on disk Pin
Luc Pattyn8-Jan-12 4:46
sitebuilderLuc Pattyn8-Jan-12 4:46 
GeneralRe: Reading an image from an array of data on disk Pin
harold aptroot8-Jan-12 4:55
harold aptroot8-Jan-12 4:55 
AnswerRe: Reading an image from an array of data on disk Pin
Luc Pattyn8-Jan-12 5:08
sitebuilderLuc Pattyn8-Jan-12 5:08 
GeneralRe: Reading an image from an array of data on disk Pin
harold aptroot8-Jan-12 5:22
harold aptroot8-Jan-12 5:22 
GeneralRe: Reading an image from an array of data on disk Pin
BobJanova9-Jan-12 0:59
BobJanova9-Jan-12 0:59 
QuestionSearch engine for LAN Pin
archies_gall8-Jan-12 0:50
archies_gall8-Jan-12 0:50 
AnswerRe: Search engine for LAN Pin
Richard MacCutchan8-Jan-12 1:16
mveRichard MacCutchan8-Jan-12 1:16 
GeneralRe: Search engine for LAN Pin
archies_gall11-Jan-12 2:04
archies_gall11-Jan-12 2:04 
AnswerRe: Search engine for LAN Pin
Abhinav S8-Jan-12 2:50
Abhinav S8-Jan-12 2:50 
QuestionSearch text in richtextbox wpf c# Pin
moi4117-Jan-12 6:02
moi4117-Jan-12 6:02 

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.