Assuming that
myfunc()
is a member of the same class as the
button1_Click()
event handler, you can just use the same code in your function as you would in your event handler:
void myfunc()
{
this->label1->Text = L"Some New Text";
}
I'm hoping that I've understood your question correctly :)
-------------------
Ah, it seems I did misunderstand the question, sorry :)
You want to access a control in a specific class from a function that's not in the same class. In that case, the outside function (myfunc) needs to receive a reference to the label, so that it can access it (otherwise it would be
very hard for the
myfunc
function to find an instance of
label1
)
Unfortunately my C++ is extremely rusty, so I'm not sure what the syntax is for passing references, but in C# I'd do the following:
void myfunc(Label lbl)
{
lbl.Text = "Some New Text";
}
And then calling it like this from inside the
button1_Click
event handler (the "caller"):
myfunc(this.label1);
So in order to get this to work, you'll need to figure out the correct syntax for the label1 argument in both the
myfunc
function and the caller.
I hope this is of more use...