| Sam Allen's profileDOT NET PERLSBlogListsSkyDrive | Help |
|
|
Code MovedThis code and post is now entirely moved to Dotnetperls.com. FTS3/SQLite Article MOVEDThe new article is at this locationCustomized Dialog/MessageBox in C# and .NETThere is now a much more complete and detailed article WITH CODE at Dot Net Perls Dot Com--A Customized Dialog...Having studied the Windows UI Guidelines (XP, Vista, etc.) I came to realize that I needed greater control over my dialogs than I could get in C#'s MessageBox.Show() method. I also wanted fewer options in place, to eliminate complexity over things I don't use. In Windows, when you present a dialog, you should usually not use an OK button, but use an action verb as the "accept" button. However, MessageBox.Show() won't let me use verbs (anything from "Go," "Proceed," "Agree," to "Acquiesce"). So, I looked for solutions and thought the simplest would be for me to implement my own MessageBox.Show(). Now, I haven't wrapped everything up perfectly and I need to learn more about reusable components, but I am pretty happy with the result so far. My dialog supports more options, in particular these:
Here are some implementation tricks, to try this at home:
Then just add the window (SpecialDialog.cs) to your projects, and call it the normal way (you will need to fix namespaces, etc.). Please see the new site (link above).Rot13 in C#: MovedNow at this location! DataGridView’s Secrets MOVEDI have this post and more "secrets" at DotNetPerls.com. No ads!SQLite Full-Text Index MOVEDPost now located at Dot Net Perls Dot Com, HERE.Build Macros--MOVEDSee the "remixed" article here. Sorry--I am moving things. The new article is a bit nicer. See you there!Dot Net Perls, Developing and DLL Importin’What has been developing in the world of Dot Net Perls? Here's some stuff I have been doing: C/C++ interoperability. Did you know that using [MarshalAs] is faster than allocating IntPtrs manually and passing them to an unmanaged DLL? Neither did I, but it is. (I also tried changing security settings on the DLL calls, but I need to do more research on that.) Make sure your unmanaged declarations look like this: [DllImport("...")] public static extern int FunctionCall([MarshalAs(UnmanagedType.LPStr)] string a); And then call them normally. This was faster than declaring the parameter as an IntPtr and then converting/freeing it manually. User-defined controls—some tricky issues here. I tried to name some properties X and Y and it ruined my program—make sure to pick different member variable names. There are a lot of little painting issues I have dealt with, but generally they are not too hard to deal with. (My user-defined control is a board grid, with mouse-hover effects, and different colors.) Override methods—these are important. In a user-defined control, use "public override void OnPaint()" to control the painting. Visual Studio will offer a bunch of Intellisense stuff when you type those things. Interesting to look at. I have given up on tooltip balloons in .NET completely; they are buggy. Other people have noticed this, too. Just don't do balloons unless you can't help it. They always find a way to fail. Read more about C/C++; branch prediction; finite state automata. I am still developing my DAWG (Direct Acyclic Word Graph); I am working on some new applications and am considering putting my code/logic into an open source project. Did more benchmarking. Enhanced/rewrote/refactored my MakeDAWG program, which generates a direct acyclic word graph and stores it in file. It is more robust now, and uses my current code to recurse through the trees. I don't think I did much with Excel/Word; maybe more on that soon. Some other hacking but nothing extraordinary. TextBox.AppendText Article MOVEDLook here for this article. I am moving this site to a much better place. Sorry for the inconvenience! Programming Variable Sht--MOVEDThis humor post about variable naming is now located at Dot Net Perls.com. Look at it HERE. Windows Forms Progress; Studying More C#Here are some things I have accomplished in C# recently:
Utility Classes for User Experience; Plural FunctionsI have been working on some cool stuff recently. I have gotten SQLite to a point where I feel capable of doing most things I can think of in it, at least with some effort. I haven't started any more personal projects, and in fact I may have a commercial project to work on soon. Anyways, I have been preparing my coding skills and trying to analyze my progress, and learn how to make that same kind of progress faster in the future. I have written 5 Windows Forms applications, each with a different set of features and a different purpose. One is a reference program with 100,000 definitions; another is a content management system; a third, an image converter and viewer; a traffic monitor; and of course the Scrabble program. The most frustrating thing for me has been having to copy and paste so much code! So I have endeavored to refactor my code as much as possible and pull out the universal, frequently-used, clear, and useful code and put it in a separate file that I can simply reference from every project. This has gone well so far. I have this code set up as a class called UserExperience.cs. Here are the functions I have put in the static class so far:
As mentioned, a separate class I made is called PluralQuick.cs. It is also a static class, and it offers one function: PluralQuick.Plural(). static string Plural(string word, int count) { if (count == 1) return word; else ... // return a plural form of the word } I have used PluralQuick.Plural("box", 2) to get "boxes", etc. It works great and improves the clarity of my code. I investigated several solutions for pluralization, and some were either too heavy (complex, bulky) or no better than this one. It would be nice if there was a single, superior solution, but this will work for now. Plural() is quicker than a heavy-duty library and not had to maintain. I throw an exception if the word cannot be pluralized. The function is meant to be only used for a small set of words that are already known (such as those in the UI). UPDATE: Look for the code in my public folder! System.Data.SQLite AwesomenessOkay, enough of that nasty Excel mess. Here's something exciting and cool: System.Data.SQLite is a public domain project that aims to build a fast and useful API for SQLite (an amazing and small database engine) that works for C# and .NET. I downloaded the executable, installed it, and after some fiddling and restarting of Visual Studio and some frustration, I put the SQLite code in as a replacement for my own SqliteSharp "hack" (well it is just a really primitive Interop interface). Some benchmarks demonstrated that the System.Data.SQLite system is very fast and powerful. I am quite happy with it. I can use all the knowledge I gained from SQL Server Compact Edition and use it with a better, faster open source project. Generic Queue<>: MOVEDThis article is now located at the new site. It is better than ever! Developing an Unabridged Dictionary in .NET and SQLiteUsing the computer as a reference is extremely handy and can make our lives easier. Sometimes, however, I don't want to read anything in-depth or complicated, or even relevant. I just want to look at random things that pique my curiosity. This is not serious research—it is entertainment. One of the things I have always been fascinated with is obscure or rare words in the English language. There are so many of them—and some of them are so odd. On the Project Gutenberg website, an unabridged dictionary from 1913, with about 100,000 definitions and words, is available. The file offered is poorly formatted and contains errors. I used Perl to simplify, clean up, and parse the 40 MB dictionary file. Next, I designed a database structure in which to put these words. I used an SQLite database for instant access and high efficiency. I implemented a clean and pleasant user interface using the .NET framework. Here are some of the features of this program:
Those are the 'features.' Here are some of the techniques I used to enhance and polish the program:
There were a lot of "false starts" with this program—here are some of the things I tried and decided against:
And, finally, here are some things I want to add to the program in the future:
Here are some screenshots of the current version of the Unabridged Dictionary. The user controls are at the bottom of the window. Note how the fonts adjust properly to the different system themes. This is key to keeping the UI looking optimal for (most) users. The program also looks "at home" on XP and performs well on any platform. From left to right: Windows Vista Aero UI, looking at bookmarks menu, with some definitions displayed (Segoe UI font); Windows Standard (old-school) interface, with Tahoma font, with the neighboring words list open; Aero UI with context menu open, which allows you to look up the selected word. The program can display one or many words at once. SQLite Versus SQL Compact: MOVEDThis post has been moved to a new site, Dot Net Perls.com. It is much faster and less annoying than Microsoft Live. See the new article at the new site. |
|
|