Startsidan  ▸  Texter  ▸  Teknikblogg

Anders Hesselbom

Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.

The stamping program

2010-01-01

To start this year and decennium, I have dug up my old Windows Forms control for command line interfacing with a user in a Windows environment, a control that I still think allows the programmer to accomplish complex interfacing with hardly any coding at all.

This program consist of one form only, and the only added control is the CLI control. The name of the CLI control instance is simply Cli1. I have loaded four images as project resources; a background image and three different colored icons. One is red, one is blue and one is green.

Click on the image to view it in full size.

This is how the program works: Type Red, Green or Blue to select which color you want to “draw” with. Click on an empty space on the CLI control to place a red, green or blue symbol. Click on an existing symbol to remove it. The complete source code for this:

Public Class Form1

    Private Enum Colors
        None
        Red
        Green
        Blue
    End Enum

    Private CurrentColor As Colors = Colors.None

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Cli1.BackgroundImage = My.Resources.Background
        Cli1.WriteLine("Type Red, Green or Blue. Then click!")
    End Sub

    Private Sub Cli1_Click(ByVal Source As Object, _
    ByVal PixelX As Integer, ByVal PixelY As Integer, ByVal CharX As Integer, ByVal CharY As Integer) _
    Handles Cli1.Click
        'What symbol did the user click on?
        Dim S As CLIControl.GraphicalElement = Cli1.GraphicalElements.GetElement(PixelX, PixelY)
        'If any, remove it. Else add a new one.
        If S Is Nothing Then
            'Add a symbol.
            Select Case Me.CurrentColor
                Case Colors.Red
                    Cli1.GraphicalElements.Add(New CLIControl.Picture("", _
                    My.Resources.Circle_Red, PixelX - 16, PixelY - 16))
                Case Colors.Green
                    Cli1.GraphicalElements.Add(New CLIControl.Picture("", _
                    My.Resources.Circle_Green, PixelX - 16, PixelY - 16))
                Case Colors.Blue
                    Cli1.GraphicalElements.Add(New CLIControl.Picture("", _
                    My.Resources.Circle_Blue, PixelX - 16, PixelY - 16))
            End Select
        Else
            'Remove a symbol.
            Cli1.GraphicalElements.Remove(S)
        End If
    End Sub

    Private Sub Cli1_UserTyped(ByVal Source As Object, ByVal Command As String) Handles Cli1.UserTyped
        If Not Command = "" Then
            Select Case Command.ToLower()
                Case "red"
                    Me.CurrentColor = Colors.Red
                Case "green"
                    Me.CurrentColor = Colors.Green
                Case "blue"
                    Me.CurrentColor = Colors.Blue
                Case Else
                    Cli1.WriteLine("Nah!")
            End Select
        End If
    End Sub

End Class

The CLI control can be downloaded from this page, and this program (compiled) is located here.

Categories: Microsoft .NET

Tags: CLIControl

Leave a Reply

Your email address will not be published. Required fields are marked *



En kopp kaffe!

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!

Bjud på en kopp kaffe!

Om...

Kontaktuppgifter, med mera, finns här.

Följ mig

Twitter Instagram
GitHub RSS

Public Service

Folkbildning om public service.

Hem   |   linktr.ee/hesselbom   |   winsoft.se   |   80tal.se   |   Filmtips