C# Archive

Rhino error - This object cannot be modified because it is controlled by a document

So it's been a bit busy recently at work writing up literature review notes, preparing for a visit to Trondheim, Norway, and continuing my research into operational modelling and planning for NHS hospitals. One of the key concepts of the development work I am currently undertaking to solve a research aim is the use of

Excel C# interop - obtaining values from cells

Working with C# and Excel has been discussed on this site before with tips on preventing Excel.exe from hanging and converting integers into Excel column headings. Today's post is a very brief example on how we can extract data from specific cells of an Excel worksheet. Obtaining a value from a specific cell Assuming we

C# - Getting a list of every 'color' from System.Drawing or System.Windows.Media

In C# there are two colour structures in existence for making easy reference to a number of colours without the need to use RGB or Hex codes. However, they tend to be accessible only by typing their name - there isn't an easy way to simply obtain a random colour from these structures. But if

C# WPF - Convert colour to brush for UI styling

Something that may be occasionally frustrating is trying to quickly colour a UI element on a WPF window programmatically when you know the colour code, or maybe even have a 'color' variable storing the colour for you. There can be various ways to do this depending on how you have your colour stored, so this

C# - how to iterate through an enum

Frequently I find I wish to iterate through an enum type to add items to a list or do something with each item. Doing so is simple, but remembering how causes a good few minutes of Google searching, so this post is here as an aid to my memory the next time I wish to

C# adding reference error - Checking a C++ DLL is valid for a C# project

DLLs compatible with C# projects can either be managed or unmanaged. However, if they're unmanaged, they cannot be included in the project using the standard References->Add Reference->Browse->OK method, as only managed DLLs can be added in .net applications in this method. To add unmanaged DLLs you need to use a form of DLLImport, which I

How to install OpenCV - Windows machines

Since 2012 when I first conducted an OpenCV project as part of my Bachelor's dissertation at Keele, I have ended up having to install OpenCV about 4 times on various computers. Today is yet another occasion where the need for an installation of OpenCV has been necessitated but, because of the length of time between

Preventing Excel.exe from hanging when using the Microsoft Excel Interop DLL with C#

So it's been a bit quiet around here recently because I've been mostly working on a client project at the office which hasn't included anything onerous that I felt a quick post would be useful to aid future development. Until now. Part of the work I've been completing has included working with Microsoft Excel through

C# WPF - text box is not editable?

In my current work in the c#/WPF environment, I've had a need to create a new pop-out window with a load of text boxes and labels programmatically depending on a previous input. However, when I ran the code, the text boxes were not selectable, editable or changeable in any way. They just sat there, visible,

Calculating a log normal value from an average and standard deviation

It's been a bit quiet round here recently due to project work at the office primarily with little Grasshopper work and little in the way of interesting snippets. However, one which I've decided to put here for future use is a function to calculate a log normal value from a given average and a given