DR00ME Posted March 7, 2004 Posted March 7, 2004 How do I make a label Public shared so I could use it from another class....? Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
Leaders dynamic_sysop Posted March 7, 2004 Leaders Posted March 7, 2004 in your Class ... [color=Blue]Public Class[/color] Class1 [color=Blue]Public[/color] frm [color=Blue]As[/color] Form1 [color=Blue]Public[/color] [color=Blue]Sub New[/color]([color=Blue]ByVal[/color] f [color=Blue]As[/color] Form1) frm = f [color=Blue]End Sub[/color] [color=Blue]Public Sub[/color] setLabel([color=Blue]ByVal[/color] strText [color=Blue]As String[/color]) frm.Label1.Text = strText [color=Blue]End Sub[/color] [color=Blue]End Class[/color] in your form ( containing the Label ) ... [color=Blue]Private Sub[/color] Button1_Click([color=Blue]ByVal[/color] sender [color=Blue]As[/color] System.Object, [color=Blue]ByVal[/color] e [color=Blue]As[/color] System.EventArgs) [color=Blue]Handles[/color] Button1.Click [color=Blue]Dim[/color] cls [color=Blue]As New[/color] Class1([color=Blue]Me[/color]) cls.setLabel("test 123") [color=Blue]End Sub[/color] Quote
DR00ME Posted March 7, 2004 Author Posted March 7, 2004 oh yeah thx very much... Im bad with these "new" statements... Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
DR00ME Posted March 7, 2004 Author Posted March 7, 2004 Public frm As Form1 Public Sub New(ByVal f As Form1) frm = f End Sub Public Sub setLabel(ByVal strText As String) frm.Label1.Text = strText End Sub it doesnt let me write frm.label1 because there isnt such a thing as frm because it is not set ? Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
DR00ME Posted March 7, 2004 Author Posted March 7, 2004 Actually I mean frm. cant find the label... Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
Leaders dynamic_sysop Posted March 7, 2004 Leaders Posted March 7, 2004 you need the label ( named correctly ) to be on your calling form , ie: if you are calling your class from Form1 , the label must be on form1. Quote
DR00ME Posted March 8, 2004 Author Posted March 8, 2004 Ok, I think you misunderstood me ? I mean I want to control class1 labels from my class2 sub programs...without inheriting the whole class1 Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
DR00ME Posted March 8, 2004 Author Posted March 8, 2004 seems like you have really tested it... and i got it to work with empty project.... I have to think how to modify it for my own classes... I think I did something wrong because my class names are a bit dodgy... Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.