474,037 Members | 2,514 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing to TextBox from Seperate Clas Redux

JP
Okay - I have incorporated some of the advise I got on the first post and
have gone ahead and setup a simple test project to demonstrate the trouble I
am having. Any help is GREATLY appreciated:

FILE FORM1.CS:

using System;

using System.Drawing;

using System.Collecti ons;

using System.Componen tModel;

using System.Windows. Forms;

using System.Data;

namespace simpleapp

{

/// <summary>

/// Summary description for Form1.

/// </summary>

public class Form1 : System.Windows. Forms.Form

{

private System.Windows. Forms.TextBox textBox1;

private System.Windows. Forms.Button button1;

/// <summary>

/// Required designer variable.

/// </summary>

private System.Componen tModel.Containe r components = null;

public Form1()

{

//

// Required for Windows Form Designer support

//

InitializeCompo nent();

//

// TODO: Add any constructor code after InitializeCompo nent call

//

}

public void addstatus(strin g status)

{
this.textBox1.A ppendText(statu s + "\r\n\r\n") ;

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Disp ose();

}

}

base.Dispose( disposing );

}

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeCompo nent()

{

this.textBox1 = new System.Windows. Forms.TextBox() ;

this.button1 = new System.Windows. Forms.Button();

this.SuspendLay out();

//

// textBox1

//

this.textBox1.L ocation = new System.Drawing. Point(0, 24);

this.textBox1.M ultiline = true;

this.textBox1.N ame = "textBox1";

this.textBox1.R eadOnly = true;

this.textBox1.S ize = new System.Drawing. Size(296, 240);

this.textBox1.T abIndex = 0;

this.textBox1.T ext = "";

//

// button1

//

this.button1.Lo cation = new System.Drawing. Point(0, 0);

this.button1.Na me = "button1";

this.button1.Si ze = new System.Drawing. Size(296, 23);

this.button1.Ta bIndex = 1;

this.button1.Te xt = "button1";

this.button1.Cl ick += new System.EventHan dler(this.butto n1_Click);

//

// Form1

//

this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);

this.ClientSize = new System.Drawing. Size(292, 266);

this.Controls.A dd(this.button1 );

this.Controls.A dd(this.textBox 1);

this.Name = "Form1";

this.Text = "Form1";

this.ResumeLayo ut(false);

}

#endregion

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main()

{

Application.Run (new Form1());

}

private void button1_Click(o bject sender, System.EventArg s e)

{

addstatus("Part one, I work \r\n\r\n");

Class1 cls1 = new Class1();

cls1.addstatust oo("Part three, I don't work \r\n\r\n");

}

public string ValueForTextBox

{

set

{

this.textBox1.T ext = value;
}

get

{

return this.textBox1.T ext;

}

}

}

}

file CLASS1.CS:

using System;

namespace simpleapp

{

/// <summary>

/// Summary description for Class1.

/// </summary>

public class Class1

{

public Class1()

{

//

// TODO: Add constructor logic here

//
addstatustoo("p art two, I don't work \r\n\r\n");


}

public void addstatustoo(st ring status)

{

//this doesn't work.

Form1 obj = new Form1();

obj.addstatus(" hi, I don't work either");

obj.addstatus(s tatus);

obj.ValueForTex tBox = "hi I don't work either!" + status + "\r\n\r\n";

}

}

}


Nov 17 '05 #1
4 1912
JP <Jp******@gmail .com> wrote:
Okay - I have incorporated some of the advise I got on the first post and
have gone ahead and setup a simple test project to demonstrate the trouble I
am having. Any help is GREATLY appreciated:


You're not calling Application.Run in, so your form is never running a
message pump.

In Class1 you're creating a new form, but never displaying it. If you
pass a reference to the current form to the addstatustoo method (as an
extra parameter) and act on that instead, you'll see it works.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
JP
Well, if I make it a static method:

public static void addstatus(strin g status)

{

Form1 obj = new Form1();

obj.textBox1.Ap pendText(status + "\r\n\r\n") ;

obj.ShowDialog( );

}

