473,387 Members | 1,864 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,387 software developers and data experts.

Public Shared Form Control

RSH
Hi,

I have a situation where I have a Windows Form and I have 2 classes defined
in the code, the primary form and a class that I got from the internet. I
have a label in the form that I would like the 2nd class to write to...so I
declared the label as "Public Shared". Which worked, I can write to it.
But I get an error when closing down visual studio, it says the label was
never declared and when i reopen Visual the label has disappeared off of the
form. When I go to put it back I get an error saying it already exists.

What is going on here? I simply need to write text to a label in the form
from a class.

Structure:

Public Class DTSConvertor725

Inherits System.Windows.Forms.Form

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog

Friend WithEvents TestSQLConnection As System.Windows.Forms.Button

Public Shared label1 As System.Windows.Forms.Label

<code goes here>

End Class


Public Class PackageEventsSink

Inherits System.Windows.Forms.Form

Implements DTS.PackageEvents

Public fParentForm As DTSConvertor725

Overridable Overloads Sub OnStart(ByVal EventSource As String) _

Implements DTS.PackageEvents.OnStart

Console.WriteLine("START in {0}", EventSource)

fParentForm.StepCount = fParentForm.StepCount + 1

fParentForm.label1.Text = "Step " & fParentForm.StepCount & " " &
EventSource

System.Windows.Forms.Application.DoEvents()

End Sub

End Class
Nov 21 '05 #1
1 3222
"RSH" <wa*************@yahoo.com> schrieb
Hi,

I have a situation where I have a Windows Form and I have 2 classes
defined in the code, the primary form and a class that I got from
the internet. I have a label in the form that I would like the 2nd
class to write to...so I declared the label as "Public Shared". Which
worked, I can write to it. But I get an error when closing
down visual studio, it says the label was never declared and when i
reopen Visual the label has disappeared off of the form. When I go
to put it back I get an error saying it already exists.

What is going on here? I simply need to write text to a label in
the form from a class.

A label can not be shared - at least not if you use the designer. It doesn't
make sense. Without creating a Form, it wouldn't be visible anyway.

If you want to access an object, you need a reference. If you don't have
one, make it available. It depends on the circumstances how to do this.
Usual approach is pass the reference to the class that needs the reference.
Armin

Nov 21 '05 #2

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

Similar topics

2
by: Ian B | last post by:
This is a basic question for anyone who knows what they're doing with web server admin so hopefully someone will be able to assist me here!... I have a www based asp.net application which allows...
6
by: darrel | last post by:
I'm still not quite sure how best to handle the passing of data between controls. This is a method I'm using at the moment: I have an XML file that contains a variety of page-centric...
0
by: VB Programmer | last post by:
I wanted to access some properties of a panel control that is on a different form. So, I went to the (Declarations) section of my main form (the form with the panel) and changed the panel (called...
9
by: Rudy | last post by:
Hello All! I'm a little confused on Public Class or Modules. Say I have a this on form "A" Public Sub Subtract() Dim Invoice As Decimal Dim Wage As Decimal Static PO As Decimal Invoice =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
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,...

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.