Visual BASIC...

XionTawa

New Member
I am a learning programmer, I have tried many different languages, and have now started and going on through Visual BASIC... If anyone knows Visual BASIC, I mean really KNOWS it, please reply to this, I have some questions about some things...
 
I am trying to make a button open a new form, I have already made the form, but I cannot find any code on opening to another form or changing to another form, or doing anything with another form for that matter...
 
this is for vb.net, but the syntax is very similar for vb6, but here's one way to do it. IT's not the only way, and there are benefits and drawbacks to doing it this way, but it is code to open another form on a button click event.


Code:
 sub ButtonEventHandler(source as object, e as EventArgs) handles button.click
   ' We dimension a new form
   dim newForm as new FormIWantToOpen
  ' Assign any attributes we need for that form
   with newForm
       .Attributes = AttributeValues
   end with
     
   '  If our existing form can operate without this finishing
   newForm.show

   '  If we hold operation of the existing form until this form is finished
   dim dlgResult as DialogResult
   dlgResult = newForm.ShowDialog

   if dlgResult = DialogResult.Cancel then
      ' Do Something 
   else
      ' Do Something else
   end if 
end sub
does that make sense?
 
Okay, please keep in mind that I am new at this...

---> dim newForm as new FormIWantToOpen <---
How do I define the form I want to open?

---> .Attributes = AttributeValues <---
What do I put at "AttributeValues"
 
you design it as a new class. for example:

Code:
public class MyNewForm
       Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        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.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(402, 49)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(75, 23)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Button1"
        Me.Button1.UseVisualStyleBackColor = True
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(23, 23)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(454, 20)
        Me.TextBox1.TabIndex = 1
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(511, 109)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
end class
the above code will get you a little square box with a blob of text, a textbox and a button. If you're dealing with a Visual IDE such as Visual Studio, the process should be something like "Project->Add Windows Form" to get a new form in the 'design' mode.

The attributes would be something you define. For example, if you want to change the text of the titlebar, you'd use

Code:
myFormInstance.text = "New Title"
You can also define your own attributes via properties.
Code:
public property MyLabelText as string
    get 
       return Label1.text
    end get
    set (value as string)
       Label1.text = value
    end set
end property
and then you'd use that in the same way...
Code:
myFormInstance.MyLabelText = "Cool Beans"
 
Back
Top