Jump to content
  • Advertisement
Sign in to follow this  
precious roy

code access problem

This topic is 3717 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I was hoping some on can help me with this problem. I want to access the (SetText) from a different class the (SetText) puts text in to a text box. now I open a new thread in that class and it is suppose to insert some text in to my text box. But I can access it, I can call my (SetText) public void but I sit cant access and if I call it public static void then my (SetText) cant access the textbox any more
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;


namespace WindowsApplication2
{
    public partial class Form1 : Form
    {
        delegate void SetTextCallback(string text);
        private Thread demoThread = null;
        private Thread demoThread2 = null;

        public Form1()
        {
            InitializeComponent();
        }

        private void ClientButton_Click_1(object sender, EventArgs e)
        {
            this.demoThread = new Thread(new ThreadStart(this.ThreadProcSafe));
            this.demoThread2 = new Thread(new ThreadStart(TestInsert.InsertTest));
            this.demoThread.Start();
            this.demoThread2.Start();
        }

        private void ThreadProcSafe()
        {
            //this.SetText("This text was set safely.");
            SetText("This text was set safely.");
        }

        public void SetText(string text)
        {
            if (this.ClientTextBox.InvokeRequired)
            {
                SetTextCallback d = new SetTextCallback(SetText);
                this.Invoke(d, new object[] { text });
            }
            else

            {
                ClientTextBox.AppendText(text + "\n");
            }
        }
        public static void test(string mm)
        {
            //I can’t access SetText from here
        }
    }
    class TestInsert
    {
        public static void InsertTest()
        {
            Form1.test("test");
            //I can’t access SetText from here
        }
    }
}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!