473,473 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

GUI editing problem via thread

1 New Member
Hello,

I would like to edit textMain from Form1 via a static class on an other thread. But I get the following error:

An object reference is required for the nonstatic field, method, or property 'WindowsApplication1.Form1.SetText(string)'

I simplified the example. Anybody who can help me?

Expand|Select|Wrap|Line Numbers
  1.     public partial class Form1 : Form
  2.     {
  3.         // Set text delegate
  4.         public delegate void SetTextDelegate(string text);
  5.  
  6.         Thread trdTest;
  7.  
  8.         // Form1
  9.         public Form1()
  10.         {
  11.             InitializeComponent();
  12.             trdTest = new Thread(new ThreadStart(DoThread));
  13.             trdTest.Start();
  14.         }
  15.  
  16.         // Thread
  17.         void DoThread()
  18.         {
  19.             StaticClass.EditGUI();
  20.         }
  21.  
  22.         // Change textbox text
  23.         public void SetText(string text) 
  24.         {
  25.             if (txtMain.InvokeRequired) 
  26.             {
  27.                 object[] params_list = new object[] { text };
  28.                 txtMain.Invoke(new SetTextDelegate(SetText), params_list);
  29.             }
  30.             else 
  31.             {
  32.                 txtMain.Text = text;
  33.             }
  34.         }
  35.  
  36.     }
  37.  
Expand|Select|Wrap|Line Numbers
  1.     // Static class
  2.     public static class StaticClass
  3.     {
  4.         public static void EditGUI()
  5.         {
  6.             Form1.SetText("test");
  7.         }
  8.     }
Aug 20 '07 #1
0 826

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Dan Weeb | last post by:
Hi All, I have struggled through this far with help from many of you so thanks. I am stuck again. I am really new to this so don't be harsh :-) There are a few problems. You can run the script...
1
by: nospam | last post by:
Amazon wins patent for ordering forms, Collapsing and Maximizing Form Areas.... NAME OF PATENT Method and system for displaying and editing of information # 6,615,226 ...
0
by: Sebi | last post by:
Hello All, I'm having problems, reading the new Values from CheckBox in a DataGrid. my Code Behind is C# I do exactly what other samples do, but I allways get the Initial Values instead of...
4
by: Stuart Ferguson | last post by:
I am attempting to put a screen in a web application that allows editing of AppSettings values in the Web.Config file using the Web Configuration manager class however on he .Save i get an access...
2
by: jpenn44 | last post by:
I have multiple datagridviews on one form. I am allowing editing in the grid, and am performing error checking. I am validating the data, if it isn't valid, I am cancelling any other events...
7
by: Rainy | last post by:
Hi, did anyone make a good set of scripts for editing Python in Vim? I know there is one on vim.org but it isn't very advanced. thx..
15
by: lbrtchx | last post by:
I am trying to write up a page with Math formulas (statistical ones) ~ http://www.geocities.com/tekmonk2005/OnLineStats02.html ~ The thing is that I am not able to make it look OK using HTML. I...
2
by: Chris Paxton | last post by:
I have a fairly basic VB.NET application that I converted from VS2003 to VS2005 and now it crashed the VS2005 IDE pretty regularly while trying to use the form designer. I've removed any 3rd...
12
by: Snoopy33 | last post by:
I have a FE / BE setup on my database. One of the main reasons that I did this was so that I could edit the front end and upload it without causing problems with day to day activities. I have...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.