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.

Using the XmlReader class with C#

c# xml xmldocument xmlreader xmlwriter 7 Comments

Some of the project files created by Cyotek Sitemap Creator and WebCopy are fairly large and the load performance of such files is poor. The files are saved using a XmlWriter class which is nice and fast. When reading the files back however, currently the whole file is loaded into a XmlDocument and then XPath expressions are used to pull out the values. This article describes our effort at converting the load code to use a XmlReader instead.

The following XML snippet can be used as a base for testing the code in this article, if required.

Read More

Comparing the properties of two objects via Reflection and C#

c# compare ienumerable reflection propertyinfo icomparable 22 Comments

As part of the refactoring I was doing to the load code for crawler projects I needed a way of verifying that new code was loading data correctly. As it would be extremely time consuming to manually compare the objects, I used Reflection to compare the different objects and their properties. This article briefly describes the process and provides a complete helper function you can use in your own projects.

This code is loosely based on a stackoverflow question, but I have heavily modified and expanded the original concept.

Read More

Creating a trackback handler using C#

c# webforms mvc asp.net trackback webrequest webresponse 3 Comments Downloads

Cyotek.com runs on its own custom CMS/blog engine developed in ASP.NET MVC 1.0, which has a number of advantages and disadvantages. One of these disadvantages is no automatic support for some common blog features such as trackbacks and pingbacks.

This article will describe how to create a trackback handler for use with MVC and the more traditional webforms.

Read More

Creating a scrollable and zoomable image viewer in C# Part 4

c# winforms scroll zoom image graphics pan imagebox 33 Comments Downloads

In the conclusion to our series on building a scrollable and zoomable image viewer, we'll add support for zooming, auto centering, size to fit and some display optimizations and enhancements.

Unlike parts 2 and 3, we're actually adding quite a lot of new functionality, some of it more complicated than others.

Read More

Creating a scrollable and zoomable image viewer in C# Part 3

c# winforms scroll zoom check image imagebox 2 Comments Downloads

After part 2 added scrolling support, we are now going to extend this to support keyboard scrolling and panning with the mouse.

In order to enable panning, we're going to add three new properties. The AutoPan property will control if the user can click and drag the image with the mouse in order to scroll. Also, we'll add an InvertMouse property to control how the scrolling works. Finally the IsPanning property; however it can only be read publically, not set.

Read More

Creating a scrollable and zoomable image viewer in C# Part 2

c# winforms scroll zoom check image imagebox 1 Comments Downloads

In the second part of our Creating a scrollable and zoomable image viewer in C# series we will update our component to support automatic scrolling when auto size is disabled and the image is larger than the client area of the control.

Originally we inherited from Control, however this does not support automatic scrolling. Rather than reinventing the wheel at this point, we'll change the control to inherit from ScrollableControl instead. This will expose a number of new members, the ones we need are:

Read More

Creating a scrollable and zoomable image viewer in C# Part 1

c# winforms scroll zoom check image imagebox 2 Comments Downloads

This is the first part in a series of articles that will result in a component for viewing an image. The final component will support zooming and scrolling.

In this first part, we're going to create a basic image viewer, without the scrolling and zooming. Rather than having a plain background however, we're going to create a two tone checker box effect which is often used for showing transparent images. We'll also allow this to be disabled and a solid colour used instead.

Read More

Adding a horizontal scrollbar to a ComboBox using C#

c# winforms combobox horizontal scroll api 4 Comments Downloads

In our WebCopy application we decided to update the User Agent configuration to allow selection from a predefined list of common agents, but still allow the user to enter their own custom agent if required.

Rather than use two separate fields, we choose to use a ComboBox in simple mode, which is both a textbox and a listbox in a single control. This mode seems somewhat out of fashion, I think the only place I see it used is in the Font common dialog, virtually unchanged since Windows 3.1.

Read More

Boulder Dash Part 2: Collision Detection

c# ai game sprite boulder dash collision detection 0 Comments Downloads

In our previous post we introduced the Firefly and Butterfly sprites and their movement rules around a random map. Now we're going to update the project to include collision detection and a new player sprite.

To start with though, we're going to do a little refactoring. The ButterflySprite and FireflySprite classes share pretty much the same movement code and will share exactly the same collision code, so we'll merge the common behaviour into a new abstract EnemySprite class which these will inherit from. We'll also add a protected constructor which will allow us to specify the differences between the inherited sprites and their movement rules.

Read More

Creating a Windows Forms RadioButton that supports the double click event

c# winforms double click radiobutton 0 Comments

Another of the peculiarities of Windows Forms is that the RadioButton control doesn't support double clicking. Granted, it is not often you require the functionality but it's a little odd it's not supported.

As an example, one of our earlier products which never made it to production uses a popup dialog to select a zoom level for a richtext box. Common zoom levels are provided via a list of radio buttons. Rather than the user having to first click a zoom level and then click the OK button, we wanted the user to be able to simply double click an option to have it selected and the dialog close.

Read More