473,396 Members | 2,026 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,396 software developers and data experts.

Accessing controls on another form

Background: I have a windows form called 'frmMain'. On this form, I have a
LABEL control called 'lblWorkStatus', and it's property is set to PUBLIC.

On another form, I have a process that checks on the status of a project
that our company is working on. Programmatically, if the status changes, I
want to relay that information to the 'lblWorkStatus' control on the main
form.

My code looks like this:

frmMain fmain = new frmMain();
fmain.lblWorkStatus.Text = "Status: Project Postponed";

The control never gets updated. Am I doing something wrong?
Thanks,
Aug 31 '07 #1
3 1789
vbtrying wrote:
[...]
My code looks like this:

frmMain fmain = new frmMain();
fmain.lblWorkStatus.Text = "Status: Project Postponed";

The control never gets updated. Am I doing something wrong?
Hard to say for sure. But based on the code you posted, it seems you
are creating a new instance of frmMain, setting that instance's
control's Text property, and then doing nothing else.

You need to at a minimum show the instance of frmMain you created. If
you meant to set the Text property on the control in an already-existing
instance of frmMain, you need to get that instance instead, rather than
creating a new one.

Pete
Aug 31 '07 #2
It is an already existing instance. How to I determine the instance? I see
that by using the NEW keyword, it is making a new instance.

If I try using the "frmMain.lblWorkStatus.Text" syntax without creating a
new instance, I dont see the lblWorkStatus control using the . sequence

I'm lost of this one ... thanks for the help !

"Peter Duniho" wrote:
vbtrying wrote:
[...]
My code looks like this:

frmMain fmain = new frmMain();
fmain.lblWorkStatus.Text = "Status: Project Postponed";

The control never gets updated. Am I doing something wrong?

Hard to say for sure. But based on the code you posted, it seems you
are creating a new instance of frmMain, setting that instance's
control's Text property, and then doing nothing else.

You need to at a minimum show the instance of frmMain you created. If
you meant to set the Text property on the control in an already-existing
instance of frmMain, you need to get that instance instead, rather than
creating a new one.

Pete
Aug 31 '07 #3
On Aug 30, 10:00 pm, vbtrying <vbtry...@discussions.microsoft.com>
wrote:
It is an already existing instance. How to I determine the instance? I see
that by using the NEW keyword, it is making a new instance.

If I try using the "frmMain.lblWorkStatus.Text" syntax without creating a
new instance, I dont see the lblWorkStatus control using the . sequence

I'm lost of this one ... thanks for the help !
In child form, define this
public frmMain myParentForm;

While creating the child form, set the parent form.

//Creating child
FrmChild frmChild = new FrmChild();
//Set Parent
frmChild.MyParentForm = this;

Now you can access the mainfrm using
frmChild.myParentFrom.lblWorkStatus.Text

But you wont be able to code it this way, as parent is created in a
different thread. You need to have a method on parent form for
updating the status, and invoke that method from your child form.

Create a method in parent:
public void UpdateStatus(string message)
{
this.lblWorkStatus.Text = message;
}

define a delegate in child form:

private delegate void delegateUpdate(string message);

and for updating the status:

delegateUpdate RelayMessage=new
delegateUpdate(this.myParentFrom.UpdateStatus)
invoke(RelayMessage,new object[] {message});

Aug 31 '07 #4

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

Similar topics

3
by: Tom Meuzelaar | last post by:
Hello: I'm using VB6 in VS enterprise. I'd like to place an HTML form inside a VB container, have a user fill out the form information, click a submit button, and then have the program capture...
4
by: Jim Heavey | last post by:
Hello, I have created a form which I intend to use a a dialog box. It has a few controls on that form and I changed the properties of those controls to "public" with the idea that I could access...
4
by: Andrew Diabo | last post by:
I have 2 forms (Form1 and Form2) in my C# project. I created the second form from the main form like so: Fom2 aForm = new Form2(); aForm.ShowDialog(); How do I access the properties of a...
3
by: Tim Fitzgerald | last post by:
Hello all, I have no problem accessing another form in my app.. however, when I try to access a ListView on a different form, I come up empty... Basically, Dim pForm As New frmMain Dim iCount...
0
by: Geraldine Hobley | last post by:
Hello I have a problem whereby I have a treeview control on one form called projecttree and I wish to clea the nodes from this control in another form The form that contains the treeview is...
5
by: RSH | last post by:
I havent been able to set a property from another class with out getting some sort of error. Can someone please tell me what I'm doing wrong here? Public Class Form1
4
by: raj_genius | last post by:
I hav two queries, whc are as follows: FIRSTLY: is it possible to access the controls(by name) of a parent form(MDI) from its child forms??if yes then how??plzz provide a coded example in VB if...
8
by: colmkav | last post by:
Hi, could someone tell me how I can check whether a database is open by name eg something like db("mydbname")
3
by: M K | last post by:
I have 2 classes. One where the form resides and I created another one for all the database stuff. after i get data from the db i want to be able to update the form. I have the namespace of...
2
by: San24 | last post by:
Guys, Let me explain the application I have - Form > Main Tab Control > Main Tab Page > User Control > Sub Tab Control > Sub Tab Page > User Control > Contols/Text Box. Form - The main...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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...
0
agi2029
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,...

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.