Possible Duplicate:
Get access to parent control from user control - C#
I have btnMessage
on my form Main
, and I also have user control (uc
).
When I click btnMessage
, it opens the uc
and also makes btnMessage.enabled = false
. In uc
, there's a button that's called btnExecute
.
What I want is that when I click on btnExecute
in uc
, btnMessage
in Main
form will be disabled. How I can do this?
Here's the update code :
I'm using function in main.cs
public Main()
{
InitializeComponent();
formFunctionPointer += new functioncall(buttonHideorEnabled);
ucMessageTarget.userFunctionPointer = formFunctionPointer;
}
public delegate void functioncall(bool _status);
private event functioncall formFunctionPointer;
public void buttonHideorEnabled(bool _status)
{
btnMessageTarget.Enabled = _status;
}
and in uc.cs
:
public static string agentName = UtilitiesToolkit.agentMessageTarget;
public static string strn;
public UcMessageTarget(string str)
{
InitializeComponent();
strn = str;
}
public Delegate userControlPointer;
public Delegate userFunctionPointer;
private void btnExecute_Click(object sender, EventArgs e)
{
btnExecute.enabled = false;
userFunctionPointer.DynamicInvoke(false);
//I want btnMessage in Main form also disabled, please tell me how
}
but, still, didn't work. when I compile, I have error in main, in this line :
public Main()
{
InitializeComponent();
formFunctionPointer += new functioncall(buttonHideorEnabled);
ucMessageTarget.userFunctionPointer = formFunctionPointer;
}
said, that
object reference is not set to an instance of object (in ucMessageTarget.userFunctionPointer = formFunctionPointer;).
please help.