Skip to content

The ups and downs of Visual Studio 2010: Auto list members

In Visual Studio 2010, the auto list members feature is much more intelligent than in previous versions. For example, assuming that X is an object with a visible function called DoSomeWork, in earlier versions of Visual Studio, you would have to know that the method started with Do to find it in the list. If you didn’t know that, you would have to scroll through the list of members and try to recall what you are looking for, or search in the object browser. Now, if you type X.Work, Visual Studio lists DoSomeWork as a suggestion, because matching is done within the name, not only from the beginning of the name. Also, you type an acronym of the function name. DSW would match DoSomeWork.

Previous versions of Visual Studio applied a “suggest and complete” policy, which is the default in Visual Studio 2010. This is usually the most effected mode. If you are aiming to call the DoSomeWork function, you can type something like X.DoSo and then what ever character you was going to type thereafter, likely an opening parenthesis. The problem with the “suggest and complete” policy shows up when you’re trying to call a function that isn’t implemented yet. The text editor will force your typing to be a call to something other than you are aiming at, something that already exists, at least if the not-yet-existing member has a name that is a subset of an existing name. I always end up grabbing my computer mouse when this happens. This is one example where the “suggest only” policy can be useful. This mode lets you type whatever you want, because it will not force you to choose from something in the list.

To toggle completion mode, press Ctrl+Alt+Space or look at the IntelliSense sub menu under the Edit menu. Just as the call hierarchy feature, this feature is available no matter what language you’re using, but (at least in the Beta) it only works in the C# editor, not the Visual Basic editor.

Now, there is no reason to have a mouse connected to the computer anymore. Thank you, Microsoft!

Categories: Visual Studio 10.

The stamping program

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:

Some visual aid

To conclude, click on an organism to zoom in on it. When an organism is zoomed in, some details about it is shown together with the DNA string of the parent organisms (if the parents are still alive).

Download: Drifting.exe

Happy new year!

If you are interested in looking at the source code, a VS2010 Visual Basic solution can be downloaded here. The solution targets .NET Framework 2.0.

Categories: Science.

Tags: ,

Pythonscript för gratis musik

Som bekant kan man ladda hem hur mycket upphovsrättsskyddad musik som helst, helt gratis och (om så önskas) helt anonymt från Google. Om du är förtjust i scriptingspråket Python, har Nick Jensen filat till ett script som du kan använda för att hämta hem din favoritmusik i MP3-format. Nick Jensen’s script finns att ladda hem här.

Categories: General.

Using regions

Regions are used to define a path or an area for later use. The Region instruction takes any number of coordinates (3 or more), and stores them in memory. The region can then be used for drawing. The following example is done in Notepad. I have created a text-file, changed the file ending from .txt to .mob. In the file, I have added these three lines of text:

Clear #ffffff 70x70
Region (10,10) (60,10) (60,60) (10,60)
Line Region #ff00ff

When loaded in the Monkeybone viewer, this is the result:

When regions are created using the MonkeyboneWriter class, they are much easier to manipulate. This example defines a shape, writes it, manipulates it, and writes it again.

Module Module1

    Sub Main()

        'Create a Monkeybone stream.
        Using W As New Monkeybone.MonkeyboneWriter("C:\regions.mob", 130, 130,
            System.Drawing.Color.Black)

            'Define a region.
            Dim R As New Monkeybone.Instructions.Region()
            R.AddPoint(10, 110)
            R.AddPoint(60, 10)
            R.AddPoint(110, 110)

            'Write the region to the stream.
            W.WriteLine(R)

            'Write an instruction to draw the region outline in green.
            Dim L As New Monkeybone.Instructions.Line()
            L.Color = Drawing.Color.Lime
            L.UseRegion = True
            W.WriteLine(L)

            'Modify the region (move it 10 pixels to the
               left and 10 pixels down) and write it again.
            R.Move(10, 10)
            W.WriteLine(R)

            'Write an instruction to draw the region outline in yellow.
            L.Color = Drawing.Color.Yellow
            W.Write(L)

            'Flush and close the stream.
            W.Flush()
            W.Close()
        End Using

    End Sub

End Module

The code produces the following mob file:

Clear #000000 130x130
Region (10,110) (60,10) (110,110)
Line Region #00FF00
Region (20,120) (70,20) (120,120)
Line Region #FFFF00

This is the result when it is loaded into the Monkeybone viewer:

Categories: General.

Tags:

Some changes made to the viewer

Some changes are made to the Monkeybone viewer, that is not related to the Monkeybone format (*.mob files). These changes are made just to make the viewer more decent.

Not only Monkeybone images can be opened. Now, you can open PNG and JPG files as well. Features such as viewing the error log, viewing the source or saving, is only available when a Monkeybone image is loaded.

