R
Ringo
namespace Microsoft.ServiceModel.Samples
Thanks, I can't figure out how to initialize _form. Can you please
explain that part?
Thanks
Ringo
namespace Microsoft.ServiceModel.Samples
{
public partial class Form1 : Form
{
public string TextBox1Text
{
get { return textBox1.Text; }
set { textBox1.Text = value; }
}
}
public class CalculatorService : ICalculator
{
private Form1 _form; // this has to be initialized somewhere,
like
your constructor for example
public double Add(double n1, double n2)
{
_form.TextBox1Text = "foo";
}
}
{
public partial class Form1 : Form
{ ...... }
public class CalculatorService : ICalculator
{
public double Add(double n1, double n2)
{
How do I use a control on the main form from this
Class???????
textbox1.text="foo";//???????????????????????
}
You shouldn't. But if you must, just change the access modifier for the
control, in the Properties in the VS Designer, so that it's visible to
other classes. Then of course you need a reference to your form in that
class.
A much better way (but still requires getting a reference to the form to
some place where the CalculatorService class can see it) is to provide
some kind of accessor in your form class that encapsulates the control's
text. For example:
Thanks, I can't figure out how to initialize _form. Can you please
explain that part?
Thanks
Ringo
namespace Microsoft.ServiceModel.Samples
{
public partial class Form1 : Form
{
public string TextBox1Text
{
get { return textBox1.Text; }
set { textBox1.Text = value; }
}
}
public class CalculatorService : ICalculator
{
private Form1 _form; // this has to be initialized somewhere,
like
your constructor for example
public double Add(double n1, double n2)
{
_form.TextBox1Text = "foo";
}
}