Page 1 of 1

Tutorial(VB.Net) Creating Windows Form App Using Notepad+CommandPrompt Rate Topic: -----

#1 emresutisna  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 21
  • View blog
  • Posts: 80
  • Joined: 14-May 09

Posted 25 November 2012 - 11:23 PM

VB.Net Programming Using Notepad And Command Prompt (Part II) Building Windows Form Application

In this tutorial I'll show you how to create a Windows Form Application. Before reading this tutorial further, it'd better if you see my previous tutorial on http://www.dreaminco...&#entry1111651.
Creating Form
I assume that you've already installed .Net Framework on your machine and ,of course, knowing VB.Net Basic. Let's get started to have some code. Open the Notepad by clicking Start -> Run -> Type Notepad. Then notepad application will be displayed. Then type this code below :
Imports System.Windows.Forms
Partial Class MyForm : Inherits Form
   Private Sub InitializeComponent()
      Me.Text = "My First Example Form"
   End Sub
   Public Sub New()
      InitializeComponent()
   End Sub
   Public Shared Sub Main()
      Dim theForm As New MyForm
      theForm.ShowDialog()
   End Sub
End Class


Then save the file with ".vb" extension. I saved the file With FileName = MyForm.Designer.vb, and ensure you choose Save As Type = AllFiles. In this case I save the file in Folder D:\App.
Explanation of the code :
Partial Class MyForm : Inherits Form
    ...
End Class


To make a Windows Form Application, you have to inherit System.Windows.Forms.Form class. The class declared as “Partial”, because I'll create another Class MyForm as part of them. This partial class will tell you how the Form and Component displayed. And another class will handle all events occurred to the Class Component Object. So, we'll separate the “View” and “Controller” as MVC (Model View Controller) Design Pattern told us.
Private Sub InitializeComponent()
     ...
End Sub


In this case I create a Sub Procedure named InitializeComponent which is used to initialize the component that will be added into the form included the component settings. On the next sample I'll add some component like Label, TextBox, and Button into the Form.
Public Sub New()
     ...
End Sub


The constructor that will call the InitializeComponent procedure. So the Form will be displayed like we describe on InitializeComponent procedure. If you don't know what the “Constructor” is, just googling it :)/>/>.
Public Shared Sub Main()
     ...
End Sub


Sub Main is the main procedure which is the starting point of your application. So, everything you've typed here would be read, compile and execute by the compiler, at startup application, before the others.
How To Compile
open the Command Prompt by clicking Start -> Run -> type cmd then press Enter.
When the Command Prompt's displayed, write down this below code to set the Work Path to be the same where .Net Framework was installed. By default it'll be installed in Folder "C:\Windows\Microsoft.Net\Framework\Vxxxx". Vxxxx is the version of your .Net Framework. In this tutorial I used .Net Framework v4.0, but it'd be running well on the other version.
path=%path%;c:\windows\microsoft.net\framework\v4.0.30319


Then change your directory into the Folder where you saved the File by type this code :
CD /D D:\App


And now it's time to compile it, just write down this code :
VBC /OUT:MyForm /T:winexe MyForm.Designer.vb


If no errors, then run your application by calling the name's of your application.
MyForm.exe


Or just :
MyForm



