Programming Windows with C#
Programming Windows(r) with C# (Core Reference) by Charles Petzold ISBN: 0735613702 This is an excellent book for both Windows Forms and GDI+. As the title suggests it is oriented towards C# programmers. VB programmers should have no trouble following along. Petzold writes lucid prose. Update: There is a VB.NET version of this book available now. Programming Microsoft Windows with Microsoft Visual Basic .NET (Core Reference). ISBN: 0735617996.
How can I let the user edit my Multi-Dimensional collection?
This is usually a problem if you have a custom collection type MyCollection which itself can take items of type MyCollection. The problem is because a single instance of a UITypeEditor is used by the framework irrespective of how many types and instances it serves to edit. Which means you cannot start editing your MyCollection from within a MyCollection editor, since the editor is already open. To work around this problem, you can provide a custom editor as follows: public class CustomCollectionEditor : CollectionEditor { // The base class has its own version of this property // cached CollectionForm private CollectionForm collectionForm; public CustomCollectionEditor(Type type) : base(type) { } public override object EditValue( ITypeDescriptorContext context, IServiceProvider provider, object value) { if(this.collectionForm != null && this.collectionForm.Visible) { // If the CollectionForm is already visible, then create a new instance // of the editor and delegate this call to it. BarItemsCollectionEditor editor = new BarItemsCollectionEditor(this.CollectionType); return editor.EditValue(context, provider, value); } else return base.EditValue(context, provider, value); } protected override CollectionForm CreateCollectionForm() { // Cache the CollectionForm being used. this.collectionForm = base.CreateCollectionForm(); return this.collectionForm; } }
Is it possible to cache an assembly to improve performance?
Ngen.exe allows you to install the native image of an assembly into the native image cache, resulting in quicker loading and execution of the assembly. For example: ngen [options] [assemblyName | assemblyPath ] ngen MyAssembly.dll This creates a native image for MyAssembly.dll and installs it to the native image cache. ngen /delete MyAssembly.dll This removes the native image from the cache. It is also important to note that the native image must be created on the end user’s machine, as it is based on the system that creates it.
How can I make the Enter Key behave like the Tab Key and move to the next cell
You can override ProcessCmdKey, catch the Enter Key, and swap it for a Tab key by sending a Tab, and not processing the Enter Key. [C#] public class MyDataGrid : DataGrid { protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData) { if(msg.WParam.ToInt32() == (int) Keys.Enter) { SendKeys.Send(‘{Tab}’); return true; } return base.ProcessCmdKey(ref msg, keyData); } } [VB.NET] Public Class MyDataGrid Inherits DataGrid Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, keyData As System.Windows.Forms.Keys) As Boolean If msg.WParam.ToInt32() = CInt(Keys.Enter) Then SendKeys.Send(‘{Tab}’) Return True End If Return MyBase.ProcessCmdKey(msg, keyData) End Function ’ProcessCmdKey End Class ’MyDataGrid
How do I get the color of a pixel in my bitmap
Use the Bitmap.GetPixel method. [C#] Color c = myBitmap.GetPixel( xPos, yPos); [VB.NET} Dim c as Color = myBitmap.GetPixel( xPos, yPos)