When an image is loaded, no matter if it is a Monekybone image or not, the viewer checks the directory for other images. You can use the file menu to load the next or previous image in the folder, or just press F11 for the previous image and F12 for the next.

Again, these changes are made just to make viewing easier. The Monkeybone viewer is designed to display Monkeybone images. If you are in to serious image viewing, I recommend IrfanView instead. But if you are looking for a viewer of the powerful and editable Monkeybone fomat, the Monkeybone viewer is it.

Categories: General.

Tags:

Counting the DNA differences

The following adjustment is done to the drifting game. In the first version, DNA differences were counted sequentially, meaning that within each group each organism was compared to its neighbor. By changing this so that every organism is compared to every other organism, and then divided to the number of comparisons done within each group, the number of DNA differences within each group is much more accurate. This makes the increasing differences, the drifting, much more obvious.

The screenshot displays the number of differences just a few years after separation of the groups.

Download the drifting game here.

Categories: Science.

Tags: ,

This is the drifting game!

The drifting game does not illustrate evolution or the power of natural selection, but change over time and our ability to tell that about relationship to other spices, such as chimpanzees. The board consists of 285 placeholders (19 x 15). Each placeholder can hold one organism. This is an organism.

The blue number indicates the age in years of the organism. The red number shows the number of offspring the organism has produced. An organism cannot produce offspring on its own; it must mate with another organism of the opposite gender. Light blue rectangle represent male organisms, pink represent female. What else? ;-) The lines are drawn between parents with the child in between.

In the middle, the DNA of the organism is displayed. The red amino acid pairs with red or yellow amino acid. The green amino acid pairs with green or blue amino acid. A DNA string consists of 24 pairs. The effect of this demonstration will be better if the number of pairs is greater, but it makes the visual overview poorer.

When organisms breed, the offspring will have a mixture of the parents DNA. Sometimes, mutations occur. Mutations cannot be traced from either parent. A mutation can sometimes be easy to spot, because in a mutation, any amino acid can pair with any amino acid. So a red could pair with a red, but it could also pair with a green. A pair of red and yellow could be a mutation, a pair of red and green is a mutation.

An organism that isn’t too young or too old might breed and an organism of high age might die and leave room for younger individuals.

To control: Press Space to pause and press F12 to separate the group in to two groups (can be done once). The expected effect after the split is that the number of DNA differences between individuals in the group will remain the same as the previous total, but the DNA differences between the groups will increase over time, even though no selection is done. The DNA differences are counted for sequentially and divided by the number individuals in a group. So, not every individual is compared with every individual. Correction here.

Before the population is splitted into two groups (press F12 to do that), the total number of DNA differences is shown. After the population is splitted into two groups, the total number of DNA differences is shown together with the number of DNA differences within each group. Now you can compare the differences within each group (expected to be smaller) with the total number of differences (expected to be larger since the groups are drifting in different directions).

Download the drifting game here.

Categories: Science.

Tags: ,

PhotoName improvements, December 2009

The following changes are made to PhotoName.

The Options dialog (click Behaviour and Other settings) lets you control what will happen if you double click an image in the list.

A new drop down menu (Edit) is added to the menu bar. From there you can change what images are selected in the list. You can choose to select all images, no images or toggle the selection.

Also, you can view all images as thumbnails, and click on the images you want to select or deselect. To do this, click Edit and Select from thumbnails.

This is very effective if you want to export images as a gallery, because you have a good overview of what pictures you have in the selected directory and which of them will be included in the gallery.

You can download PhotoName from here.

Categories: General.

Tags:

The Monkeybone writer

The Monkeybone Viewer takes a mob file and displays its content on screen. The file stores instructions, such as Bar and Line, as Unicode text. These files can be created by hand using any text editor, such as Notepad (shown here, here, here and here).

To automate the generation of the Monkeybone file, you can write a program that creates a file with instructions (with mob as file ending), and writes the instructions to that file. If you do this using the .NET Framework, you might create a StreamWriter and write lines of text to that writer.

To ensure that the output file is formatted the correct way, and to make this process easier, you can download and use the Monkeybone library that contains the MonkeyboneWriter class. The MonkeyboneWriter class inherits from the StreamWriter class, and it provides overloads of the WriteLine function that takes objects that represent Monkeybone instructions. To make a Bar instruction appear in the file, create a Monkeybone.MonkeyboneWriter object, create a Monkeybone.Bar object and set the properties of the object. Pass the Monkeybone.Bar object to the WriteLine function of the Monkeybone.MonkeyboneWriter object. To make another Bar instruction appear in the file, you can create a new Bar object or modify the Bar object you already have, and pass it to the WriteLine function again, like so:

