Visual Basic 2010 Textbox Based Simple Edit Program
By Stephen Bucaro
Visual Basic is a Visual Programming Environment for developing Windows applications.
This means that to design the application's interface you simply drag controls like buttons,
text boxes, check boxes, and so on from a Toolbox, drop them on a form, reposition and re-size
them with the mouse, and edit their properties.
Visual Basic is very popular because it's based on the Basic programming language, which is very
easy for inexperienced programmers to understand. Another reason for Visual Basic's popularity is
that Visual Basic Express edition can be downloaded for free at
microsoft.com⁄express⁄Downloads⁄.
In this example, you'll create a very simple text editor that uses the Textbox control.
This example is for beginners so I'll go step-by-step through the process of developing the program.
However, if you have absolutely no experience with Visual Basic 2010 (VB), you should read
one of the beginners articles on this site, like
Your First Visual Basic 2010 Express Program.
Every VB Project follows three basic steps: 1. Design the visual interface, 2. Write the code,
3. Debug the code. We could also include a fourth step: create the installation file containing
the application and redistributable resources. But we won't be performing that fourth step in this example.
1. Start a New Project... | Windows Forms Application.
2. Edit Form1's properties as shown below.
(Name) | Main |
FormBorderStyle | Fixed Single |
MaximizeBox | False |
Size | 600,400 |
Text | Simple Edit |
o When setting properties, make sure the Form or Control who's properties
you're setting is selected. The Properties window always displays the properties of
the selected object.
o If you can't find a VB application window that you need, you can always select
Window | Reset Window Layout in VB's main menu. This will restore the environment to
the default window layout.
3. Add a Textbox control and two Button controls to the form as shown below.
o To add a control to the form you can drag-and-drop it from the Toolbox, or you can
just double-click it in the Toolbox, it will appear on the form where you can use the mouse
pointer to reposition and re-size the control on the form.
4. To size the Textbox as shown , set the Textbox Multiline property to True.
Set the first button's (Name) property to btnOpen and set its Text property
to Open File.
Set the second button's (Name) property to btnSave and its Text property
to Save File.
5. Near the bottom of the Toolbox, find the OpenFileDialog and the SaveFileDialog.
double-click to select one of each of these controls.
o Because the OpenFileDialog and the SaveFileDialog are not visual components
on the form they are displayed below form in the design window.
o The OpenFileDialog and the SaveFileDialog don't actually open or save files,
they only allow the user to navigate the file system and enter or select a filename. You have
to add the code to your form to actually open or save files .
o Because unpredictable events can cause a PC to shut down or stop working, it's wise to occasionally
save your project. To save the changes you've made so far, in VB's main menu select File | Save All.
The Save Project dialog box will appear displaying the name of the project and the location where
it will be saved. Click on the [Save] button.
|