Re: update Window Form's list box.
From: alan (alan_at_discussions.microsoft.com)
Date: 10/14/04
- Next message: alan: "Re: update Window Form's list box."
- Previous message: Serge Lobko-Lobanovsky: "System.OutOfMemory exception: error creating window handle"
- In reply to: Claes Bergefall: "Re: update Window Form's list box."
- Next in thread: alan: "Re: update Window Form's list box."
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 14 Oct 2004 02:15:08 -0700
thanks!
but i get the following error
private Class1 cls= new Class1(this);
" Keyword this is not available in the current context"
"Claes Bergefall" wrote:
> Well, you failed to mention that you already had an existing form.
> Pass a reference of your exisiting form to the constructor of Class1
>
> public class Form1 : System.Windows.Forms.Form
> {
> private Class1 cls = new Class1(this);
> }
>
> public class Class1
> {
> private Form1 m_frm;
> public Class1(Form1 frm)
> {
> m_frm = frm;
> }
> public void update()
> {
> m_frm.label1.Text = "yeah";
> }
> }
>
> /claes
>
>
> "alan" <alan@discussions.microsoft.com> wrote in message
> news:25D54A82-D4C1-42DE-B390-86CDEC9A275B@microsoft.com...
> > Label won't be updated, thanks!
> > here is my example :
> >
> > Form1.cs
> >
> > using Cls_ns;
> >
> > namespace sampleFrm
> > {
> > public class Form1 : System.Windows.Forms.Form
> > {
> > public System.Windows.Forms.Label label1;
> > private System.Windows.Forms.Button button1;
> > static Class1 cls = new Class1 ();
> > ...etc....
> > static void Main()
> > {
> > Application.Run(new Form1());
> > }
> > private void button1_Click(object sender, System.EventArgs e)
> > {
> > cls.update ();
> > }
> > }
> > }
> >
> > Class1.cs
> >
> > --------------------------------------------------------------------------
> ----
> > using System;
> > using sampleFrm;
> >
> > namespace Cls_ns
> > {
> > /// <summary>
> > /// Summary description for Class1.
> > /// </summary>
> > public class Class1
> > {
> > static Form1 frm = new Form1 ();
> > public Class1()
> > {
> > //
> > // TODO: Add constructor logic here
> > //
> >
> > }
> >
> > public void update()
> > {
> > frm.label1.Text = "yeah";
> > }
> > }
> > }
> >
> >
> >
> > "Claes Bergefall" wrote:
> >
> > > The code that you show should work just fine.
> > > You'll need to provide more info/code
> > >
> > > /claes
> > >
> > > "alan" <alan@discussions.microsoft.com> wrote in message
> > > news:4BBEC6E2-B741-41E0-BB59-28600E455D6E@microsoft.com...
> > > > I have 2 classes
> > > > form.cs and cls1.cs
> > > >
> > > > in form.cs
> > > > using cls1_ns;
> > > > namespace form_ns
> > > > {
> > > > ....public class formCls.....
> > > > public System.Windows.Forms.ListBox LstBox;
> > > > ...}
> > > >
> > > > in cls1.cs
> > > >
> > > > using form_ns;
> > > > namespace cls1_ns
> > > > {
> > > > class ...etc...
> > > > static formCls cForm = new formCls();
> > > > .....
> > > > public void funcA()
> > > > {
> > > > ....
> > > > cForm.LstBox.Add (....)
> > > > }
> > > > }
> > > > }
> > > >
> > > > this doesn't work, would you please tell how to update the value in
> window
> > > > form from another class?
> > > > thanks a lot!!!
> > > >
> > >
> > >
> > >
>
>
>
- Next message: alan: "Re: update Window Form's list box."
- Previous message: Serge Lobko-Lobanovsky: "System.OutOfMemory exception: error creating window handle"
- In reply to: Claes Bergefall: "Re: update Window Form's list box."
- Next in thread: alan: "Re: update Window Form's list box."
- Messages sorted by: [ date ] [ thread ]