gotcha. thank you very much

On Oct 31, 2:04 pm, Joe Enos <[EMAIL PROTECTED]> wrote:
> Your code must start somewhere non-static - for example, a
> button_click event handler.  From there, you can call a static method
> and just pass the thing in.
>
> Suppose the following:
> You have a textbox with ID txt1.  The code gets started by clicking
> btn1.
> public void btn1_Click(object sender, EventArgs e)
> {
>   DoSomething(txt1);}
>
> public static void DoSomething(TextBox textBox)
> {
>   textBox.Text = "AAA";
>
> }
>
> Working with the form is a little different - if you can stick with
> the textbox only, that will be the easiest and probably the most
> readable.
>
> On Oct 31, 11:00 am, Dickery1 <[EMAIL PROTECTED]> wrote:
>
>
>
> > i am pretty green to c#. can u provide an example or a link on how to
> > pass reference to the form or textbox.
> > appreciate ur help
>
> > On Oct 31, 1:48 pm, Joe Enos <[EMAIL PROTECTED]> wrote:
>
> > > You can't access an instance's textbox from a static method - the
> > > static method does not even know whether or not an instance of the
> > > form even exists, let alone which one is calling it.
>
> > > If you can change your static methods so their not static, that would
> > > be best - or you can pass the reference to the textbox (or the form
> > > itself) around as a parameter, then you'll be able to access it.
>
> > > On Oct 31, 10:42 am, Dickery1 <[EMAIL PROTECTED]> wrote:
>
> > > > i have issues in writing to a textbox from static method
> > > >         private  static void appendToTextBox(string str){
> > > >             Form1.textBox1.Text  += str + "\r\n";
>
> > > >         }
>
> > > >         An object reference is required for the nonstatic field, 
> > > > method, or
> > > > property 'collectTickData.Form1.textBox1'
>
> > > > how do i fix it. aparrently all the mehods calling appendToTextBox are
> > > > static and so i made it static too.
> > > > appreciate any help.- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

Reply via email to