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 example would be:
FILE: classone.cs
namespace DemoApp
{
public class classone : System.Windows. Forms.Form
{
public System.Windows. Forms.TextBox textBox1;
private System.Componen tModel.Containe r components = null;
public classone()
{
InitializeCompo nent();
}
private void InitializeCompo nent()
{
this.textBox1 = new System.Windows. Forms.TextBox() ;
((System.Compon entModel.ISuppo rtInitialize)(t his.timer1)).Be ginInit();
//
// textBox1
//
this.textBox1.L ocation = new System.Drawing. Point(0, 32);
this.textBox1.M ultiline = true;
this.textBox1.N ame = "textBox1";
this.textBox1.R eadOnly = true;
this.textBox1.S crollBars = System.Windows. Forms.ScrollBar s.Both;
this.textBox1.S ize = new System.Drawing. Size(568, 344);
this.textBox1.T abIndex = 4;
this.textBox1.T ext = "textBox1";
//
// classone
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(568, 373);
this.Controls.A dd(this.textBox 1);
this.Load += new System.EventHan dler(this.Form1 _Load);
((System.Compon entModel.ISuppo rtInitialize)(t his.timer1)).En dInit();
this.ResumeLayo ut(false);
}
public void addstatus(strin g status)
{
MessageBox.Show (status);
this.textBox1.A ppendText("HI") ;
this.textBox1.A ppendText(statu s + "\r\n\r\n") ;
}
}
}
FILE classtwo.cs
namespace WxAlert
{
public void addToreport(str ing rep, int debugDetail)
{
classone obj = new classone();
obj.addstatus(r ep);
}
}
When calling the addToreport method, everything compiles and runs - just
nothing gets written to the textbox window. Not even the "HI" - the
information does show correctly in the MessageBox. 6 3226
In actuality this is the same NameSpace - that is a type-o. Thanks for the
assist.
"JP" <Jp******@gmail .com> wrote in message
news:OO******** ********@TK2MSF TNGP12.phx.gbl. .. 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 example would be:
FILE: classone.cs namespace DemoApp
{
public class classone : System.Windows. Forms.Form
{
public System.Windows. Forms.TextBox textBox1;
private System.Componen tModel.Containe r components = null;
public classone()
{
InitializeCompo nent();
}
private void InitializeCompo nent()
{ this.textBox1 = new System.Windows. Forms.TextBox() ;
((System.Compon entModel.ISuppo rtInitialize)(t his.timer1)).Be ginInit();
//
// textBox1
//
this.textBox1.L ocation = new System.Drawing. Point(0, 32);
this.textBox1.M ultiline = true;
this.textBox1.N ame = "textBox1";
this.textBox1.R eadOnly = true;
this.textBox1.S crollBars = System.Windows. Forms.ScrollBar s.Both;
this.textBox1.S ize = new System.Drawing. Size(568, 344);
this.textBox1.T abIndex = 4;
this.textBox1.T ext = "textBox1";
//
// classone
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(568, 373);
this.Controls.A dd(this.textBox 1); this.Load += new System.EventHan dler(this.Form1 _Load);
((System.Compon entModel.ISuppo rtInitialize)(t his.timer1)).En dInit();
this.ResumeLayo ut(false);
}
public void addstatus(strin g status)
{
MessageBox.Show (status);
this.textBox1.A ppendText("HI") ;
this.textBox1.A ppendText(statu s + "\r\n\r\n") ;
}
}
}
FILE classtwo.cs
namespace WxAlert
{
public void addToreport(str ing rep, int debugDetail)
{
classone obj = new classone();
obj.addstatus(r ep);
}
} When calling the addToreport method, everything compiles and runs - just nothing gets written to the textbox window. Not even the "HI" - the information does show correctly in the MessageBox.
You only create the classone form but you never show it. This is what
addToreport should look like addToreport should look like
public void addToreport(str ing rep, int debugDetail)
{
Form2 obj = new Form2();
obj.addstatus(r ep);
obj.Show();
}
/Patric Johansson
My C# blog: http://spaces.msn.com/members/pjsson
Hmm.. Tried that and it just opened a lot of new windows without any change
to the textbox.
What the addToreport method is intending to do is send a string to the other
class which will then print that string in the textbox. I am using this for
reporting. so each time I call that method I want a string to be added to
the text box. Works perfectly if all my methods are in the class that
creates the form, but if I move things to a seperate class I can't seem to
create the same behavior.
"Patric Johansson" <Pa************ *@discussions.m icrosoft.com> wrote in
message news:B8******** *************** ***********@mic rosoft.com... You only create the classone form but you never show it. This is what addToreport should look like addToreport should look like
public void addToreport(str ing rep, int debugDetail) { Form2 obj = new Form2(); obj.addstatus(r ep); obj.Show(); }
/Patric Johansson My C# blog: http://spaces.msn.com/members/pjsson
Ok, add this to your main form where the text box is
If let's say your main form class is called Form1 then:
public static Form1 MainForm = null;
Then on your form initialization set it to itself that way a reference to
your form is maintained. In your form you can setup some accessor
attributes like this:
public string ValueForTextBox
{
set
{
TextBox1.Text = value;
}
get
{
return TextBox1.Text;
}
}
on your other classes, if they are in the same namespace you can use
something like:
Form1.MainForm. ValueForTextBox = somevalue;
Try it and see if it will help you.
"JP" <Jp******@gmail .com> wrote in message
news:Os******** ******@TK2MSFTN GP14.phx.gbl... Hmm.. Tried that and it just opened a lot of new windows without any change to the textbox.
What the addToreport method is intending to do is send a string to the other class which will then print that string in the textbox. I am using this for reporting. so each time I call that method I want a string to be added to the text box. Works perfectly if all my methods are in the class that creates the form, but if I move things to a seperate class I can't seem to create the same behavior.
"Patric Johansson" <Pa************ *@discussions.m icrosoft.com> wrote in message news:B8******** *************** ***********@mic rosoft.com... You only create the classone form but you never show it. This is what addToreport should look like addToreport should look like
public void addToreport(str ing rep, int debugDetail) { Form2 obj = new Form2(); obj.addstatus(r ep); obj.Show(); }
/Patric Johansson My C# blog: http://spaces.msn.com/members/pjsson
Ok - think we're getting closer, so now I get an error:
'System.Windows .Forms.Control. text' is inaccessible due to its protection
level
in:
set
{
this.textBox1.t ext += value;
}
"Alex Passos" <bz@netmerlin.n ospam.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. Ok, add this to your main form where the text box is
If let's say your main form class is called Form1 then:
public static Form1 MainForm = null;
Then on your form initialization set it to itself that way a reference to your form is maintained. In your form you can setup some accessor attributes like this:
public string ValueForTextBox { set { TextBox1.Text = value; } get { return TextBox1.Text; } }
on your other classes, if they are in the same namespace you can use something like:
Form1.MainForm. ValueForTextBox = somevalue; Try it and see if it will help you.
"JP" <Jp******@gmail .com> wrote in message news:Os******** ******@TK2MSFTN GP14.phx.gbl... Hmm.. Tried that and it just opened a lot of new windows without any change to the textbox.
What the addToreport method is intending to do is send a string to the other class which will then print that string in the textbox. I am using this for reporting. so each time I call that method I want a string to be added to the text box. Works perfectly if all my methods are in the class that creates the form, but if I move things to a seperate class I can't seem to create the same behavior.
"Patric Johansson" <Pa************ *@discussions.m icrosoft.com> wrote in message news:B8******** *************** ***********@mic rosoft.com... You only create the classone form but you never show it. This is what addToreport should look like addToreport should look like
public void addToreport(str ing rep, int debugDetail) { Form2 obj = new Form2(); obj.addstatus(r ep); obj.Show(); }
/Patric Johansson My C# blog: http://spaces.msn.com/members/pjsson
On Fri, 1 Apr 2005 13:30:20 -0500, "JP" <Jp******@gmail .com> wrote: Ok - think we're getting closer, so now I get an error:
'System.Window s.Forms.Control .text' is inaccessible due to its protection level
in:
set
{
this.textBox1. text += value;
}
this.textBox1.T ext += value;
with capital T
--
Ludwig Stuyck http://www.coders-lab.net This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: JP |
last post by:
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;
|
by: iwdu15 |
last post by:
how can i open a file i saved and place the info into different text boxes?
|
by: Darin |
last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to
handle textbox.validating, and I have the form setup so the Cancel
button is the Cancel button.
WHen the user clicks on the cancel button, the textbox.validating is
being called. I don't want it to be since they are exiting the screen
the validation doesn't have to be done.
How can I do that.
|
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
|
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...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |