<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WinSoft.se &#187; CLIControl</title>
	<atom:link href="http://www.winsoft.se/tag/clicontrol/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.winsoft.se</link>
	<description>Development with focus on Visual Basic .NET</description>
	<lastBuildDate>Thu, 26 Jan 2012 19:28:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Word wrapping</title>
		<link>http://www.winsoft.se/2010/10/word-wrapping/</link>
		<comments>http://www.winsoft.se/2010/10/word-wrapping/#comments</comments>
		<pubDate>Wed, 27 Oct 2010 19:47:25 +0000</pubDate>
		<dc:creator>Anders Hesselbom</dc:creator>
				<category><![CDATA[Microsoft .NET]]></category>
		<category><![CDATA[CLIControl]]></category>

		<guid isPermaLink="false">http://www.winsoft.se/?p=1474</guid>
		<description><![CDATA[One limitation of the Command Line Interface control, is that it could only display as long strings of text as it&#8217;s width in characters at a time. The following text would be cut off just after &#8220;I like the way&#8221;: Dim S As New System.Text.StringBuilder() S.Append("Just gonna stand there and watch me burn ") S.Append("That's [...]]]></description>
			<content:encoded><![CDATA[<p>One limitation of the Command Line Interface control, is that it could only display as long strings of text as it&#8217;s width in characters at a time. The following text would be cut off just after &#8220;I like the way&#8221;:</p>
<pre class="csharpcode">
<span class="kwrd">Dim</span> S <span class="kwrd">As</span> <span class="kwrd">New</span> System.Text.StringBuilder()
S.Append(<span class="str">"Just gonna stand there and watch me burn "</span>)
S.Append(<span class="str">"That's all right because I like the way it hurts "</span>)
S.Append(<span class="str">"Just gonna stand there and hear me cry "</span>)
S.Append(<span class="str">"That's all right because I love the way you lie "</span>)
S.Append(<span class="str">"I love the way you lie"</span>)
Cli1.WriteLines(S.ToString())</pre>
<p>Now, the WriteLines function also takes a boolean, and when True, the text will be devided into several lines, without breaking any words.</p>
<pre class="csharpcode">Cli1.WriteLines(True, S.ToString())</pre>
<p>The CLI Control can be downloaded from <a href="http://www.winsoft.se/net-controls/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.winsoft.se/2010/10/word-wrapping/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The stamping program</title>
		<link>http://www.winsoft.se/2010/01/the-stamping-program/</link>
		<comments>http://www.winsoft.se/2010/01/the-stamping-program/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 11:48:49 +0000</pubDate>
		<dc:creator>Anders Hesselbom</dc:creator>
				<category><![CDATA[Microsoft .NET]]></category>
		<category><![CDATA[CLIControl]]></category>

		<guid isPermaLink="false">http://www.winsoft.se/?p=814</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>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.</p>
<p>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 <strong>Cli1</strong>. 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.</p>
<p><a href="http://imghost.winsoft.se/upload/402141262346015cli.jpg" target="_blank"><img class="alignnone" src="http://imghost.winsoft.se/upload/402141262346015cli.jpg" alt="" width="391" height="206" /></a></p>
<p><em>Click on the image to view it in full size.</em></p>
<p>This is how the program works: Type Red, Green or Blue to select which color you want to &#8220;draw&#8221; 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:</p>
<pre class="csharpcode">
<span class="kwrd">Public</span> <span class="kwrd">Class</span> Form1

    <span class="kwrd">Private</span> <span class="kwrd">Enum</span> Colors
        None
        Red
        Green
        Blue
    <span class="kwrd">End</span> <span class="kwrd">Enum</span>

    <span class="kwrd">Private</span> CurrentColor <span class="kwrd">As</span> Colors = Colors.None

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

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

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

<span class="kwrd">End</span> <span class="kwrd">Class</span>
</pre>
<p>The CLI control can be downloaded from <a href="http://www.winsoft.se/net-controls/">this page</a>, and this program (compiled) is located <a href="http://www.winsoft.se/files/Stamping.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.winsoft.se/2010/01/the-stamping-program/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First CLI control demo</title>
		<link>http://www.winsoft.se/2009/07/first-cli-control-demo/</link>
		<comments>http://www.winsoft.se/2009/07/first-cli-control-demo/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 09:37:39 +0000</pubDate>
		<dc:creator>Anders Hesselbom</dc:creator>
				<category><![CDATA[Microsoft .NET]]></category>
		<category><![CDATA[CLIControl]]></category>

		<guid isPermaLink="false">http://www.winsoft.se/?p=410</guid>
		<description><![CDATA[To demonstrate the CLI control, I have made a simple guessing game. The source code is below. If you want to run it yourself, place the exe file and a copy of CLIControl.dll in the same folder. Public Class Form1 'How many times has the user guessed? Private GuessCount As Integer = 0 'The correct [...]]]></description>
			<content:encoded><![CDATA[<p>To demonstrate the CLI control, I have made a simple guessing game. The source code is below. If you want to run it yourself, place the <a href="http://www.winsoft.se/files/CliDemo1.zip">exe file</a> and a copy of <a href="http://www.winsoft.se/files/CLIControl.zip">CLIControl.dll</a> in the same folder.</p>
<div class="wp-caption aligncenter" style="width: 510px"><img alt="CLI Control" src="http://imghost.winsoft.se/upload/835001248082338clidemopic1.png" title="CLI Control" width="500" height="243" /><p class="wp-caption-text">CLI Control demo</p></div>
<pre>Public Class Form1

	'How many times has the user guessed?
	Private GuessCount As Integer = 0

	'The correct answer (can be 1 to 1000).
	Private CorrectAnswer As Integer

	'A random number generator is needed.
	Private Rnd As New Random()

	'Game flag.
	Private GameOn As Boolean = False

	'At startup, set some properties of the CLI control.
	Private Sub Form1_Load(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles MyBase.Load

		'Create a background for the control. If you have a
                'file, use LoadBackgroundFromFile.
		Dim Background As New System.Drawing.Bitmap(20, 50)
		Using G As System.Drawing.Graphics = Graphics.FromImage(Background)
			Using Blue1 As New SolidBrush(Color.FromArgb(255, 20, 40, 60))
				G.FillRectangle(Blue1, 0, 0, 20, 50)
			End Using
			Using Blue2 As New SolidBrush(Color.FromArgb(255, 40, 60, 80))
				G.FillRectangle(Blue2, 0, 10, 20, 10)
			End Using
		End Using
		'Assign the background (not needed if you use LoadBackgroundFromFile).
		Cli1.BackgroundImage = Background

		'Create and assing a brush for the text font.
		Cli1.TextBrush = New System.Drawing.Drawing2D.LinearGradientBrush( _
		 New Point(0, 0), _
		 New Point(0, Cli1.Height), _
		 Color.FromArgb(100, 255, 255, 255), _
		 Color.FromArgb(255, 255, 255, 255))

		'Add a shadow to the text.
		Cli1.TextShadow = True

		'The number that the user is trying to find (1 to 1000).
		Me.CorrectAnswer = Me.Rnd.Next(1, 1001)

		'Say something to the user, and add some lines for decoration.
		Cli1.WriteLine("Welcome! Guess a number between 1 and 1000!")
		Cli1.WriteLine()
		Dim P As New System.Drawing.Pen(Color.Yellow, 2)
		Cli1.GraphicalElements.AddLine("", P, 0, 304, Cli1.Width, 0)
		Cli1.GraphicalElements.AddLine("", P, 0, 323, Cli1.Width, 0)

		'Go!
		Me.GameOn = True
	End Sub

	Private Sub Cli1_UserTyped(ByVal Sender As Object, _
        ByVal Command As String) Handles Cli1.UserTyped
		'If the game is running, assume that the user is guessing
                'on the correct number.
		If GameOn Then
			Try
				Dim I As Integer = Integer.Parse(Command)
				If I < 1 Or I > 1000 Then
					Cli1.WriteLine("The number must be between 1 and 1000!")
				Else

					'Increase the number of guesses.
					Me.GuessCount += 1

					'Display the guess count as an image.
					Me.AddGuessCountImage()

					If I = CorrectAnswer Then

						'Correct!
						Cli1.WriteLine("Correct in " &#038; Me.GuessCount.ToString() &#038; _
                                                        " guesses!")
						Cli1.WriteLine()
						'Add a green line.
						Cli1.GraphicalElements.AddLine("", Pens.Green, 0, _
                                                         323, Cli1.Width, 0)
						Me.GameOn = False

					ElseIf I < CorrectAnswer Then

						Cli1.WriteLine("I am thinking of a larger number.")

					ElseIf I > CorrectAnswer Then

						Cli1.WriteLine("I am thinking of a smaller number.")

					End If

				End If
			Catch ex As Exception
				Cli1.WriteLine("You must type a number between 1 and 1000!")
			End Try
		Else
			Console.WriteLine("Game over!")
		End If
	End Sub

	Private Sub AddGuessCountImage()
		Dim B As New System.Drawing.Bitmap(70, 70)
		Using F As New System.Drawing.Font("Times New Roman", 30, FontStyle.Regular)
			Dim GuessCountString As String = Me.GuessCount.ToString()
			Using G As Graphics = Graphics.FromImage(B)
				G.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
				G.FillEllipse(Brushes.Black, 0, 0, 69, 69)
				G.DrawEllipse(Pens.Red, 0, 0, 69, 69)
				Dim StringSize As SizeF = G.MeasureString(GuessCountString, F)
				Dim X As Single = 35 - (StringSize.Width / 2)
				Dim Y As Single = 35 - (StringSize.Height / 2)
				G.DrawString(GuessCountString, F, Brushes.White, X, Y)
			End Using
		End Using
		Cli1.GraphicalElements.AddPicture("", B, 400 + Me.Rnd.Next(200), 250)
	End Sub

End Class</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.winsoft.se/2009/07/first-cli-control-demo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vector graphics in CLI control</title>
		<link>http://www.winsoft.se/2009/07/vector-graphics-in-cli-control/</link>
		<comments>http://www.winsoft.se/2009/07/vector-graphics-in-cli-control/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 16:24:20 +0000</pubDate>
		<dc:creator>Anders Hesselbom</dc:creator>
				<category><![CDATA[Microsoft .NET]]></category>
		<category><![CDATA[CLIControl]]></category>

		<guid isPermaLink="false">http://www.winsoft.se/?p=402</guid>
		<description><![CDATA[This post is done from the middle of nowhere and I am using my 3G phone as a modem. I hope that I manage to upload everything. I have added support for vector graphics in my CLI control to make the control more versatile. A collection named GraphicalElement holds the graphics to be drawn. Graphical [...]]]></description>
			<content:encoded><![CDATA[<p>This post is done from the middle of nowhere and I am using my 3G phone as a modem. I hope that I manage to upload everything.</p>
<p>I have added support for vector graphics in my CLI control to make the control more versatile. A collection named GraphicalElement holds the graphics to be drawn. Graphical elements in the collection can be manipulated and changes are reflected when the control is redrawn (you can call the Invalidate method to flag the control as dirty). When scrolling occurs, all graphical elements also are moved up. Elements are deleted when they scroll out of view.</p>
<p>This simple example shows how to add graphics (it draws 60 bars in a nice pattern):</p>
<p><strong>For I As Integer = 1 To 60<br />
Cli1.GraphicalElements.AddBox(&#8220;&#8221;, Brushes.Yellow, I * 10, 10, 8, _<br />
CType(50 + (Math.Sin(I / 3) * 50), Integer))<br />
Next</strong></p>
<p>Because elements are deleted automatically when they scroll out of view, items will get new index numbers. Therefore, you should either save a reference to the item (a reference can be created manually using the Box constructor, but a reference to a Box is also given as return value from the AddBox method) or give the element a name, and then acquire a reference when a reference is needed using the FindElementByName method of the GraphicalElement collection.</p>
<p>When I have the opportunity, I will do some more examples and some illustrations.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.winsoft.se/2009/07/vector-graphics-in-cli-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

