I have a public property in a partial class (UserControl
) which I would like to access from another partial class (Form
). However I cannot call this property, even though it is public. They are located in the same namespace
, so this should not be the issue.
Partial Class #1 (User Control)
public partial class MyUserControl : UserControl
{
// This is the value I want to read from the main form
public String MyVariableValue
{
get { return cboMyComboBox.Text; }
}
}
Partial Class #2 (Main Form)
public partial class MyForm : Form
{
// This function should show a message box with the value
private void ShowMyVariable()
{
MessageBox.Show("You have selected: " + MyUserControl.MyVariableValue);
}
}
Error code:
CS0119 'MyForm' is a type, which is not valid in the given context
Update: I had a lot of errors in the original code which has been corrected. It is two different forms, that was not clear before, sorry...