Wednesday, July 31, 2019

Using Resources to store images in a windows forms C# program


It is useful to store the images used by a program inside the executable as resources. Visual studio offers an efficient way to do that.

The method is very simple  but I always forget how to do it. So, this is a very short tutorial.

Note: I use Visual studio 2017 but the procedure is similar with other versions.

1.    Create the project

We use Visual studio to create a windows Forms App.


2.    Put the resource in the project

Open the Resource.resx file by double clicking on it. (Visual studio will open a specific editor)



In the toolbar of this editor select Add Resource and select “Add existing file” then choose the desired image file (here I will use summer.bmp).



This will create a new resource containing the desired image



3.    Use the image

You can now use the image resource in the designer i.e. as the image property of a Picture box



But you can also access the image in the code by using <program_name>.Properties.Resources.<resourcename>.

See example below:

namespace image_in_ressource
{
    public partial class Form1 : Form
    {
        private Image summerImage;
        public Form1()
        {
            InitializeComponent();
            summerImage = new Bitmap(image_in_ressource.Properties.Resources.summer);
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawImageUnscaled(summerImage, new Point(0, 0));
        }
    }
}


Tuesday, May 14, 2019


Making a feeder for Märklin M Tracks


Even if Märklin M tracks are not manufactured anymore, it is very easy to find a lot of them online and since they are obsolete, they are often quite cheap.

But it is sometimes more problematic to find feeder tracks. So, let’s build our own.


We will use the very common 5106 straight M track.
We will solder the wires at the indicated places.




Before soldering the wires, we must use a small knife (I have used the blade a small flat screwdriver) to scratch the paint and the oxide.

To let the wires go out it is easy to drill a small hole on the metallic side of the track.


The metal is not hard at all to drill

Once everything is finished don’t forget to make a knot in the wires to prevent excessive constrains on the solders

And here it is, just as good as the original much harder to find 5111, ready to provide power to all your trains.


            



Thank you to my father who shown mehow to do that in 1979.