Manipulate any program by using C#

Manipulate any program by using CsharpThis article is going to be all about how you can control, customize and extend other programs using C#. As an example scenario we’re going to be extending the default Windows program Notepad with a custom function.
The C# application will modify all running instances of Notepad by adding a new button to the UI and listening for clicks on the button. A click on the button will convert the text in the Notepad text field into HTML using a Markdown parser (What is Markdown?) and display the HTML in our application.
If you follow the article, the finished product is going to look like this:

The article will have you construct the program step by step. If you want to read the full […]

How to convert C# DateTime.Ticks into Unix timestamp

C# DateTime.Ticks ConverterWith the .NET frameworks DateTime functions you can do a lot of nice things. The handling turns out, in my opinion, very pleasant. The only requirement: You find yourself in a pure .NET environment. When other systems come into play, the trouble begins. But why is it that you can not compare DateTime.Ticks with the PHP mktime()-function?
If you request the “timestamp” from a DateTime-object (DateTime.Ticks), so you get back the number of ticks since 01.01.0001 00:00. A tick in turn is 100 nanoseconds long.
A Unix timestamp, as produced by mktime() for example, is to the contrary, the number of seconds since 01/01/1970. A direct comparison is not possible. So you have to convert between the both units at first. And how to do this, is what I want to show you today, based on a […]

Simple XML serialization in C#

C# XML SerialisierungToday I want to show you how to perform a XML serialization in C#. Serialization itself, means that you convert an object to another, transportable form.
Using XML serialization, it is possible, for example, to store an object of a class in the form of an XML file and restore it later.
This can make sense if you if you want to transfer an object, for example, via HTTP or  restore an object to its state after closing and reopening an application.
For our example, I created the following class “Blog”:

public class Blog
{
public string User { get; set; }
public string Pass { get; set; }
public string Subdomain { get; set; }
public string BaseUrl { get; set; }
}

The method used to serialize is as follows:

public […]

How to create articles on Blogspot with C#

Blogger C# API LogoToday I want to show you how to create a blog article on Blogger.com/Blogspot.com with C#. For this you need first of all the Google.GData.Client.dll, which you can find inside the Google .Net API package.
You can download the API package here from Google. (The file is called Google_Data_API_Setup_2.2.0.msi (Please note that the version number – 2.2.0 – over time may change of course.)
If the download is complete, install the package, open a new project in Visual Studio and add a reference to the Google.GData.Client.dll.
The .dll file can be found in the installation directory of the API package. (Click on the link “add a reference” above, if you need help embedding .dlls into a Visual Studio project.)
If you have included the DLL, you can start already. Blog posts (aka articles) can be created as follows:

private static int […]

How to change the size of a textbox in C#

I admit, the title sounds almost trivial. But on the second sight, it is not so easy to change the size of a TextBox control in C#, because a TextBox does not have the AutoSize property. For other controls you can set the AutoSize property to false and then change the height (height-property). For the TextBox control this is unfortunately not the case.
Nevertheless you can set the height of a TextBox by using a small workaround. The trick is as follows:

textBoxTest.Multiline = true;
textBoxTest.MinimumSize = new Size(150, 24);
textBoxTest.Size = new Size(150, 24);
textBoxTest.Multiline = false;

First you have to set the multiline property to true. Then you can adjust, according to your mood, the minimum-size and the size property to change the size of the TextBox. When you’re done, you set the Multiline property back to false. The TextBox maintains the set size just yet. It’s that simple
Who still wonders, why you should […]