SORU
31 Ocak 2009, CUMARTESİ


Bir nesne başvurusu static olmayan alanı, yöntemi veya Windows form özelliği için gereklidir

namespace WindowsApplication1
{       
    public partial class Form1 : Form
    {           
        public Form1()
        {
            InitializeComponent();    
        }    
        private void button1_Click(object sender, EventArgs e)
        {                
            //int[] val ={ 0, 0 };
            int val;
            if (textBox1.Text == "")
            { MessageBox.Show("Input any no"); }
            else
            {
                val = Convert.ToInt32(textBox1.Text);                    
                Thread ot1 = new Thread(new ParameterizedThreadStart(SumData));
                ot1.Start(val);                
                }                  
        }
        private static void ReadData(object state)
        {
            System.Windows.Forms.Application.Run(); 
        }         
        void setTextboxText(int result)
        {
            if (this.InvokeRequired)
            { this.Invoke(new IntDelegate(SetTextboxTextSafe), new object[] { result }); }
            else
            {
                SetTextboxTextSafe(result);
            }    
        }
        void SetTextboxTextSafe(int result)
        {
            label1.Text = result.ToString();
        }            
        private static void SumData(object state)
        {
            int result;
            //int[] icount = (int[])state;
            int icount = (int)state;

            for (int i = icount; i > 0; i--)
            {
                result  = i;
                System.Threading.Thread.Sleep(1000);
            }
         setTextboxText(result);                    
        }
        delegate void IntDelegate(int result);
        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}

Herkes bu hata gerçekleşiyor neden bana cevap verdi diye Nesne başvurusu static olmayan alanı, yöntemi veya özelliği için gereklidir 'WindowsApplication1.Form1.setTextboxText(int)

CEVAP
31 Ocak 2009, CUMARTESİ


Statik bir yöntem olmayan statik bir özellik aradığınız gibi görünüyor. Özelliği statik ya da Form1 örneği oluşturmanız gerekir.

static void SetTextboxTextSafe(int result)
{
    label1.Text = result.ToString();
}

YA

private static void SumData(object state)
{
    int result;
    //int[] icount = (int[])state;
    int icount = (int)state;

    for (int i = icount; i > 0; i--)
    {
        result  = i;
        System.Threading.Thread.Sleep(1000);
    }
    Form1 frm1 = new Form1();
    frm1.setTextboxText(result);
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:
C#

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Anthony Le

    Anthony Le

    10 EKİM 2006
  • Monica Catral

    Monica Catra

    12 NİSAN 2009
  • Xbox

    Xbox

    1 Kasım 2005