Click here to Skip to main content
15,925,444 members
Home / Discussions / C#
   

C#

 
AnswerRe: Key Press Event In C# Pin
Graham Nimbley9-Apr-06 14:46
Graham Nimbley9-Apr-06 14:46 
QuestionUnActivate C# Form Pin
Areff9-Apr-06 5:16
Areff9-Apr-06 5:16 
AnswerRe: UnActivate C# Form Pin
User 66589-Apr-06 7:19
User 66589-Apr-06 7:19 
QuestionForm to Web Service Pin
babamara9-Apr-06 4:42
babamara9-Apr-06 4:42 
AnswerRe: Form to Web Service Pin
babamara9-Apr-06 4:44
babamara9-Apr-06 4:44 
QuestionReflection Pin
rmedo9-Apr-06 4:29
rmedo9-Apr-06 4:29 
GeneralRe: Reflection Pin
Guffa9-Apr-06 5:32
Guffa9-Apr-06 5:32 
GeneralRe: Reflection Pin
rmedo10-Apr-06 22:26
rmedo10-Apr-06 22:26 
QuestionShowDialog Help Pin
rikkemus9-Apr-06 0:29
rikkemus9-Apr-06 0:29 
AnswerRe: ShowDialog Help Pin
WillemM9-Apr-06 2:45
WillemM9-Apr-06 2:45 
AnswerRe: ShowDialog Help Pin
CWIZO9-Apr-06 2:47
CWIZO9-Apr-06 2:47 
AnswerRe: ShowDialog Help Pin
Ravi Bhavnani9-Apr-06 5:16
professionalRavi Bhavnani9-Apr-06 5:16 
QuestionXml question Pin
eggie58-Apr-06 15:13
eggie58-Apr-06 15:13 
AnswerRe: Xml question Pin
Jakob Farian Krarup9-Apr-06 6:23
Jakob Farian Krarup9-Apr-06 6:23 
GeneralRe: Xml question Pin
eggie59-Apr-06 9:42
eggie59-Apr-06 9:42 
Questionhow to get errors number in sqlserver from C# Pin
superdragon8-Apr-06 14:28
superdragon8-Apr-06 14:28 
AnswerRe: how to get errors number in sqlserver from C# Pin
Sean898-Apr-06 16:03
Sean898-Apr-06 16:03 
GeneralRe: how to get errors number in sqlserver from C# Pin
superdragon9-Apr-06 18:36
superdragon9-Apr-06 18:36 
QuestionPlz Help me with these two problems !!! Pin
mrkeivan8-Apr-06 9:06
mrkeivan8-Apr-06 9:06 
AnswerRe: Plz Help me with these two problems !!! Pin
Ed.Poore8-Apr-06 9:14
Ed.Poore8-Apr-06 9:14 
GeneralRe: Plz Help me with these two problems !!! Pin
mrkeivan8-Apr-06 10:23
mrkeivan8-Apr-06 10:23 
AnswerRe: Plz Help me with these two problems !!! Pin
Guffa8-Apr-06 11:08
Guffa8-Apr-06 11:08 
GeneralRe: Plz Help me with these two problems !!! Pin
Ed.Poore8-Apr-06 12:20
Ed.Poore8-Apr-06 12:20 
GeneralRe: Plz Help me with these two problems !!! Pin
mrkeivan8-Apr-06 18:04
mrkeivan8-Apr-06 18:04 
GeneralRe: Plz Help me with these two problems !!! Pin
Ed.Poore8-Apr-06 21:44
Ed.Poore8-Apr-06 21:44 
mrkeivan wrote:
OK this code should be in my first form as a property, right ?


This code should be in the form which you are using to display the value, i.e. not the one with the property you're trying to access.

private Form1 f = new Form1();
public Form1 Form {
  get {
    return this.f;
  }
}


This is a property definition, it defines a property called Form with type Form1 (i.e. your form). You cannot have a variable inside the get {...} construct otherwise it will be re-initialised everytime you access the property. Hence the private Form1 f declaration outside the property definition, this only creates a Form1 object once when the variable is initialised and then you can access this variable through the Form property (to get the number property you want.

NB: If you are doing the following:
One form (the "master" form) is in control of displaying the second ("input") and you want the master form to display the number property of the input form then you can do the following which is slightly simpler:

public class MasterForm : Form {
  private Form1 inputForm = new Form1();

  // This is just an example function, you'd put the code from here
  // into you're event handler / whatever function you use to display
  // the code.
  public void DisplayNumber() {
    MessageBox.Show(this.inputForm.number.ToString());
  }
}


This code ensures that by having the variable declared as global to the functions etc inside the MasterForm, the second Form1 is only created once.

Ed

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.