Building graphical apps in visual studio

10 min read

Want to create your own programs with graphical interfaces? Darien Graham-Smith explains why it’s easier than you might think

Part 2: Creating graphical interfaces

Two months ago (see issue 349, p44) we introduced the free edition of Microsoft Visual Studio, and walked you through setting up your first program in Visual Basic. What we didn’t touch on is the aspect of Microsoft’s IDE that makes it “visual” and sets it apart from many other development environments – namely, the ability to create rich graphical interfaces for your programs.

In fact, that undersells just how powerful the package is. Visual Studio isn’t just about adding buttons and menus to your code: it allows you to design the GUI first, and then slot in event-driven code to make each element work – a wonderfully intuitive and efficient workflow.

To showcase just how easy it can be, this month we’ll walk through the process of creating a sample graphical application in VB that loads in a text file, sort its lines alphabetically and saves the sorted lines under a new name. And to drive it, we’ll build a rich Windows-native interface using standard buttons, text fields and file requesters.

GETTING STARTED

You can begin the project in the usual way, by opening Visual Studio and selecting “Create a new project”. Then, in the project selector window that opens, choose Windows Forms App, making sure you select the Visual Basic template, rather than the C# one. Windows Forms (or WinForms for short) is a framework that lets you use all the standard Windows GUI elements in your own programs; you could alternatively use the more modern Windows Presentation Foundation (WPF) framework, which gives you more freedom to define your own UI elements using an XML-type language, but it’s easier to get quick results with WinForms.

The next thing is to give our project a name – we’ve called ours FileSorter. You can select .NET 6.0 as your target framework, as we won’t be using any functions introduced in later releases; then hit Create and Visual Studio will set up your project.

In a minute or two you’ll see the main Visual Studio window open on your new project, but in place of the code scaffolding that appeared last time, you should see the Designer view, showing an empty window. This will be the primary (and only) “Form” used by our app, so our next task is to customise it to our needs.

Let’s start by changing the name of the form to something a bit more friendly than

This article is from...

Related Articles

Related Articles