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 2016

FTP Server Easter Eggs

easter egg 0 Comments

I've recently being working on integrating FTP into our CopyTools application. As a result of this, I have been staring at quite a lot at FTP logs as the various tests and processes do their work.

This morning I was running the CopyTools GUI client watching the progress bar climb upwards as I was putting the support through it's final paces. At the same time, the output from the FTP commands were being printed to the debug log. I was idly watching that too, when all of a sudden the following entries appeared

Read More

Error "DEP0001 : Unexpected Error: -1988945902" when deploying to Windows Mobile 10

c# uwp 2 Comments

Last month, I foolishly upgraded my Lumia 630 to a 650 even though I had every intention of abandoning the Windows Mobile platform after watching Microsoft flounder without hope. However, after using an Android phone as an experiment for a couple of weeks, I decided that despite the hardware (a Galaxy S5) being much better than the budget phones I typically buy, I just don't like Android. As Microsoft also reneged on their promise of a Windows 10 upgrade for the 630, I grabbed a 650 to amuse myself with.

Today I wrote a simple UWP application, which was multiple fun learning curves for the price of one, such as XAML, forced use of async/await, and of course the UWP paradigm itself.

Read More

Displaying multi-page tiff files using the ImageBox control and C#

c# winforms imagebox tiff sample 1 Comments Downloads

Earlier this week I received a support request from a user wanting to know if it was possible to display multi-page tiff files using the ImageBox control. As I haven't wrote anything about this control for a while, it seemed a good opportunity for a short blog post.

One you have obtained an Image instance containing your tiff graphic, you can use the GetFrameCount method in conjunction with a predefined FrameDimension object in order to determine how many pages there are in the image.

Read More

Aligning Windows Forms custom controls to text baselines using C#

c# winforms designer 1 Comments Downloads

One of the nice things about the Visual Studio WinForms designers are the guidelines it draws onto design surfaces, aiding you in perfectly positioning your controls. These guidelines are known internally as snap lines, and by default each visual component inheriting from Control gets four of these, representing the values of the control's Margin property.

A problem arises when you have multiple controls that have different heights, and contain a display string - in this case aligning along one edge isn't going to work and will probably look pretty ugly. Instead, you more than likely want to align the different controls so that the text appears on the same line.

Read More

Retrieving font and text metrics using C#

c# interop api GetTextMetrics TEXTMETRIC 0 Comments Downloads

In several of my applications, I need to be able to line up text, be it blocks of text using different fonts, or text containers of differing heights. As far as I'm aware, there isn't a way of doing this natively in .NET, however with a little platform invoke we can get the information we need to do it ourselves.

The GetTextMetrics metrics function is used to obtain metrics based on a font and a device context by populating a TEXTMETRICW structure.

Read More

Creating and restoring bacpac files without using a GUI

azure backup sql sqlpackage restore 0 Comments

Almost all databases I use are SQL Server databases. They are created with hand written SQL scripts and upgraded with hand written SQL scripts - it is very rare I'll use SQL Server Management Studio's (SSMS) designers to work with database objects. When backing up or restoring databases, I have various SQL scripts to do this, which works fine when SQL Server has access to your file system, or you theirs.

This isn't always the case. Last year I replaced our woefully inadequate error logging system with something slightly more robust and modern, and this system is hosted on Microsoft's Azure platform using SaaS. No direct file access there!

Read More

Adding keyboard accelerators and visual cues to a WinForms control

c# winforms keyboard mnemonic 0 Comments Downloads

Some weeks ago I was trying to make parts of WebCopy's UI a little bit simpler via the expedient of hiding some of the more advanced (and consequently less used) options. And to do this, I created a basic toggle panel control. This worked rather nicely, and while I was writing it I also thought I'd write a short article on adding keyboard support to WinForm controls - controls that are mouse only are a particular annoyance of mine.

Below is an fairly simple (but functional) button control that works - as long as you're a mouse user. The rest of the article will discuss how to extend the control to more thoroughly support keyboard users, and you what I describe below in your own controls.

Read More

Implementing events more efficiently in .NET applications

c# clr event 0 Comments

One of the things that frequently annoys me about third party controls (including those built into the .NET Framework) are properties that either aren't virtual, or don't have corresponding change events / virtual methods. Quite often I find myself wanting to perform an action when a property is changed, and if neither of those are present I end up having to create a custom version of the property, and as a rule, I don't like using the new keyword unless there is no other alternati...

Read More

SQL Woes - Mismatched parameter types in stored procedures

sql timeout parameter 0 Comments

We had a report of crashes occurring for certain users when accessing a system. From the stack data in the production logs, a timeout was occurring when running a specific stored procedure. This procedure was written around 5 years ago and is in use in many customer databases without issue. Why would the same SQL suddenly start timing out in one particular database?

The stored procedure in question is called for users with certain permissions to highlight outstanding units of work that their access level permits them to do, and is a fairly popular (and useful) feature of the software.

Read More

Generating code using T4 templates

c# visual studio t4 template 0 Comments

Recently I was updating a library that contains two keyed collection classes. These collections aren't the usual run-of-the-mill collections as they need to be able to support duplicate keys. Normally I'd inherit from KeyedCollection but as with most collection implementations, duplicate keys are not permitted in this class.

I'd initially solved the problem by simply creating my own base class to fit my requirements, and this works absolutely fine. However, this wasn't going to suffice as a long term solution as I don't want that base class to be part of a public API, especially a public API that has nothing to do with offering custom base collections to consumers.

Read More