blez's : blog

code / design / music and more

Leave a comment

How to use HTML5 audio in the WebBrowser control?

No matter how new version of Windows you use, the WebBrowser control always uses older version of IE. That’s pretty awful solution since we all know how good IE is. Using meta tags it is possible to say to IE to use a specific version. The following example illustrates how to make a simple html5 audio player playing mp3 directly from some url.

// the obvious..
// webBrowser1 is a WebBrowser control
// someUrl is an url to a mp3 file

var source = "<html><head><meta http-equiv='X-UA-Compatible' content='IE=9'></head><body><audio id='player' style='position: absolute; left: 0; top: 0; width: 100%' controls autoplay='autoplay'><source src='{0}' type='audio/mpeg'>You need a newer version of IE to play this track.</audio></body></html>";
webBrowser1.DocumentText = string.Format(source, someUrl);

1 Comment

How to create transparent labels in WinForms

If you come from VB6, you’ll notice that WinForms doesn’t have transparent labels. WHICH SUCKS if you really need them. There are workarounds like using WPF instead or drawing the ‘labels’ with DrawText. But I recently found a better way – using the LinkLabel control. It supports transparency just fine. The only thing you have to do is to disable all its link properties.
The code below shows how:

// if your LinkLabel is called linkLabel

linkLabel.ForeColor = this.ForeColor;
linkLabel.LinkColor = this.ForeColor;
linkLabel.VisitedLinkColor = this.ForeColor;
linkLabel.ActiveLinkColor = this.ForeColor;
linkLabel.DisabledLinkColor = this.ForeColor;
linkLabel.LinkArea = new LinkArea(0, 0);
linkLabel.LinkBehavior = LinkBehavior.NeverUnderline;
linkLabel.Cursor = Cursors.Arrow;
linkLabel.BackColor = Color.Transparent;