This is a preview version of Cyotek's blog and may be missing functionality and/or unstable. Please visit https://www.cyotek.com/blog for the current version of the blog.
If you encounter any problems using this preview site, please contact us with the details.

Archived posts for All of 2011

Detecting if an application is running as an elevated process, and spawning a new process using elevated permissions

c# uac elevated permissions UnauthorizedAccessException SecurityException process runas 2 Comments

Recently I was writing some code to allow a program to register itself to start with Windows for all users. On Windows 7 with User Account Control (UAC) enabled, trying to write to the relevant registry key without having elevated permissions throws an UnauthorizedAccessException exception. If you want to make these sorts of modifications to a system, the application needs to be running as an administrator.

To check if your application is currently running with elevated permissions, you simply need to see if the current user belongs to the Administrator user group.

Read More

Extending the ImageBox component to display the contents of a PDF file using C#

c# winforms image imagebox pdf ghostscript convert 2 Comments Downloads

In this article, I'll describe how to extend the ImageBox control discussed in earlier articles to be able to display PDF files with the help of the GhostScript library and the conversion library described in the previous article.

You can download the source code used in this article from the links below, these are:

Read More

Convert a PDF into a series of images using C# and GhostScript

c# image pdf ghostscript convert gsapi_new_instance gsapi_exit gsapi_delete_instance 68 Comments Downloads

An application I was recently working on received PDF files from a webservice which it then needed to store in a database. I wanted the ability to display previews of these documents within the application. While there are a number of solutions for creating PDF files from C#, options for viewing a PDF within your application is much more limited, unless you purchase expensive commercial products, or use COM interop to embed Acrobat Reader into your application.

This article describes an alternate solution, in which the pages in a PDF are converted into images using GhostScript, from where you can then display them in your application.

Read More

Detecting if a given font style exists in C#

c# font 4 Comments

In a previous article, Creating a WYSIWYG font ComboBox using C#, there is a hacky bit of code which uses a try catch block to handle processing when a given font style doesn't exist. This article describes a better way of handling this requirement without relying on the exception handler.

Originally we used the following code to determine if a font style exists: (Some of the additional code has been removed for clarity)

Read More

CSS Syntax Highlighting in the DigitalRune Text Editor Control

c# winforms css syntax digitalrune sharpdevelop 0 Comments Downloads

For projects where I need some form of syntax highlighting, I tend to use the open source DigitalRune Text Editor Control which is a modified version of the text editor used in SharpDevelop. While it has a number of syntax definitions built in, the one it didn't have was for CSS formatting.

After doing a quick search on the internet and finding pretty much nothing, I created my own. This article describes that process, along with how to embed the definition directly in a custom version of the control, or loading it into the vendor supplied control.

Read More

Importing a SourceSafe database into Subversion

sourcesafe vss subversion svn migrate opensource 0 Comments Downloads

In my previous article on migrating a VSS database into SVN, I hadn't tried importing a VSS database into an existing repository, which is something I found the original code couldn't handle.

I rewrote the original tool to have a GUI front end in addition to a console version, updated to allow importing into existing repositories, and fixed a crash which would occur when trying to import a file which couldn't be retrieved from SourceSafe. The updated tool worked enough for my purposes, but hasn't been extensively tested. However, as my three VSS databases are now in SVN it's unlikely I'll be making further updates to the code.

Read More

Migrating from Visual SourceSafe to Subversion

sourcesafe vss subversion svn migrate 7 Comments

For years now, we've used Microsoft Visual SourceSafe (VSS) for our source code control, but given that Microsoft dropped support for it some time ago in favour of Team Foundation Server, we've decided to switch VSS with an open source system. This article describes our experiences with a test migration.

As I tend to prefer the client/server model I decided to trial Subversion (SVN) over other systems such as Git or Mercury. I also want to be able to import the VSS databases containing our current code, and the one with the legacy VB6 components we used to offer.

Read More

Enabling shell styles for the ListView and TreeView controls in C#

c# winforms treeview listview uxtheme shell 3 Comments Downloads

For those who remember the Common Controls OCX's featured in Visual Basic 5 and 6, there was one peculiarity of these. In Visual Basic 5, the Common Controls were linked directly to their shell counterparts. As the shell was updated, so did the look of any VB app using these. However, for Visual Basic 6, this behaviour was changed and they didn't use the shell for drawing.

Curiously enough, history repeats itself in a limited way with Visual Studio .NET. If you use the ListView or TreeView controls on Windows Vista or higher, you'll find they are somewhat drawn according to the "classic" Windows style - no gradients on selection highlights, column separators (ListView) or alternate +/- glyphs (TreeView).

Read More

Creating a WYSIWYG font ComboBox using C#

c# winforms combobox font ownerdraw 6 Comments

This article shows how to use the built in ownerdraw functionality of a standard Windows Forms ComboBox control to display a WYSIWYG font list.

To start, we'll create a new class, and inherit this from the ComboBox control.

Read More