Module Module1

    Sub Main()

        'Create a Monkeybone stream.
        Using W As New Monkeybone.MonkeyboneWriter("C:\mypicture.mob", _
            200, 170, System.Drawing.Color.Black)

            'Create a vertical Monkeybone bar.
            Dim B As New Monkeybone.Instructions.Bar(10, 10, 20, 100)
            B.Orientation = Monkeybone.Instructions.Bar.BarOrientation.Vertical
            B.Color = Drawing.Color.Red

            'Write the bar to the stream.
            W.WriteLine(B)

            'Modify it, and write it again.
            B.X += 10
            B.Y += 20
            B.Color = Drawing.Color.Yellow
            W.WriteLine(B)

            'Modify it, and write it again.
            B.X += 10
            B.Y += 20
            B.Color = Drawing.Color.Green
            W.WriteLine(B)

            'A nice sine effect on top of everything!
            Dim SineBar As New Monkeybone.Instructions.Bar(0, 5, 1, 160, Drawing.Color.White)
            SineBar.Orientation = Monkeybone.Instructions.Bar.BarOrientation.Vertical
            For I As Integer = 0 To 31
                SineBar.X += 6
                SineBar.BarFillPercent = 60 + CType((Math.Sin(I / 5) * 40), Integer)
                W.WriteLine(SineBar)
            Next

            'Flush and close the stream.
            W.Flush()
            W.Close()
        End Using

    End Sub

End Module

(The code requires a reference to the Monkeybone library.)

Monkeybone pictures can created using Notepad, from any program that creates a Unicode text file with the mob file ending, or from a .NET application using the MonkeyboneWriter class of the Monkeybone library.

This is the output from the example program (the contents of the mypicture.mob file):

Clear #000000 200x170
Bar #FF0000 X:10 Y:10 W:20 H:100
Bar #FFFF00 X:20 Y:30 W:20 H:100
Bar #008000 X:30 Y:50 W:20 H:100
Bar #FFFFFF X:46 Y:5 W:5 H:160 VFill:60%
Bar #FFFFFF X:52 Y:5 W:5 H:160 VFill:68%
Bar #FFFFFF X:58 Y:5 W:5 H:160 VFill:76%
Bar #FFFFFF X:64 Y:5 W:5 H:160 VFill:83%
Bar #FFFFFF X:70 Y:5 W:5 H:160 VFill:89%
Bar #FFFFFF X:76 Y:5 W:5 H:160 VFill:94%
Bar #FFFFFF X:82 Y:5 W:5 H:160 VFill:97%
Bar #FFFFFF X:88 Y:5 W:5 H:160 VFill:99%
Bar #FFFFFF X:94 Y:5 W:5 H:160
Bar #FFFFFF X:100 Y:5 W:5 H:160 VFill:99%
Bar #FFFFFF X:106 Y:5 W:5 H:160 VFill:96%
Bar #FFFFFF X:112 Y:5 W:5 H:160 VFill:92%
Bar #FFFFFF X:118 Y:5 W:5 H:160 VFill:87%
Bar #FFFFFF X:124 Y:5 W:5 H:160 VFill:81%
Bar #FFFFFF X:130 Y:5 W:5 H:160 VFill:73%
Bar #FFFFFF X:136 Y:5 W:5 H:160 VFill:66%
Bar #FFFFFF X:142 Y:5 W:5 H:160 VFill:58%
Bar #FFFFFF X:148 Y:5 W:5 H:160 VFill:50%
Bar #FFFFFF X:154 Y:5 W:5 H:160 VFill:42%
Bar #FFFFFF X:160 Y:5 W:5 H:160 VFill:36%
Bar #FFFFFF X:166 Y:5 W:5 H:160 VFill:30%
Bar #FFFFFF X:172 Y:5 W:5 H:160 VFill:25%
Bar #FFFFFF X:178 Y:5 W:5 H:160 VFill:22%
Bar #FFFFFF X:184 Y:5 W:5 H:160 VFill:20%
Bar #FFFFFF X:190 Y:5 W:5 H:160 VFill:20%
Bar #FFFFFF X:196 Y:5 W:5 H:160 VFill:22%
Bar #FFFFFF X:202 Y:5 W:5 H:160 VFill:25%
Bar #FFFFFF X:208 Y:5 W:5 H:160 VFill:29%
Bar #FFFFFF X:214 Y:5 W:5 H:160 VFill:35%
Bar #FFFFFF X:220 Y:5 W:5 H:160 VFill:41%
Bar #FFFFFF X:226 Y:5 W:5 H:160 VFill:49%

If you load the mypicture.mob file in the Monkeybone viewer, this would be the result:

Categories: General.

Tags: