473,395 Members | 1,413 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Access a form's control e.g. Label1 directly from a Self Defined Class

How on planet earth do you access a form's component e.g Label from a self defined class.

Class SelfDefinedClass
{
....
public void myMethod()
{
Label1.Text = "yzyzyzyz";
}
}
Dec 6 '11 #1
1 1274
adriancs
122 100+
go to the designer of that form.
for example: Form2.Designer.cs
change the properties of the component from private to public
example:
change this
Expand|Select|Wrap|Line Numbers
  1. private System.Windows.Forms.Label label1;
to this
Expand|Select|Wrap|Line Numbers
  1. public System.Windows.Forms.Label label1;
then upon creating/or after closing the Form, you'll be able to gain access the value of the component.
example:
Expand|Select|Wrap|Line Numbers
  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3.     Form2 f2 = new Form2();
  4.     f2.label1.Text = "Change to this text";
  5.     f2.ShowDialog();
  6.     MessageBox.Show(f2.label1.text);
  7. }
Dec 7 '11 #2

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

Similar topics

7
by: James Fortune | last post by:
In response to different users or situations (data context) I transform the appearance and characteristics of Access Forms through code. This seems to fit in with the idea of polymorphism. Do...
6
by: Programmer | last post by:
I am making a project in which i have one interface ITest, and a class which is implementing that interface. I am making object of that class using object...
2
by: KK | last post by:
Hi All I need to create a windows form control(from System.Windows.Forms.dll assembly) dynamically using Activator.How do I achieve this?Sample code is much more helpful. Thanks in advance ...
1
by: paulyip | last post by:
I've create a private class and an arrayList of it. I found that I can't us indexOf the check whether they are the same. Is it true that they are in different location in the memory, that I have...
0
by: Vincent Mouton | last post by:
Hi, I am having trouble integrating a System.Windows.Forms.Control into an asp.net page. I based my tryout on the sample provided in the quickstart tutorials...
2
by: Richard Dixson | last post by:
I created a web form and dropped a table in there called resultsTable. This also resulted in the following being added to the Webform1 class: public System.Web.UI.WebControls.Table resultsTable; ...
1
by: William Parker | last post by:
I have a web control I made called header.ascx. It has its own properties and methods I defined. But I cannot figure out how to access this control from my code behind page. I can create the...
5
by: c676228 | last post by:
Hi, I guess I am confused. In aspx script, I mean (you won't use Codebehind="enrollinfo.aspx.vb", but mix code with html and code together) You can access user control's property directly. Since I...
0
by: gxl034000 | last post by:
Hi, I have been trying to use a .net Forms control in my webpage to open up an application(notepad) on the client. The control works fine when embedded in a windows form, but I keep getting a...
6
by: mgawelek | last post by:
I am doing this in vb.net 2K5 The code below is in a module trying to edit the main form's label control. The error message is: BorderStyle is not a member of System.Windows.Forms.Control. When it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
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...

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.