Getting Started with Oxygene for .Net

We will start with .Net console applications. See the thorough documentation of the .Net console. Using Oxygene for .Net within Visual Studio, the IntelliSense facility (achieved with auto-completion pop-ups) makes it easy to see how to:

  • change the screen size;
  • change the colour of the screen and text;
  • output text;
  • input the value of a string variable;
  • input a key combination;
  • output the letter pressed and the modifying key(s);
  • position the output of text with co-ordinates within the window.

The following code achieves all of this. We provide the code first for a Tiny .Net project and then for a .Net Console Application.

namespace DotNetTinyDemo;

interface

implementation

begin
  Console.SetWindowSize(60, 10);
  Console.BackgroundColor := ConsoleColor.Gray;
  Console.Clear();
  Console.ForegroundColor := ConsoleColor.Blue;
  writeLn('Hello World!');
  Console.Beep(500, 1000); //Note of frequency 500/s for 1 s
  Console.ForegroundColor := ConsoleColor.DarkGreen;
  write('Please enter your forename: ');
  var forename : String := Console.ReadLine();
  writeLn('Hello, ' + forename + '. Please press a key combination such as CTRL+J.' );
  var key : ConsoleKeyInfo := Console.ReadKey();
  writeLn('You pressed ' + key.Key + ' with ' + key.Modifiers.ToString());
  Console.SetCursorPosition(20, 6);
  writeLn('Finished!');
  Console.Read();
end.



namespace DotNetConsoleDemo;

interface

type
  ConsoleApp = class
  public
    class method Main(args: array of String);
  end;

implementation

class method ConsoleApp.Main(args: array of String);
var
  forename: String;
begin
  Console.SetWindowSize(60, 10);
  Console.BackgroundColor := ConsoleColor.Gray;
  Console.Clear();
  Console.ForegroundColor := ConsoleColor.Blue;
  Console.WriteLine('Hello World!');
  Console.Beep(500, 1000); //Note of frequency 500/s for 1 s
  Console.ForegroundColor := ConsoleColor.DarkGreen;
  Console.Write('Please enter your forename: ');
  forename := Console.ReadLine();
  Console.WriteLine('Hello, ' + forename + '. Please press a key combination such as CTRL+J.' );
  var key : ConsoleKeyInfo  := Console.ReadKey();
  Console.WriteLine('You pressed ' + key.Key + ' with ' + key.Modifiers.ToString());
  Console.SetCursorPosition(20, 6);
  Console.WriteLine('Finished!');
  Console.Read();
end;

end.

We obtained the following screenshot of the program in action.

Screenshot

Screenshot

See other examples of console programs on the next page.

WinForms Applications for .Net

The RemObjects WinForms samples are:
  • ListBox: a list box with a list box, text box and button. The button has the name &Add. The ampersand before the letter A enables the key combination ALT+a to be an alternative to pressing the button.
  • LocalXMLDataStore: Shows data with a DataGridView and saves it to an XML file. Our Local_XML_File is based on it and shows you exactly how to create the application rather than providing you with the solution.
  • BasicWindowsApp has a button that when pressed shows a "Hello World" message.
  • Dr Bob's Memory Game uses code to create an array of buttons that reveal a randomly generated number when pressed for the first time then hide it shortly after you press another button. Check a button's number by clicking on it again.

WPF Applications for .Net

For those of you wondering whether you should choose WinForms or WPF for your forms-based application, this StackOverflow page is a good place to start looking for answers. WPF has hardware support for graphics and enables sophisticated graphical effects.

The RemObjects WPF samples are:
  • OxygeneLogo: Draws the logo using data stored in a XAML file.
  • PictureViewer: Allows the user to select an image then (reversibly) rotate and/or crop it and/or convert it to black and white.
  • Sorter: Sorts coloured bars of random length into order of increasing size

Practice with our simple WPF demonstration is good preparation for developing a Windows Phone App.

Useful key combinations and mouse clicks

  • Type CTRL+ALT+X for the Toolbox then double click on a component name in the Toolbox to add that component to the form then drag it to the required position.
  • Type F4 to highlight the Properties pane.
  • Type F5 to debug and execute or Ctrl+Shift+B to build the solution without running it.
  • Type Ctrl+Shift+N for new project.
  • Type Ctrl+Shift+S to save all project files.
  • If you lose the designer view, right click inside Main.pas and select the top menu item View Designer.
Programming - a skill for life!

Getting Started, Links and other resources