Hey, that's pretty cool. You should write an article on it! Wish I could've gotten that JScript call working-- I tried for about half an hour and gave up in disgust. You'd think they would've put a simple expression evaluator in the base class library, eh?
I wrapped it up in a little class for you-- I may use this code myself on a project:
Another way is through DataSets. These are disconnected recordsets you could get from the SQL Server/MSDE (or whatever data provider, so long as it has either an OLE DB provider or classes designed specifically for it using ADO.NET) using a DataAdapter or DataReader (the latter would force you to fill the DataSet yourself).
Using a DataView on a DataTable lets your sort and filter using SQL-like expressions (some simple and aggregate functions are supported, too). See the documentation for the DataView in the .NET Framework SDK for more information.
Also, if you plan on displaying these in a DataGrid, you can also use expressions in the columns.
Notice how classes A and B refer to each other. If I were to do this, there would be a compile error in class A saying more or less that it doesn't know what "B" is. Should I split these classes out into separate class files (.cs)? I don't want to have to make them into separate projects or anything like that.
In C++, I remember being able to create class prototypes, where I could say:
My advice would be to try something out for yourself before you ask a question like this-- not because you annoy people, but because you'll learn more that way. I only ask people for help if it's something I can't get myself.
In this case, it's obvious that you didn't try to compile this code, or you would've found out things like the fact that
return new B();
and that a constructor method doesn't have the word class in its signature. You would've also found out that when you fix all these problems, your code compiles fine! The .NET compiler is pretty smart; it seems to've been built for dummies in some respects. Not that I'm saying yours is a stupid question-- it definitely isn't. I remember having to change my design once on a Java project due to circular references.
the following code:
Bitmap myBitmap = new Bitmap(@"C:\My Documents\My Pictures\GaugeTime.gif");
Graphics g = Graphics.FromImage(myBitmap);
//error is:A Graphics object cannot be created from an image that has an indexed pixel format.
It seems the gif picture is not supported? what should I do?
You'll need to save myBitmap to a stream as a different format (the easiest way, though other ways exist - see the .NET Framework SDK for more information about the Bitmap class). You can do this by creating a MemoryStream, saving the Bitmap as a different format, and then get a Graphics object from that:
using (Bitmap myBitmap = new Bitmap(@"C:\...\GaugeTime.gif"))
using (MemoryStream ms = new MemoryStream())
using (Bitmap newBitmap = new Bitmap(ms))
using (Graphics g = Graphics.FromImage(newBitmap))
// Draw in your image and save it to a new file or something.
The various using statements just dispose the object when it falls out of scope - even if an Exception is thrown for some reason. Each using statement compiles to the following:
using (Bitmap bmp = new Bitmap(32, 32))
// Compiles to...
Bitmap bmp = new Bitmap(32, 32);
if (bmp != null) bmp.Dispose();
If you’re going to ask someone to do your homework for you the night before it’s due, at least try searching for it online before you post! I will give you a clue; there is an article here on CP that covers this.
Or maybe we're trying to help you help yourself. You won't learn anything by being given the answer. Do you think the regulars here learned by being told how to do everything? If you don't understand what you're doing, then learn. There's plenty of resources and as Nick said, there's even an article here on CP about Blowfish encryption using C#.
I just find it slightly strange that you don't even know where to start and yet you are trying to implement blowfish encryption in C#, the night before none-the-less. Did you find the article here on CP?
P/Invoke the SendMessage native API and send the LB_SETITEMHEIGHT (0x01a0) message to the CheckedListBox's Handle.
If you override CreateParams and set the LBS_OWNERDRAWVARIABLE (0x0020) style, then specify the item index in the WPARAM parameter (3rd parameters to SendMessage) to set just a single item's height, otherwise the height is set uniformly for all items.