Posts Tagged ‘Visual Studio’

C# WPF programming / my other side

October 21, 2019 Leave a comment

As well as antennas and radio I am also quite keen on coding/programming in C# for mainly Windows applications.  I started writing programs in the 1980’s using Commodore BASIC and moved on from there.  A few years ago (about 10) I picked up where I left off and started using Visual C# in Visual Studio.  Funnily, although I started out with BASIC, I just couldn’t get on with Visual Basic – a feeling I hear echoed amongst many of my friends and contacts – so I gave C# a go.

I started like most with the standard “Hello World” program:-

  • static void Main(string[] args)
  • {
    • Console.Writeline(“Hello World”);
  •  {

and then moved on to Windows Forms programming which was quite easy and self explanatory. Using Windows XP and Windows 7 (never touched Vista) Windows Forms were great and I created many small but useful programs, some of which I published through the Microsoft app store.  Then with the advent of Windows 8 Windows Store apps were more for the Windows Phone which, unfortunately was too late to the already flooded smartphone market and was later withdrawn.  Also around this time, I moved from using Windows Forms to using WPF in Visual Studio 2012.  What a difference! Gone were the square regimental blocks used in WinForms and suddenly transition between pages and windows was much more fluid and reasonable animation was possible.  However, it did mean also having to learn XAML.

WinFormsSample Windows Forms layout in VS2017

WPFSample.JPG WPF layout in VS2017, note the XAML beneath the design screen.

Then Windows 10 happened.  With Windows 10 the Windows Store became more difficult -apps had to be written in UWP(Universal Windows Protocol) format.  An absolute nightmare for most developers.  This was a much stricter protocol with limitations on what was allowed and , due to the many different form factors including PC Desktop, tablet, Phone, etc, it need to be able to resize without truncation.  So what now for all of us who had been happily writing software in WinForms or WPF?  Did this mean that we would have to learn UWP coding?

UWPSample UWP Layout in VS2017

Not at all it turns out.  Thankfully, if you upgrade to Visual Studio 2019 (even the Community Version) you can write your desktop apps using WPF in order to tweak them and perfect them ready for uploading to the Windows Store.  However, before you can you must first right click on the solution and add new project.  This should be a UWP blank app. There is no need to write any code for this project, just right click on the project and associate it with the app you have created in WPF.  Once you have done this right click on the UWP project that you have added and scroll down to publish and then create Windows Store App Package.  This will create a package that can be uploaded to the Windows Store (.appxupload, appxbundle, etc).

Of course, in all samples above, the result is the same, the message “Hello World” is displayed in the screen. However, in the first, console project the command to do so is

“Console.Writeline(“Hello World”);

in the Windows Form and WPF the command is

“MessageBox.Show(“Hello World”);

and in the UWP app the command is

“MessageDialog msg = new MessageDialog(“Hello World”);

Showing how each of the different packages differ in their command format.

Visual Studio 2012 vs what came before

I started off, many years ago, programming in Commodore BASIC (Vic 20, C64) and then progressed onto GWBASIC and such before delving into C as a programming language. I first used Borland C and then moved onto Borland Turbo C. This gives a little bit of a background of my programming history.

I took a break for some years as other things got in the way and then took it up again with the advent of Visual Studio 2005. This was a little different as it involved a little object oriented programmingand something called C# that was a new language to me. The thing with C# is that it replaces the traditional C language and adds Windows forms as well as the more traditional console type execution. The fact that the forms were available predefined within the SDK also made programming somewhat easier and the end product more user friendly with a half decent GUI.

In 2007/8 a new beast was released called Visual Studio 2008. this time the new version of Visual C# included LINQ or Language-Integrated Query.  this enabled direct integration with the .NET Framework collections, SQL Server databases, ADO.NET Datasets, and XML documents, enabling the creation of greater databases and easily shared routines across the MSDN .NET framework.  It also introduced the ability to adjust the properties of any given object using the associated XAML code.

I gave the 2010 version of Visual Studio a miss for various reasons and the next update I got was the new Visual Studio 2012.  As a rule I use the Express version until I decide to go out and exchange hard cash for a professional or ultimate version.  The first thing I noticed was that whereas previous issues had been a single SDK, when I downloaded the VS2012 Express from I was only able to see templates for metro style apps for the Windows8 Store and no generic Windows form apps or WPF templates.  I put out a general query through twitter and discovered that I actually needed to download a second SDK – Visual Studio 2012 Express for Desktop.  Anyway, on doing this I found that I now had all the usual generic templates albeit spread over 2 SDK’s.  Also it is worth noting that Visual Basic 2012 is now a full Object Oriented Language and now has much the same power as C# or C++.  Not quite the same as previous versions of Visual Basic so if you do update from VB5.0 or whatever you have quite a learning curve to progress through.

Anyway, I do like Visual Studio 2012 now I am getting the hang of it and may make some software available either as freeware or shareware at some stage before going on to full professional development again.

Thank you for taking the time to read this.