Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 70,208 times

Contents

Related Categories

Windows Forms and Controls - The Complete Form Class

musician

The Complete Form Class

By now you will have noticed that the code behind the form contains a lot more than just the button events we accessed. In fact it contains everything needed to create what we created using the visual designer. We could have opened notepad, and typed all of it in ourselves, then compiled it and it would have executed just fine. In fact lets do just that but let’s not type it in. We can copy and paste what we need. We don’t need some of the designer specific code created by VS.Net so to be clear here’s what we’ll use:-

First off we need to create our references and declare the form Class


Imports System
Imports System.Windows.Forms
Imports System.Drawing

Public Class frmMain
   Inherits System.Windows.Forms.Form

This declares the form and specifies that it Inherits from the form namespace, i.e. it is a form.

Next up we declare our controls outside of the following procedures


   Friend WithEvents cbCancel As System.Windows.Forms.Button

   Friend WithEvents cbAccept As System.Windows.Forms.Button

   Friend WithEvents txtEnteredText As System.Windows.Forms.TextBox

   Friend WithEvents lblEnterText As System.Windows.Forms.Label

The Friend keyword allows us access to them from the second instance of the form we create. You can use Private if you don’t want to directly access them from inherited forms.

   Shared Sub Main()

       System.Windows.Forms.Application.Run(New frmMain())

   End Sub

This is the Main procedure that the compiler looks for in any project.It’s the first thing that runs when you launch the exe.

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 application must keep it's 3 most important aspects seperate - presentation (external CSS), structure (XHTML) and behavior (external javascript).

Comments

  • Re: [2433] Windows Forms and Controls

    Posted by musician on 01 Aug 2008

     Only 5 years after the last post eh :) Anyway because things may have changed I recommend you look at the microsoft docs on this - Re: [2433] Windows Forms and Controls

    Posted by san08 on 30 Jul 2008

     

    Hi ,
    I tried to do make the exe of my Windows forms project in the way you had suggested , but to no avail. Here is the code of the bat file that i had made.:-

     %windir%\Mi...

  • Posted by musician on 22 Oct 2003

    It may not work with mdi children.

  • Does the Form 'MinimumSize' property really work?

    Posted by ferrant.be on 11 Jul 2003

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