Click here to Skip to main content
15,885,195 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to pass the content of a variable from Form.cs to Form.Design.cs in C#

I want to pass the value to the instance but the instance in question is in the Form.Design.cs. How to pass the variable in the Form.Design.cs first to retrieve and pass to the instance in question.


What I have tried:

I passed as in two normal forms but it does not work.
Posted
Updated 17-Mar-21 4:28am
Comments
Richard MacCutchan 17-Mar-21 10:45am    
The question makes no sense. The form.designer.cs file just contains the code to create and display the form and its controls. The actual instance of the Form can be referred to in your Form.cs file by the this keyword.

1 solution

The code in the designer class is the same class as the code in your form class.

It's just split across two different files.

Therefore all the members in one file are directly accessible in the other file.
'
If you have a label called label1 on your designer (which is reflected in Form.Design.cs) you just access it in Form.cs code as

C#
label1.Text = "foo";


like that.

You shouldn't need to mess with the designer code directly. You're probably engaging in some kind of anti-pattern.

What are you trying to do?
 
Share this answer
 
v2
Comments
Member 15037126 17-Mar-21 11:15am    
I want to get the values of a class of a namespace in a class of another namespace. but in my class I don't have an instance of the class to pass the parameter directly but rather in its Form.Design.cs.
honey the codewitch 17-Mar-21 12:17pm    
Okay, it sounds like what you're really trying to do is access something like a control from outside the form it's declared on. For example, you have class a that needs to access an instance of Form.cs. Where is Form created? Because first you'll need that. If it's your main form, it's created in Program.cs in the Main() routine as part of Application.Run().. it calles "new Form()" - you will need the value it returned to access any fields in it. It is simply not otherwise directly possible since that form could be anywhere in memory. Or there might even be more than one of them, or none of them. Without some sort of access to the "pointer" for the instantiated Form you are out of luck. Form is just a class. It's nothing until it's created with "new"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900