Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
Can VB enter text into a textbox on another window? if not can it run a different program that is either built in or in the same folder to enter info into the textbox? :confused:
Posted
Declare your form as public inside a module and set its controls from any other form.
Dream as if you'll live forever, live as if you'll die today
  • Leaders
Posted

if you have a textbox on Form1 and you want to change it's text from Form2 , you can do this :

 

at top of Form2 , modify the Public Sub New()

Public Class Form2

   Inherits System.Windows.Forms.Form
   Public frm As Form1 '/// first make a public reference to your form ( eg: Form1 )

#Region " Windows Form Designer generated code "

   Public Sub New(ByVal myForm As Form) '/// make myForm as a Form ( not Form1 )
       MyBase.New()
       'This call is required by the Windows Form Designer.
       InitializeComponent()
       frm = myForm '/// initialize the instance of the form as Form1.
       'Add any initialization after the InitializeComponent() call

   End Sub

 

from a command button on Form2 :

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       frm.TextBox1.Text = "i am some text from form2 to form1's textbox!"

   End Sub

 

to show the Form2 , do this in Form1 :

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

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