Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Experts*
Posted

If you start your program from sub main just declare your form as public beofre starting it. If you start from a form you can either pass the instance around through constructors or make some public variable in a module.

To pass instance through constructors:

Let say Form1 is your main form and Form2 is some other form.

In Form2:

Dim formmain as Form 'some variable to hold the instance
'pass in the form instance
Public Sub New(byval mainform as form1) 'get the variable that 
'contains the form's instance
MyBase.New
InitializeComponents()
formmain = mainform 'get the instance to a variable that
'can be used in this throughout this class
End Sub

'in some other sub

public sub DoSomething()
formmain.sometextbox.text = "some text" 'use the variable with
'that instance to access the textbox on the form.
end sub

You can do that, or declare a public variable.

Posted

Another solution is to make a public property in your main form to access private members.

 

public string SomeText {
  get {
     return Textbox1.Text;
  }
  set {
     Textbox1.Text = value;
  }
}

 

You can then use it as such in other forms;

 

MainForm.SomeText = "Hello there.";
string str = MainForm.SomeText;
Console.Writeline(str + "-" + MainForm.SomeText);

 

With this solution you don't have to worry about changing code in multiple forms if you happen to change the textbox to another control (a label for example) or rename the textbox for some reason, all you'd have to do is change the code in the main form and not have to worry about breaking the code in others.

Gamer extraordinaire. Programmer wannabe.
Posted

in lienform

dim mainframe as mainframe
private sub button1_click(byval sender as system.object,byval e as system.eventargs)hangles button1.click
mainframe.text1.text = "HY"
me.close()
end sub

 

Error : additional information: object reference not set to an instance of an object.

 

What can I do??

 

The mainframe is already loadded and lienform is loadded by mainframe.

 

 

 

Think you

ComCrack

[ () /\/\ [ |\ /\ [ |<
Posted (edited)

There is my project:

 

[edit] Attachment removed - please don't post binaries [/edit]

Edited by divil
[ () /\/\ [ |\ /\ [ |<
  • *Experts*
Posted

I changed your LienForm file and in the MainFrame change your Lien form declaration to:

Dim LienForm As New LienForm(me)

It will pass in the reference to your form and then use it to access the textbox.

lienform.vb

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...