PureSc0pe Posted May 7, 2004 Posted May 7, 2004 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? Quote It's not impossible, it's Inevitable.
Denaes Posted May 7, 2004 Posted May 7, 2004 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 :) Quote
PureSc0pe Posted May 7, 2004 Author Posted May 7, 2004 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() Quote It's not impossible, it's Inevitable.
georgepatotk Posted May 7, 2004 Posted May 7, 2004 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 Quote George C.K. Low
PureSc0pe Posted May 7, 2004 Author Posted May 7, 2004 (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 May 7, 2004 by PureSc0pe Quote It's not impossible, it's Inevitable.
georgepatotk Posted May 7, 2004 Posted May 7, 2004 then do it in this way Public Shadows parentForm as Form1 Quote George C.K. Low
PureSc0pe Posted May 7, 2004 Author Posted May 7, 2004 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. Quote It's not impossible, it's Inevitable.
georgepatotk Posted May 7, 2004 Posted May 7, 2004 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 Quote George C.K. Low
PureSc0pe Posted May 7, 2004 Author Posted May 7, 2004 Does the fact that their both forms and neither one is the actual .exe matter? Quote It's not impossible, it's Inevitable.
georgepatotk Posted May 7, 2004 Posted May 7, 2004 ur startup has to be Form1. that's all does it work?? Quote George C.K. Low
PureSc0pe Posted May 7, 2004 Author Posted May 7, 2004 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. Quote It's not impossible, it's Inevitable.
georgepatotk Posted May 7, 2004 Posted May 7, 2004 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. Quote George C.K. Low
PureSc0pe Posted May 7, 2004 Author Posted May 7, 2004 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() Quote It's not impossible, it's Inevitable.
georgepatotk Posted May 7, 2004 Posted May 7, 2004 zip it and upload. I will fix for you. Quote George C.K. Low
georgepatotk Posted May 7, 2004 Posted May 7, 2004 See this exampleMyFirstApplication.zip Quote George C.K. Low
PureSc0pe Posted May 7, 2004 Author Posted May 7, 2004 (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 May 7, 2004 by PlausiblyDamp Quote It's not impossible, it's Inevitable.
georgepatotk Posted May 7, 2004 Posted May 7, 2004 I got your problem. Give me few minutes. I write an example for you. Quote George C.K. Low
georgepatotk Posted May 7, 2004 Posted May 7, 2004 Your program is nice. Good interface..MyFirstApplication.zip Quote George C.K. Low
PureSc0pe Posted May 7, 2004 Author Posted May 7, 2004 (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 May 7, 2004 by PlausiblyDamp Quote It's not impossible, it's Inevitable.
PureSc0pe Posted May 7, 2004 Author Posted May 7, 2004 (edited) Here's what I added... Edited May 7, 2004 by PureSc0pe Quote It's not impossible, it's Inevitable.
georgepatotk Posted May 7, 2004 Posted May 7, 2004 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. Quote George C.K. Low
PureSc0pe Posted May 7, 2004 Author Posted May 7, 2004 The upload is being removed...Why are executables not allowed? Quote It's not impossible, it's Inevitable.
georgepatotk Posted May 7, 2004 Posted May 7, 2004 casue exe might cause virus.. Quote George C.K. Low
PureSc0pe Posted May 7, 2004 Author Posted May 7, 2004 I see..ok I won't upload .exe anymore.. Anyways, It works! Thanks for all your help! ;) Quote It's not impossible, it's Inevitable.
georgepatotk Posted May 7, 2004 Posted May 7, 2004 Is it working as expected?? Kindly let me know, if it works, then I need to go out. Quote George C.K. Low
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.