… is not something I’m known for. Being an introvert, I’d rather avoid the uncomfortable dialog. If I can’t avoid it, I want to end it as quickly as possible. My “normal” method is to lay out my argument as logically as possible. If that doesn’t work, I go for the throat and attack the inner most issue at hand. Pulling out the nasty gore and exposing it to daylight, so we can address the core problem and move on as quickly as possible.
So…
I am struggling with my current client. The lead is… um challenging. Let me give you a bit of background.
Read more…
I have several clickonce deployments. And it gets old having to manually increament my version numbers in the AssemblyInfo file especially when my deployment method does that on it’s own.
So… Here’s my solution. Read more…
You have a list of “something” and you want to remove items from the list. I can think of a couple ways to do this.
Remove Items V1:
List myList = new List() { "one", "two", "three" };
// print out the original list
foreach (string item in myList)
Console.WriteLine(item); // one two three
myList.Remove("two");
// print out the new list
foreach (string item in myList)
Console.WriteLine(item); // one three
Remove Items V2:
List myList = new List() { "one", "two", "three" };
// print out the original list
foreach (string item in myList)
Console.WriteLine(item); // one two three
myList = myList.Expect(i => i == "two");
// print out the new list
foreach (string item in myList)
Console.WriteLine(item); // one three
Notes:
The rules for a foreach loop don’t allow you to delete or nullify an object in the collection during the looping, so you need to remove items more directly. For complete objects, this can be a bit harder. Leveraging LINQ can make the task much easier. With the second example, you could use any property/method within the complex object for your comparison. E.G.: IsDirty or ItemFlaggedForDelete().
Ever tried to debug a loop inside a listObject.Range? Use get_Address(). It makes the process a lot easier.
Code: Read more…
Description:
Set a cell’s solid background color using a single user-defined color.
Code: Read more…
Description:
Set a cell’s background color to a vertical gradient using two user-defined colors.
Code: Read more…
Description:
I need to link an list of (string) items into a sentence at runtime. Here’s a short and simple method to handle the commas and ampersand.
Code: Read more…
Description:
WinForm controls placed in a worksheet while it is not at 100% will be positioned incorrectly. Here’s a simple workaround to change the zoom to 100% then revert to the previous setting.
Code: Read more…
Below is code loading and examining an assembly.
Problem:
You want to open an assembly to see what’s inside with as little effort as possible.
Solution:
I’m sure there are easier ways but this works…
Code: Read more…
You can embed items into your WinForm app. So how to do you figure out what you have and the correct path to retreive the items? Here’s a method to show you what’s an embedded resource in your application.
Code:
using System.Diagnostics;
using System.Reflection;
private void ExposeResources()
{
Assembly assembly = Assembly.GetExecutingAssembly();
foreach ( string resource in assembly.GetManifestResourceNames() )
Debug.WriteLine(resource);
}
Usage:
ExposeResources();
Reference:
http://msdn.microsoft.com/en-us/library/aa287526(VS.71).aspx
I’ve embedded images into my app. Now I need to retrieve those images. Here’s code to do it.
Code:
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
...
Image workingImage;
private void LoadImages()
{
Assembly assembly = Assembly.GetExecutingAssembly();
Stream file;
if ( workingImage == null )
{
file = assembly.GetManifestResourceStream(".WorkingAni_32x32.gif");
if (file != null)
{
workingImage = Image.FromStream(file);
}
}
}
Usage:
Change the <AssemblyName> to match your environment. If you can't find the embedded resouce, use my "List Embedded Resources" snippet to find the correct path to your image.
The build action for the image properties must be set to 'Embedded Resource'.
If you are adding a new image, the project MUST BE REBUILT before the image is embedded. Rebuilding the entire solution is an easy way to ensure this gets done.
I found this today. I need to convert an enumeration into a string list to populate a combobox. I had been looking at converters to do the heavy lifting, but realized that I should do the work in the ViewModel. That simplifies the XAML a bit. While I was typing out code to read the enum values from the settings file Resharper showed me a choice… I could use my custom converter or use the one in the Component Model. Well, I’d rather use the framework solution over a custom solution any day. If nothing else it’s less to test.
Here’s an example from MSDN:
using System.ComponentModel;
Enum myServer= Servers.Exchange;
string myServerString = "BizTalk";
Console.WriteLine(TypeDescriptor.GetConverter(myServer).ConvertTo(myServer, typeof(string)));
Console.WriteLine(TypeDescriptor.GetConverter(myServer).ConvertFrom(myServerString));
Enjoy,
References:
MSDN EnumConverter Class
http://msdn.microsoft.com/en-us/library/system.componentmodel.enumconverter.aspx