C#程序 [英] C# program

查看:58
本文介绍了C#程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 // main Form class:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using txtboxvalue;

namespace txtboxvalue
{


public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Class1 ob = new Class1();
             ob.fuc();
        }
 



 //Generated separate class:



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace txtboxvalue
{
    class Class1
    {
       
       
        public void fuc()
        {

            Thread th=new Thread(chat);

            th.Start();
             
        }
        public void chat()
        {
            Form1 frm = new Form1();
         frm.textbox.Text = "hello";
        }



        
    }
}


我想访问文本框线程聊天中的主要Form类分配一个value.it只能在fuc方法中完成,但不能在chat方法中完成.plzzzzzzzzzzzz帮助我.........



I want to access  the textbox of main Form class in thread chat to assign a value.it can done only in fuc method but not in chat method.plzzzzzzzzzzz help me.........


推荐答案

我想在线程聊天中访问主要Form类的文本框来分配一个值。它只能在fuc方法中完成,但不能在聊天方法中完成.plzzzzzzzzzzzzz帮助我

我可以告诉你,函数访问的fun()和控件都在同一个处理线程中,启动程序的函数可以访问控件。

I can tell you that the fun() and control that the function is accessing are in the same processing thread, the one that started the program as to why the function can access the control.

也许这会对你有帮助。

https://www.codeproject.com/Articles/269787/Accessing-Windows-Forms-Controls-across-Threads


这篇关于C#程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