Tag Archives: c#

I see my ImageComboBox and ToolStripImageComboBox was broken.

So I fixed it. Not sure when it broke. Also I don’t think I shared it before… Anyway, here it is now, and it’s fixed in my full source code archive too. The issue was the native struct pinvoke declaration … Continue reading

Posted in Programming | Tagged , , , | Leave a comment

My custom ToolStripSlider Windows Forms control

In the last post I shared the full source code of my jack-of-all-trades application. Since you can get the code there, I can now share classes and the code for controls, even if they refer to image resources in the … Continue reading

Posted in Programming | Tagged , , , , | Leave a comment

All the c# source code of the last few articles, and then some…

I guess it will never really be ready to share, so here it is… as is. My old share that you’ll find links to in older posts, was shared on OneDrive. This is on Google drive. You’ll find two zip … Continue reading

Posted in Programming | Tagged , | Leave a comment

Ever wondered how code can estimate the size of an image to be saved?

This is an idea I came up with a few years ago, while high on meth, so how clever it really is, is probably debatable. I’d noticed how applications that can save images always have this feature where they tell … Continue reading

Posted in Programming | Tagged , | Leave a comment

Extracting shell images for files and directories in c#

I did share my application’s full source code years ago, but that was way out of date and I should update it at some point. Anyway… my app is mostly an image viewer like the old ACDSee application, and it … Continue reading

Posted in Programming | Tagged , , , , | Leave a comment

Some Task extensions

I’m on a 30 day Facebook ban because I called some Donald Trump supporters white trash. Apparently I, a white South African, am guilty of hate speech and racism against white people. But actual hate speech, often subtle, always insidious, … Continue reading

Posted in Programming | Tagged , | Leave a comment

Here are my Stream extensions, including a c# wrapper for the ReOpenFile Windows API function, and some code that uses my CopyToStreamAsync extension method.

I don’t have many Stream extension methods, in fact there are only two, but I think they are useful. CopyToStreamAsync, an extension to Stream, is an alternative to Stream.CopyToAsync, and is featured in one of my most popular posts. ReOpen, … Continue reading

Posted in Programming | Tagged , , , , , , , , , | Leave a comment

How to pause or resume a process with c#

I wrote this post already, but the plugin I used back then formatted the code badly, so here is the subject again… The code shared today is slightly different to the original post since I have been updating my old … Continue reading

Posted in Programming | Tagged , , | Leave a comment

How to indicate the Windows display is in use (and also enable or disable the screen saver) with c#

Still going through my old code, and I found this… One part of my application is a video player, but if you’ve ever written one and used it to watch a video that’s more than a couple of minutes or … Continue reading

Posted in Programming | Tagged , , | Leave a comment

Using c# to copy, move, rename files, and delete to the recycle bin via SHFileOperation

