By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,699 Members | 1,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,699 IT Pros & Developers. It's quick & easy.

Public Shared Form Control

P: n/a
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
Share this Question
Share on Google+
1 Reply

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.