mercredi 7 août 2019

how do I retrieve the status of a checkbox within a usercontrol.cs from the main form or from another usercontrol?

I am completely new to C#, (started last Sunday). Only doing this project for fun. I'm building a simple program that randomly selects an item from a list of items, but I'm using groups of items to limit the choices. I created a usercontrol1 with a several checkboxes (MoB, LotW, etc.) that represent those groups of items. So, if checkbox MoB and LotW are checked on usercontrol1, then when I push a button on form1 it will choose a random item from MoB or LotW. If just MoB is checked it will only choose from group MoB.

My problem is that when I try to reference the checkboxes on form1, it doesn't recognize the checkbox. Thanks in advance.

I've searched several threads such as below. But I don't want to create a new form. I just want to access the information within the usercontrol1. I made sure that the checkboxes were set to public. I don't know if there are more things I need to set to public.

transfer value between checkboxes in another forms in C#

//not sure about showing code. All I want to do is a simple if statement where MoB is a checkbox on userControl1 and userControl3 retrieves the status of said checkbox.

public UserControl3()

{

InitializeComponent();

if (MoB.Checked) { cavemonsters.Add("Goblin Archer");

}

Error is: "The name MoB does not exist in the current context"




Aucun commentaire:

Enregistrer un commentaire