Adding Component Into Form
To add components into form, we could follow these steps :
1. Declare the component
2. Initialize and sets the component's property value
3. Add the component into the form
Now, let's see the codes. Open MyForm.Designer.vb file that we've created above. And update it to be like these :
Imports System.Windows.Forms
Partial Class MyForm : Inherits Form
   'Component's Declaration
   Friend WithEvents lblFirstName As Label
   Friend WithEvents lblLastName As Label = New Label
   Friend WithEvents txtFirstName As TextBox = New TextBox
   Friend WithEvents txtLastName As TextBox = New TextBox
   Friend WithEvents btnShow As Button = New Button
   Private Sub InitializeComponent()
      Me.Text = "My First Example Form"
      'lblFirstName Setting
      lblFirstName = New Label   'Object Initialization
      lblFirstName.Text = "First Name : " 
      lblFirstName.AutoSize = True 'Set the label into AutoSize
      lblFirstName.Location = New System.Drawing.Point(10,10) 'Set the location/position of the lblFirstName Object relative to the form System.Drawing.Point(x, y)

      'lblLastName Setting
      lblLastName = New Label
      lblLastName.Text = "Last Name : " 
      lblLastName.AutoSize = True
      lblLastName.Location = New System.Drawing.Point(10, 60)

      'txtFirstName Setting
      txtFirstName = New TextBox
      txtFirstName.MaxLength = 50 
      txtFirstName.Size = New System.Drawing.Size(150, 40)
      txtFirstName.Location = New System.Drawing.Point(100, 10)
      
      'txtLastName Setting
      txtLastName = New TextBox
      txtLastName.MaxLength = 50 
      txtLastName.Size = New System.Drawing.Size(150, 40)
      txtLastName.Location = New System.Drawing.Point(100, 60)

      'btnShow Setting
      btnShow = New Button
      btnShow.Text = "&Show" 
      btnShow.Size = New System.Drawing.Size(50, 30)
      btnShow.Location = New System.Drawing.Point(10, 100)

      'Adding the control/component into the Form
      Me.Controls.Add(lblLastName)
      Me.Controls.Add(lblFirstName)
      Me.Controls.Add(txtLastName)
      Me.Controls.Add(txtFirstName)
      Me.Controls.Add(btnShow)
      Me.Size = New System.Drawing.Size(txtLastname.Right + 20, btnShow.Top + 70)
   End Sub
   Public Sub New()
      InitializeComponent()
   End Sub
   Public Shared Sub Main()
      Dim theForm As New MyForm
      theForm.ShowDialog()
   End Sub
End Class


Then save it.
Now to handle btnShow Click event, we'll create an event handler in another file. Create a new file on Notepad :
Imports System.Windows.Forms
Public Class MyForm
  'This is the event handler
 for btnShow.Click
  Private Sub btnShow_Clicked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShow.Click
      MessageBox.Show("Welcome " & txtFirstName.Text & " " & txtLastName.Text,"Welcome")
  End Sub
End Class


Then save it as MyForm.vb in the same folder ( D:\App). Now let's compile it :
VBC /OUT:MyForm /T:winexe MyForm.vb MyForm.Designer.vb


If no errors, then run your application by calling the name's of your application.
MyForm


Hopefully the tutorial's clear enough for you... I'm so sorry if my english's not good enough. Next tutorial we'll see how to display the data from database (Ms.Access or SQL Server). Happy coding bro...

Is This A Good Question/Topic? 2
  • +

Replies To: Tutorial(VB.Net) Creating Windows Form App Using Notepad+CommandPrompt

#2 PAHS  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 27-April 13

Posted 30 April 2013 - 02:27 AM

wow never thought of that -
but there is no point when you
have visual studio now its made %99.99 easy
:sweatdrop:

lucky microsoft invented that or we'd be dead typing up code. :death:
Was This Post Helpful? 0
  • +
  • -

#3 emresutisna  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 21
  • View blog
  • Posts: 80
  • Joined: 14-May 09

Posted 26 May 2013 - 09:45 AM

View PostPAHS, on 30 April 2013 - 02:27 AM, said:

wow never thought of that -
but there is no point when you
have visual studio now its made %99.99 easy
:sweatdrop:/>

lucky microsoft invented that or we'd be dead typing up code. :death:/>

Yes, that's right.
But I think it's a good thing to know 'behind the scene' of the Visual Studio...
So, you could know the concept...
:bigsmile:
Was This Post Helpful? 0
  • +
  • -

#4 Dakry  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-July 14

Posted 19 July 2014 - 11:04 PM

Hi, thanks for the great tutorial.

I'm a newbie in the VB world and I really hope that you could show me how to create WPF from notepad/notepad++ and command prompt if possible.

I'm trying to learn the language without having to resort to Visual Studio.

Thank you very much for your time.

Dakry

Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3806
  • View blog
  • Posts: 13,500
  • Joined: 12-December 12

Posted 20 July 2014 - 02:53 AM

There is a discussion here at SO about the challenge of WPF without using an IDE.

Personally, I wouldn't attempt this completely from scratch. I would at least use VS to initiate the application. You might consider XamlPad2 for writing the XAML, and, as you mention, Notepad++ for the code behind.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1