Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have a C# winforms app which I'm trying to pass a 0 or 1 from a checkbox on a form upon a button click to another project in the solution for use in a string.

The 0 or 1 in the string modifies the data that an API pulls.

What I have tried:

In the form, I have

private void OK_Click(object sender, EventArgs e)
{
int passme = checkbox1.Checked ? 0 : 1;
}

and

private void checkbox1_CheckedChanged(object sender, EventArgs e)
{

}

and passme returns the value within the form, but how do I pass it to another project to use in the string with the button click?

Any help would be appreciated, this is my first time playing with C# and I can't seem to figure this out.
Posted
Updated 18-Apr-21 19:52pm
Comments
Mohibur Rashid 19-Apr-21 0:12am    
what is the interface to share this information, you need to decide.
[no name] 19-Apr-21 0:49am    
Add a public static string field / property to the other project, and store it in that. (the 25 cent solution).

1 solution

The first thing to work out is "what is the other project?"

1) If you mean another form, then it's not difficult, but exactly how you do it depends on the "relationship" between the two forms.
Have a look at these, one of them will fit your circumstances.
The form that creates an instance of another:
C#
MyForm mf = new MyForm();
mf.Show();
Is the "parent", the other form is the "child".
(This doesn't imply any formal MDI relationship)

Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 2: Child to Parent[^]
Transferring information between two forms, Part 3: Child to Child[^]

2) If it's a separate project within the same solution (i.e. a separate EXE or DLL file is created when you build your application in Visual Studio) then you need to look at that project and decide which class it needs to go to, and what properties to use, then find the appropriate instance of that class to work with. Or perhaps add the class and / or properties! We can't help you with that as we have no idea what you code looks like!

3) If it's a separate project that is added as a Reference to your application in Visual studio, then it's the same as (2) above, but with the added complication that you may not be able to see or modify the code in the "destination" project either!

So start by sitting down and working out what you need to happen to what, and when - then start thinking about what you need to know in order to do it. We can't tell you "do this" because we have no idea what you have to work with, and we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
 
Share this answer
 

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