Home > Net >  Winform window by value
Winform window by value

Time:11-09

Winform, the main form to the child form by value, not pop-up window, just to save values, and then open the child form when to receive the main window to get the value of the intermediate is passed through what can? (a form of the background data, the main form of the value of a field change, child form after receive the value will be the new value shown)
I in model layer defines a new model, inherit the child form to show the background information of the model, in the main form of assignment with the new model and child form to receive the value of the new model, but have not received, could you tell me how to write should be?
Child form to show the background information call model:
Public partial class testModel
{
Public testModel ()
{}
# region Model

///no.
Public int testId {get; The set; }

///name
Public string testName {get; The set; }

///
Public string testVal {get; The set; }

# endregion Model
}
Create a new model inherits the above model, used for main form will be handed over the new value
Public partial class newtestModel: testModel
{
Public newtestModel ()
{}
# region Model

///
Public string newtestVal {get; The set; }

# endregion Model
}
Main form of the combination of a new model of value:
Public List Newlist=new List (a);
Foreach (Model. TestModel aa in the list)//(the list is to testModel backstage data)
{
Model. NewtestModel b=new Model. NewtestModel ();
B.t estId=aa. TestId;
B.t estName=aa. TestName;
B.n ewtestVal=1;
Newlist. Add (b);
}
Child form receiving:
Fmain fe=new fmain ();//main form
List List=fe. Newlist;//the result is null
I want to change the main form of value to the child form, present child form, should be how to write? Wish you a great god for help, thank you ~

CodePudding user response:

Can use a static class

CodePudding user response:

reference 1/f, mo zi Chen reply:
can use static class

Can you specific points?

CodePudding user response:

First of all you the new one main form is a new master form object is certainly not
To get the main window static object can be used to save the main window reference
But such modifications of the main window and cannot inform your child window, child Windows don't know when the main window will change value of
This time can be defined in child window events value changes in the main window and used to notify the child window

CodePudding user response:

How do you write fmain constructor

CodePudding user response:

reference OrdinaryCoder reply: 3/f
, first of all, you are the new one main form is a new master form object is certainly not
To get the main window static object can be used to save the main window reference
But such modifications of the main window and cannot inform your child window, child Windows don't know when the main window will change value of
This time can be defined in child window events value changes in the main window and used to notify the child window

The static class how to write can be added value to the child form cycles corresponding values show?

CodePudding user response:

reference 4 floor Bridge_go response:
fmain constructor how to write the

Main form haven't write, I was responsible for writing the child form, need to do is to build an interface or the model, the main form to change the value of the displayed on the child form, but now I write the model has a problem, there is a problem or get way

CodePudding user response:

Methods varied,
By value between forms,
1 simple point: a static variable
2 trouble spot: entrusted

Of course, if you want to save the database, it doesn't matter,,,,,,,

CodePudding user response:

references to learn ~ 5 floor response:
Quote: refer to the third floor OrdinaryCoder response:

First of all you the new one main form is a new master form object is certainly not
To get the main window static object can be used to save the main window reference
But such modifications of the main window and cannot inform your child window, child Windows don't know when the main window will change value of
This time can be defined in child window events value changes in the main window and used to notify the child window

The static class how to write can be added value to the child form cycles corresponding values show?

Can be defined in any kind of public static MainWindow MainWindow.
Assignment can be in the Loaded event MinWindow
The name of the class. The mainWindow=this;

CodePudding user response:

Defines the interface, using the interface, reference https://www.cnblogs.com/xbingyou/p/12370909.html

CodePudding user response:

references on 7th floor is wrath of god reply:
methods varied,
By value between forms,
1 simple point: a static variable
2 trouble spot: entrusted

Of course, if you want to save the database, it doesn't matter,,,,,,,

Static variables, how many

CodePudding user response:

references to learn ~ 10 floor response:
Quote: refer to 7th floor is nu month god reply:

Methods varied,
By value between forms,
1 simple point: a static variable
2 trouble spot: entrusted

Of course, if you want to save the database, it doesn't matter,,,,,,,

How static variables, multiple

If it is a lot of variables, you can put into a class,

CodePudding user response:

references to learn ~ 2 floor response:
Quote: reference 1/f, mo zi Chen reply:

You can use a static class

Can you specific points?


Have told, want oneself to deal with

CodePudding user response:

Defined in child form a public methods, this method will value, after the parent form instance, anti-fuzzy form, calling the child form method

CodePudding user response:

Learning,,... ,... . ...

CodePudding user response:

Static class, database, or the form, or use a reference type

CodePudding user response:

1: trust, also known as agent
2: events
3: the public attribute
4: define a public static class
Tell me you like that?

CodePudding user response:

Methods varied,
By value between forms,
Static variable
Entrust

CodePudding user response:

Child form a copy of the original constructor, and then paste, then add a parameter list, inside the parent form to create a child form use child form when add the new constructor (with list parameters), so that you can pass the child form the modified list

CodePudding user response:

Look at my blog, may be used

CodePudding user response:

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related