codesnipped in wordpress

To have a nice view of code and use some syntax highlights there is a easy opportunity to show code in a better way. The basic way that i will show in the following lines is made for this languages:

actionscript3, bash, clojure, coldfusion, cpp, csharp, css, delphi, diff, erlang, fsharp, go, groovy, html, java, javafx, javascript, latex, matlab, objc, perl, php, powershell, python, r, ruby, scala, sql, text, vb and xml

Basically you can use it like this:


(sry, I had to paste it as a pic to show it here to you)

As well there are opportunities to modify the code block with the following parameter:

  • autolinks (true/false) — Makes all URLs in your posted code clickable. Defaults to true.
  • collapse (true/false) — If true, the code box will be collapsed when the page loads, requiring the visitor to click to expand it. Good for large code posts. Defaults to false.
  • firstline (number) — Use this to change what number the line numbering starts at. It defaults to 1.
  • gutter (true/false) — If false, the line numbering on the left side will be hidden. Defaults to true.
  • highlight (comma-seperated list of numbers) — You can list the line numbers you want to be highlighted. For example “4,7,19”.
  • htmlscript (true/false) — If true, any HTML/XML in your code will be highlighted. This is useful when you are mixing code into HTML, such as PHP inside of HTML. Defaults to false and will only work with certain code languages.
  • light (true/false) — If true, the gutter (line numbering) and margin (see below) will be hidden. This is helpful when posting only one or two lines of code. Defaults to false.
  • padlinenumbers (true/false/integer) — Allows you to control the line number padding. true will result in automatic padding, false will result in no padding, and entering a number will force a specific amount of padding.
  • title (string) — Set a label for your code block. Can be useful when combined with the collapse parameter.

For more check out this:

transparency in c#

In .net and c# we have different opportunities to set something transparent. I want use a picture and add a blue semi-transparency. For this example I used a windows-forms-application and added a track bar and a picture box. In my code I use some functions of the library “System.Drawing.Drawing2D”. In the constructor of my main form I add the method “drawBlueTransparency” to the paint-event of the picture box.

public Form1()
 trackBar1.Maximum = 255;
 pictureBox1.Paint += new PaintEventHandler(drawBlueTransparency);

I also set the maximum of the track bar to 255 because this is the maximum of the alpha value that I used in the event-function (see variable  “alphaValue”). As well you could use a max of 10 and recalc the alphaValue.

private void drawBlueTransparency(object sender, PaintEventArgs e) 
 var rect = new Rectangle(20, 20, 184, 184); 
 var brush = new SolidBrush(Color.FromArgb(alphaValue, 0, 0, 255));
 e.Graphics.FillEllipse(brush, rect); 

The method just creates a new rectangle and use it to draw a ellips in it. For this it also needs a brush that is initialized by a color with the alphaValue. If the alphaValue is 0 you will see nothing of the blue ellipse and if you set the alphaValue to 255 (maximum) you just will see the blue ellipse without any transparency. Everything in between is like semi-transparent.

Now I can set different alpha values and use the method “.Refresh()” to redraw the picture box.

private void trackBar1_Scroll(object sender, System.EventArgs e)
 alphaValue = trackBar1.Value;

Here you can see the result:


Easy! 🙂