Wrox Programmer Forums
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 19th, 2003, 02:38 AM
Registered User
 
Join Date: Jun 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to aldwincusi
Default Forms?

before this was easy in VB6, I have two windows forms Form1 and Form2 each has a button control, How will I change the text property and disabled the button in Form1 during run time by clicking on the button in Form2, can anyone give me a sample code thnx

HEY_HEY
 
Old June 21st, 2003, 09:12 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Form 1 and Form 2 are both objects.

Form 1 is shown. That spawns Form 2- this way it has a reference to the Form2 object.

When the click event is fired- form 1 can detect it and perform an action...



Hal Levy
NOT a Wiley/Wrox Employee- Got a job for me?
 
Old June 30th, 2003, 12:33 AM
Registered User
 
Join Date: Jun 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to UberDeveloper5150
Default

Ok well Your question wasn't really clear to me but I did what I "THINK" you were getting at. I'm assuming that you are using VB.NET so Here's what I did:

Create a project with 2 forms, "FORM1" and "FORM2"
Create a Module called "MODULE1"

Put this is module1:

     'Create an instance of form2
      Public frmTwo as new Form2

THATS it for module1 now in the Form1_Load event put:
      frmTwo.Show

AND in the form1, Button1_Click event put:

      frmTwo.Text = "HELLO THERE!!!"
      frmTwo.Button1.Enabled = False

When you start the program forms 1 and 2 will be displayed on the screen when you click Button1 on form1 the Text Property of form2 is changed and the button on form2 is disabled. In VB6 you used to be able to access controls on another form by just preceeding the control name with the form name. But in VB.NET you have to create an instance of the second form and then use the instance to access controls on the second form...here is the entire code:




Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.
    'Do not modify it using the code editor.
    Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(208, 116)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Button1"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(516, 418)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        frmTwo.Text = "Hello There!"
        frmTwo.Button1.Enabled = False

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        frmTwo.Show()
    End Sub
End Class




Module Module1
    Public frmTwo As New Form2
End Module








Tim
Uber Development God
[email protected]





Similar Threads
Thread Thread Starter Forum Replies Last Post
Forms and Sub forms Mink Access 1 December 1st, 2004 08:38 AM
Opening forms from other forms Paulsh Access VBA 1 September 30th, 2004 06:54 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.