Library tutorials & articles

Windows Forms and Controls

The Complete Form Class (ctd.)

Now deep breath it’s time for the Constructor or the New procedure. This runs when a new instance of the form is created.

   Public Sub New()
       MyBase.New()
       Me.cbCancel = New System.Windows.Forms.Button()
       Me.cbAccept = New System.Windows.Forms.Button()
       Me.txtEnteredText = New System.Windows.Forms.TextBox()
       Me.lblEnterText = New System.Windows.Forms.Label()
       Me.SuspendLayout()
       '
       'cbCancel
       '
       Me.cbCancel.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right)
       Me.cbCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
       Me.cbCancel.Location = New System.Drawing.Point(204, 108)
       Me.cbCancel.Name = "cbCancel"
       Me.cbCancel.TabIndex = 3
       Me.cbCancel.Text = "Cancel"
       '
       'cbAccept
       '
       Me.cbAccept.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right)
       Me.cbAccept.Location = New System.Drawing.Point(112, 108)
       Me.cbAccept.Name = "cbAccept"
       Me.cbAccept.TabIndex = 2
       Me.cbAccept.Text = "Accept"
       '
       'txtEnteredText
       '
       Me.txtEnteredText.Anchor = (System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right)
       Me.txtEnteredText.Location = New System.Drawing.Point(132, 24)
       Me.txtEnteredText.Name = "txtEnteredText"
       Me.txtEnteredText.TabIndex = 1
       Me.txtEnteredText.Text = "TextBox1"
       '
       'lblEnterText
       '
       Me.lblEnterText.Location = New System.Drawing.Point(20, 28)
       Me.lblEnterText.Name = "lblEnterText"
       Me.lblEnterText.Size = New System.Drawing.Size(100, 16)
       Me.lblEnterText.TabIndex = 0
       Me.lblEnterText.Text = "Enter Text:"
       Me.lblEnterText.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
       '
       'frmMain
       '
       Me.AcceptButton = Me.cbAccept
       Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
       Me.CancelButton = Me.cbCancel
       Me.ClientSize = New System.Drawing.Size(292, 153)
       Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblEnterText, Me.txtEnteredText, Me.cbAccept,

Me.cbCancel})
       Me.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular,

System.Drawing.GraphicsUnit.Point, CType(0, Byte))
       Me.MinimumSize = New System.Drawing.Size(200, 100)
       Me.Name = "frmMain"
       Me.Text = "Forms and Controls"
       Me.ResumeLayout(False)
   End Sub


A lot of interesting code in there which sets the all the properties of the controls to exactly what we set them to in the VS.Net designer. No other properties are mentioned because they were left at the defaults.

Comments

  1. 01 Aug 2008 at 19:22

     Only 5 years after the last post eh :) Anyway because things may have changed I recommend you look at the microsoft docs on this - http://msdn.microsoft.com/en-us/library/ms229597(VS.80).aspx

  2. 22 Oct 2003 at 16:26

    It may not work with mdi children.

  3. 11 Jul 2003 at 03:26

    I use VB.Net (framework 1.0.3705) on Windows 2000, and I noticed the 'MinimumSize' property doesn't seem to have any effect on my forms (MDIChildren). Does that property really prevent users from resizing a form to a smaller size than the MinimumSize? Any other experiences?


    Thank you,

  4. 01 Jan 1999 at 00:00

    This thread is for discussions of Windows Forms and Controls.

Leave a comment

Sign in or Join us (it's free).

Brian O'Connell Microsoft Certified Applications Developer with 10 years experience developing web based applications using asp, asp.net for a Local Authority in Dublin. Clings to a firm belief that a web applicat...

Related podcasts

  • xpert to Expert: Inside Concurrent Basic (CB)

    "Concurrent Basic extends Visual Basic with stylish asynchronous concurrency constructs derived from the join calculus. Our design advances earlier MSRC work on Polyphonic C#, Comega and the Joins Library. Unlike its C# based predecessors, CB adopts a simple event-like syntax familiar to VB progr...

Want to stay in touch with what's going on? Follow us on twitter!