smithvoice.com
Pages by tag

10 pages are tagged with CSharp


To check more tags, click here  click to open


Winform Designmode


Summary:

Coding out and about without my libraries drive and hit that old, old, old bug of user controls not making it easy to tell you when you're in Designmode if you nest subclassed UCs. Felt like a noob fool, had to waste time running through all of the forum posts of hacks that still don't work.. till I found this one. It's not mine but it's better than mine in that it works (for me) across the nesting scenarios even when called from a grandchild control. Now I'm glad I forgot my drive :).

The code is in an Anonymous comment, in case that page goes away, I put it here.

Why does the simple DesignMode feature that was spot-on in the VB5/6 era still elude the VS team after ten years of .Net? 

Thanks Anonymous!



Get back the explicit prop


Summary:

Here's one of those things that some of us came cross way back and fixed on our machines and promptly forgot about, but that comes up every time you hit a new machine or machine from a new .Net convert.

A few days ago I told a friend how he could get a few performance gains by modifying the wizarded Entity classes and when I went to his house and sat at his 'puter my fingers called up the prop snippet and got that VS2008 shortie:

public int myProp{ get; set;} 

Ugh, I hate that thing. 

I know that "under the hood" C# creates a hidden variable for that syntax-saccharine shorthand but it gets me that back in the day of VB5/6 when the tool created ANYTHING under the hood all we ever heard from C++ guys was that that practice was shining example of why VB sucked... nothing should be "under the hood."



A couple useful VS Snippets


Summary:

coming from a decade of VB, "msgBox" is what my fingers keep typing whenever I want a dialog. It's so much faster and natural for me than "M..e..s..s..a..g..e..B..o..x. [tab]S..h..[tab]".

There is a C# snippet to save the typing, it's "mbox", yeah that's shorter, but my fingers still go right to the "g" instead of the "b". Thanks to how easy it is to make a snippet this is no longer a problem....

Here's another one that comes in handy: A tweaked class snippet.

80% of the time my classes get refactored into the same regions, "declarations", "public properties", "private property puts" (for internal business rule checking, keeping ...



Saving extended extensions with the FileSaveDialog


Summary:

Neat how MS breaks the old rules of 8.3 with all of the dlls of the Framework, isn't it? The file names started out as direct representations of namespace hierarchies but as with all good intentions that didn't last long; We did however get the thumbs-up on it being a big-company standard to do XXX.XXX.XXX.XXX....XXX files naming to make the files themselves more intutitive.

Little sticky point is how to get the FileSaveDialog to save the darned extended extensions.



Integer-only Textbox


Summary:

I was working on a project today and needed an integer-only textbox and I thought 'don't I have one of these?'

Yep, found it... it's in the free image control eBook.

But I was typing in c#2005 so it had to be ported.

To save you the effort if you need one with braces, here's the port.



Calculating floating holidates


Summary:

When rendering a calendar's dayboxes or creating a company's HR days-off list, figuring out New Years Day, Christmas and Valentines Day are easy, but what about those floating holidays that depend on the instance of the Day in the Month?

This set of utilities gives a dev a lot of options plus offers protection against accidental weird arguments.

What's more, now all floating Holidays a company cares about are simply defined in a config file with month, instance number and/or flag for relative instance position from start or end of the month. (Non-floating holidays are likewise easily defined with a flag for specific Day number.)

Example test harness: start a Winform project, copy the class code to a class file, drop two textboxes on the form (txtDate and txtInstance), add a button to the form, double click on the button and paste this code in the stub:



Simple address formating


Summary:

If you've ever bought address records or hired a company to do DE following a major direct mailing or just had to work a site that gets a lot of address posted you see how how little effort is usually spent on getting address strings into a standard format to help cut down on duplicates and make query results more useful. That's really too bad because it's not that hard to get the lion's share of the raw text into a consistent format.

The simple class below is a good one for your utility library. It takes a raw address string, removes extra spaces then converts direction and street labels to standard abbreviations.



Free-form sorting lists of Objects


Summary:

Both Arrays and Arraylists implement IList which means that they both expose a Sort method. Thing is that for anything custom you have to define exactly how the elements should compare themselves to other elements for a Sort to happen.

Many resources tell you that sorting elements in these "collections" should be done by implementing IComparable and creating a CompareTo method on the item class itself (if it is not a primative that already has one built-in). For example if you have a Person object then they say that you should create a custom hard-coded CompareTo method in the Person class code that takes the LastName public variable and uses that for the comparisons that add up to a sorted list.

The problem comes when you have an object or struct that could be sorted in a few different ways depending on current needs, even a simple Person object might sometimes be more useful sorted on say an Address property instead of just the last name.



VB Must Be Killed!


Summary:

You still here? Cool. You get a special door prize. Here's an autorun exe you can stick on any cd or dvd-rom to kick off an html page.

Use this for your program install cds or to automatically show Aunt Martha a cd full of family pictures.

Like I said, making great looking and highly interactive startup screens with Delphi is a breeze (Can you say DemoShield-killer?) but making great looking web pages only takes a working knowledge of Notepad. The problem is that cd/dvd AutoRuns only work against actual executables. So this is a real executable; It does nothing more than shell the user's default web browser to open an HTML page located in the same folder.

Name the page you want to start "Default.htm" and save it to the root directory of the cd, drop the autorun.exe and autorun.inf text file in the root directory of the cd.



Easy gradient forms


Summary:

Companies know that an app can have all the best functionality but if it doesn't look spiffy it won't sell. Offer users an upgrade that has no difference but pop-up flat buttons and they'll pay the price.

Time was when you wanted to get a gradient background on a form you had to do a lot of API work, and in VB the redraws were never quite quick enough. Plus the complexity of dealing with areas that needed to be repainted vs areas that didn't and setting a forms' controls to match the form gradient of their location led most of us to go for custom controls.

Times have changed.

Create a new vb.net form, add a label (name it "lblTest" and give it a Text value), add a button (name it "butClickMe" and give it a Text value). Doubleclick on the form to bring up code view. Now, navigate to the Paint event and drop in this code:



<< 1 >> 
who is smith     contact smith     rss feed
Since 1997 a place for my stuff, and it if helps you too then all the better smithvoice.com