Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
What would I do to execute a command into a diff form? When I click a button on form2, I need it to execute that on form1..Any Ideas?
It's not impossible, it's Inevitable.
Posted

You mean you want to create a method on one form and make it accessable on another?

 

It would have to be a public sub/function and I believe the form you want to run it off of would have to be instantiated (formX = new formX).

 

Generally if you have something you want accessable across forms, it's best to create a class for both forms to access.

 

Then again after having a form's code raging upward of 2000 lines of code, you quickly learn to love encapsulating code in classes :)

Posted

When I click a button on form2, I need it to do this on form1:

 

ComboBox1.DataSource = ini.GetSectionNames()

 

 

 

Something like this?

 

Form1 = New Form2

ComboBox1.DataSource = ini.GetSectionNames()

It's not impossible, it's Inevitable.
Posted

in form1

 

private sub btnNextForm_Click(....) btnNextForm.Click
  dim frm2 as new Form2
  frm2.parentForm = me
  frm2.show
end sub

public sub ToBeExecute()
  'do whatever you like here
End Dub

 

 

in form2

 

Public Shadows parentForm as Form

Private Sub btnCallFromForm1_Click(...) btnCallFromForm1.Click
  parentForm.ToBeExecute()
End Sub

George C.K. Low

Posted (edited)

In form1, I put:

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Dim frm2 As New Form2
       frm2.ParentForm = Me
       frm2.Show()
   End Sub

   Public Sub ToBeExecute()
       ComboBox1.DataSource = ini.GetSectionNames()
   End Sub

 

 

In form2, I put:

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       ParentForm.ToBeExecute()
   End Sub

 

There are no errors in form1, however, form2 says "ParentForm.ToBeExecute()" is an error...It's not a member of System.Windows.Forms.Form

 

And yes I defined "Public Shadows ParentForm As Form"

Edited by PureSc0pe
It's not impossible, it's Inevitable.
Posted
then do it in this way

Public Shadows parentForm as Form1

 

That got rid of the coding errors, however, when I run it, it highlights the following: "ParentForm.ToBeExecute()"

 

Error: An unhandled exception of type 'System.NullReferenceException' occurred in PureSc0pe's Program.exe

 

Additional information: Object reference not set to an instance of an object.

It's not impossible, it's Inevitable.
Posted

I think you must be running the program directly from Form2

 

you got to run it from Form1.

the form1 link to form2

let the Form1 set 'parentForm = Me' before you run the procedure

George C.K. Low

Posted
ur startup has to be Form1. that's all

does it work??

 

I am trying to execute a command on a form from another form...It's not using the startup form.

It's not impossible, it's Inevitable.
Posted

OK then.

you got to do this.

 

dim frm1 as new Form1

frm1.ToBeExecute()

 

I think your knowledge on OO is still weak. Just read more article or books will do.

 

Update me wheter this had cleared your doubt.

George C.K. Low

Posted

It runs everything, but it doesn't execute the command...

 

In the form it needs to be executed in i have this:

 

Public Sub ToBeExecute()

ComboBox1.DataSource = ini.GetSectionNames()

End Sub

 

In the form the button is pressed to execute the command:

 

Public Shadows parentForm As Form1

 

Form2_Load

ComboBox1.DataSource = ini.GetSectionNames()

Dim frm2 As New Form2

frm2.parentForm = Me

frm2.Show()

 

Buton Click

dim frm1 as new Form1

frm1.ToBeExecute()

It's not impossible, it's Inevitable.
Posted (edited)
Form2.vb is where you click the button and it executes the command on TS.vb What you enter into Form2.vb is written onto settings.ini I need combo1.text to update when you add a server to the list... ComboBox1.DataSource = ini.GetSectionNames() gets the names from the ini file.. Edited by PlausiblyDamp
It's not impossible, it's Inevitable.
Posted (edited)

Thanks :D

 

But were you able to get it to work on my program? I changed mine to what you had and it's still not working... :(

Edited by PlausiblyDamp
It's not impossible, it's Inevitable.
Posted

    Private Sub TS_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       ComboBox1.DataSource = ini.GetSectionNames()
       f2 = Me
       f3 = New Form2
   End Sub

 

Congratulation! it is done.

George C.K. Low

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...