This works, but it displays a new window for everytime I write to it. For
my purposes I need to have the class be able to write to the form - without
having the form pass a reference.

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
JP <Jp******@gmail .com> wrote:
Okay - I have incorporated some of the advise I got on the first post and
have gone ahead and setup a simple test project to demonstrate the
trouble I
am having. Any help is GREATLY appreciated:


You're not calling Application.Run in, so your form is never running a
message pump.

In Class1 you're creating a new form, but never displaying it. If you
pass a reference to the current form to the addstatustoo method (as an
extra parameter) and act on that instead, you'll see it works.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #3
JP
FYI - got this to work by making the textbox static:

private static System.Windows. Forms.TextBox textBox1;

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
JP <Jp******@gmail .com> wrote:
Okay - I have incorporated some of the advise I got on the first post and
have gone ahead and setup a simple test project to demonstrate the
trouble I
am having. Any help is GREATLY appreciated:


You're not calling Application.Run in, so your form is never running a
message pump.

In Class1 you're creating a new form, but never displaying it. If you
pass a reference to the current form to the addstatustoo method (as an
extra parameter) and act on that instead, you'll see it works.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #4
JP <Jp******@gmail .com> wrote:
FYI - got this to work by making the textbox static:

private static System.Windows. Forms.TextBox textBox1;


That's fine so long as there's only ever one textbox you need to write
to, but it's very inflexible.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1978
by: Sue | last post by:
Anyone have any ideas on why the code below will show up in a browser's sourcecode as an empty table, and is not visible? aspx: <headertemplate> <asp:Table ID="MyTable" runat="server" /> </headertemplate>
6
3227
by: JP | last post by:
I'm sure this is a simple question and I'm overlooking the obvious. But, I have two seperate classes (in seperate files) under the same namespace. I am calling a method in one class that contains public System.Windows.Forms.TextBox textBox1; When I try to write to this textbox it never publishes anything. If I call the same method from inside the same class it does. How can I publish to this textbox from an external class. Simple...
7
2152
by: I am Sam | last post by:
I have a DataGrid that is passing information to a stored procedure properly but the parameters aren't being casted properly. I was woundering if anyone can tell me how I should properly cast the following: (TextBox)UserPrefix=(TextBox)e.Item.Cells.Controls; string strUserPrefix=UserPrefix.Text; I keep getting the following error and I don't know why because I have declared the UserPrefix as a textbox using "protected...
19
1995
by: hamil | last post by:
I have a form with one button, Button1, and a Textbox, Textbox1 I have a class, class1 as follows. Public Class Class1 Public DeForm As Object Sub doit() DeForm.Textbox1.text = "It works" End Sub End Class
16
2230
by: iwdu15 | last post by:
how can i open a file i saved and place the info into different text boxes?
5
1666
by: Ian Tedridge | last post by:
If I have 3 textboxes on a form plus 1 multiline textbox. How can I add the text from textbox 1 to 3 to the multiline textbox ? I can add the 3 textbox contents to one line of the multiline textbox, but need each text line to appear on seperate lines. this is driving me crazy, please help
10
2504
by: garyusenet | last post by:
I have a multiline textbox. The size of the text box should be 75 characters wide, and 5 lines in height like this: - <---75 characters--> <---75 characters--> <---75 characters--> <---75 characters--> <---75 characters-->
7
2883
by: billa856 | last post by:
Hi, My project is in MS Access 2002. In that I have two forms which I am using for Shipping Entry. Now First Form(ShippingAlerts) Is fillup by persons working in customer services.and the Second Form(ShippingEntry) is fillup by workers operating Hi-Low machines to put Boxes in Trucks. Now In First Form(ShippingAlerts)I have some fields like AutoNo,BillToAddress,ShipToAddress. and some other like CustomerCode,ItemNo,PONo,LONo,PalletNo...
8
4915
by: fniles | last post by:
I am using VB.NET 2008. I would like to search a textbox (find next and find previous), and when it finds the text, move my cursor in the textbox to where the found text is. How can I do that ? Thank you
0
10532
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10328
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
12120
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11591
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
11128
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8685
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6639
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4933
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3951
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.