While we’re on the subject of deleting files as in the last post, I found this old code of mine in the same solution. I don’t use it anymore because I use IFileOperation instead, but this code still works. (The … Continue reading

Posted in General, Programming | Tagged , , | Leave a comment

Some slight overkill for a method that deletes files and directories

Still cleaning up and improving my old code… I found this. It’s a method in my base class for console applications, to handle deleting files. This is something I’ve approached in different ways in different places – even in the … Continue reading

Posted in General, Programming | Tagged , | Leave a comment

Using a Folder Browser Common Dialog in c#

Lately I have been taking my old solution, which contains a large amount of my personal and experimental code, and updating it for Visual Studio 2019, since there are several wizards which help people like me who have missed all … Continue reading

Posted in Programming | Tagged , , | Leave a comment

Saving a collection of images to a high quality GIF animation using c#

I ran into an interesting problem this weekend… I was showing off a feature of my code to my son, and it didn’t work as expected… I have this application with years of my personal code, which I have recently … Continue reading

Posted in Programming | Tagged , | Leave a comment

Easily draw semi-transparent text on an image in c#

I had a requirement to return an image with text on it, and it turns out this is really easy to do in c#. My code is running in a WCF service so my input and outputs are base64-encoded strings, … Continue reading

Posted in Programming | Tagged , | Leave a comment

Subclassing Exception to log some contextual information

Today I arrived at work to find some truly wonderful emails in my inbox, containing the informative error: String or binary data would be truncated. So somewhere in a public method, one of the members of a structure in scope … Continue reading

Posted in Programming | Tagged , | Leave a comment

My poor man’s factory pattern in c# – one way of instantiating all derived classes of an abstract base class

Apologies for deleting yesterday’s post. It used my actual code and the syntax highlighting was broken in my Open Live Writer. This one uses simplified code that I wrote in an example solution, and thus does not involve me sharing … Continue reading

Posted in Programming | Tagged , , | Leave a comment

A straightforward implementation of ISynchronizeInvoke in c#

I ran into an unusual problem the other day… I’m developing a control that under the hood uses one of three implemented fingerprint scanner API’s in c#. My code is not complicated… just use the relevant DLLs and have their … Continue reading

Posted in Programming | Tagged , | Leave a comment

Split a List<T> into smaller lists of size N.

Well, my stupid header (created years ago when I was still a tweaker) promises an occasional descent into madness, so here you go… use this code at your own risk. Every so often I find that I have a generic … Continue reading

Posted in General, Work | Tagged , | Leave a comment

How to initialize an enum from a string or int value in c#

I didn’t know you could do this, but I tried and it seems fine so it’s worth sharing. I’m working in a large code base, where my input might come from a web form, or an imported file, or even … Continue reading

Posted in Programming | Tagged , | Leave a comment

Sample code to send email via gmail in c# (updated)

I wrote a post recently with some code to send email via gmail in c#. The other day, I needed to update it to allow for multiple attachments. Rather than update the original post, I’ve written this new one… (The … Continue reading

Posted in Programming | Tagged , | Leave a comment

Sample code to send email via gmail in c#

For some time, I’ve had a block of code that I copied and pasted all over the place, to send emails via gmail. It didn’t add an attachment, but I needed to do so today. So rather than copy and … Continue reading

Posted in Programming | Tagged , | Leave a comment

Beware of calling Contains in the Where predicate on IQueryable<T> in LINQ to SQL if your collection has more than 2100 items

Recently I ran into a problem I’d never seen before – the 2100 parameter limit in the SQL that’s generated when you call Contains in the IQueryable<T>.Where predicate in LINQ to SQL. To make matters worse, this happened when filtering … Continue reading

Posted in Programming | Tagged , | Leave a comment

How to load a cursor from embedded resources in C#

Last night, being the last night my son was staying with his cousins, I was bored and spent some time looking at some old code. I don’t know if anyone else still uses Windows Forms applications, but in case you … Continue reading

Posted in Programming | Tagged , , | 1 Comment

Beware of WCF POST service methods that receive JSON that contain DateTime values

I ran into a weird problem today… I have a third party that returns some data to our endpoint in JSON format. I created my endpoint, posted JSON to it, and all seemed well. But when the third party posted … Continue reading

Posted in Programming | Tagged , , , | Leave a comment

A SQL helper class that allows executing a query or running a stored procedure, with or without dynamic parameters

A while back I wrote about my extension method to copy a non-generic collection to an array. A commenter pointed out that it isn’t really necessary. Oh well… here is some code that uses it… (If you use this code, … Continue reading

Posted in Database, SQL | Tagged , | 1 Comment

Convert a non-generic collection to an array – my most useful extension method ever…

Funny how things work out… I wrote one of my most simple extension methods years ago, one that converts a non-generic collection to an array (because arrays implement IEnumerable<T> on which I can call Linq extension methods). Lately I find … Continue reading

Posted in Programming | Tagged , , | 2 Comments

How to get the row index in the client side code of a DataItemTemplate in an ASPxGridView column

This was pissing me off for far too long today. I also have a DataItemTemplate with an ASPxHyperlink control in one of my columns of an ASPxGridView. When the user clicks the hyperlink, I need to call a JavaScript function … Continue reading

Posted in Programming | Tagged , , , | 2 Comments

How to add to the Windows recent documents in C#

I realize that I haven’t written anything here for ages… so I looked through my old code for something simple but useful, and found this. If ever you need to add a file to the Windows recent document list, this … Continue reading

Posted in Programming | Tagged , | Leave a comment

How to ensure that a number is always round up to the nearest integer

Yes, this is silly. I never used Math.Ceiling before; so I never even knew what it was for. In my use case, I’m sending SMS messages via a third party WCF service. It works well, but in my own WCF … Continue reading

Posted in Programming | Tagged , | Leave a comment

How to convert Unicode text to plain ASCII

Let’s say you have a string that was input by somebody out of your control… Maybe it got to you via a call to your web service from a remote client, indirectly via somebody else’s software. And you need to … Continue reading

Posted in Programming | Tagged , | Leave a comment

Experimental new C++ operator joke

This is fucking hilarious… Raymond Chen introduced some “new C++ tadpole operators” on his blog. It’s a joke, one that I didn’t get immediately, but what makes it even funnier is that many commenters also didn’t get it. They’re upset … Continue reading

Posted in Programming | Tagged , | Leave a comment

Do NOT cache SSL certificates on the client side – How to post XML asynchronously and read the response using HttpClient in c#

I had one hell of a day yesterday. The evening before, I’d renewed the certificate on a WCF service of ours, because the old one was about to expire. After renewing it, I tested the service to confirm that I … Continue reading

Posted in Programming | Tagged , , , , | Leave a comment

Zipping a directory and including relative directory paths is non-intuitive with DotNetZip

I recently had to write some code to auto-update an application via an FTP server. It uses home-grown code since ClickOnce is too limiting, and is written in a Windows Forms .NET 3.5 Visual Studio 2010 project. It also had … Continue reading

Posted in Programming | Tagged , | Leave a comment

How to implement IDisposable properly

Every so often I write a class with disposable members, so it needs to implement IDisposable. I always copy and paste from one of my other classes, so I figured it would be useful to share the pattern of IDisposable … Continue reading

Posted in Programming | Tagged , | Leave a comment

A pattern for implementing the == operator in C#

I’ve been neglecting this blog for a while because I have very little time to write here… Every now and then I need to implement the == operator on one of my classes; typically because I want to compare two … Continue reading

Posted in Programming | Tagged , , | Leave a comment

A quick and easy way to call a Web Service without the generated configuration

I recently had to call a web service without being able to use the section it adds to the application configuration file. The reason for this is that my project is a class library running in the process of a … Continue reading

Posted in Programming | Tagged , | Leave a comment

How to get the application’s directory in C#

Just a short one today… I always used to forget how to get the path of the directory that my code is running in, and although I did remember it eventually, I also recall that along the way, I found … Continue reading

Posted in Programming | Tagged , | Leave a comment

On the importance of logging exceptions

It’s been a while since I wrote a programming blog-post, so here goes… We developers like to think that our code is perfect, that there are no bugs. But there are always bugs. And even in cases where our code … Continue reading

Posted in Programming | Tagged , | Leave a comment

Fun with c# code – A disabled ProgressBar

I just noticed this post somehow made the top posts list on my recovery blog, so here is an updated version. (Links updated and code repasted; otherwise it is as is from the original.) Incidentally, the code works just fine … Continue reading

Posted in Programming | Tagged , | Leave a comment

Fascinating stuff – found a copy of Stephen Toub’s Managed ThreadPool that used to be hosted on the now defunct GotDotNet.com

I’m still waiting for our sprint planning meeting to start… it’s only at 2PM… so I have spent the whole day reading interesting articles; mostly programming-related. I’ve been feeling more than a little disappointed that the push on all the … Continue reading

Posted in Programming | Tagged , | Leave a comment

Convert a FileStream opened in synchronous mode to one in asynchronous mode, in C#

Raymond Chen published an interesting blog post today explaining how to convert a synchronous file handle to an asynchronous one, via the ReOpenFile Windows API function. But that function is not implemented in the .Net BCL. Thus I wrote a … Continue reading

Posted in Programming | Tagged , , | Leave a comment

How to start an external process that is associated with a file type, and bring it’s window to the front, in C#

I found a number of answers regarding how to do this online, but none worked exactly the way I wanted. This is because I actually have one extra requirement. That is, if the file type does not have an associated … Continue reading

Posted in Programming | Tagged , , , , | Leave a comment

Confused by my own design – behaviour through inheritance – How not to achieve it

I wonder, do we all get to that point where our own code, written days or weeks or months or maybe even years back, makes us ask the question, “How the fuck did I do that?” Everything here refers to … Continue reading

Posted in Programming | Tagged , , | Leave a comment

Playing with Glass windows forms in C#

I’ve mentioned before that I’m a little behind the current technology, in that I am still running Windows 7. Since Aero Glass fell by the wayside in favour of what looks like a mobile user interface, this may not be … Continue reading

Posted in Programming | Tagged , , , | Leave a comment

Playing with Property Grids in C# – Part 2

In Part 1 we saw how easy it is to use a PropertyGrid control for a user interface with user-configurable options. Here we expand on that a little. Customizing the appearance of an enum I mentioned that we will see … Continue reading

Posted in Programming | Tagged , , | Leave a comment

Playing with Property Grids in C# – Part 1

The PropertyGrid Control is a really handy control, well suited for any UI where the user can configure options, since it can display them in a categorized grid, with a description at the bottom for its selected property. The only … Continue reading

Posted in Programming | Tagged , , | Leave a comment

Customize the Windows 7 logon background with C#

Due to the frustration of not having shared or even written any code for a while, I went home last night and coded this little application. It’s trivial, but kind of fun. Update: And tonight, 5th June 2013, I added … Continue reading

Posted in Programming | Tagged , | Leave a comment

How to load an embedded Cursor from resources in C# (Windows Forms)

How to load an embedded cursor from resources – one that has 32-bit colour, is a trick that has eluded me for a long time, until now. Wait. What’s that, you say? The managed Cursor type does not support animated … Continue reading

Posted in Programming | Tagged , | Leave a comment

Still playing with animated Gif images in C#

On this, the last day of my present job (with nothing to do at all), and looking forward to starting the new one, where I may have very little time for blog-writing, to alleviate the boredom I’ve added a bit … Continue reading

Posted in Programming | Tagged , , | Leave a comment

Saving an animated Gif Image with c# in Windows Forms

As mentioned yesterday, you can use the GifEncoder from the Bumpkit class library to save animated Gif image files. In fact, the encoder has no dependencies on the rest of the class library, so I just copied it’s code-file into … Continue reading

Posted in Programming | Tagged , , | Leave a comment