How do I control the position of the context menu when it is invoked via the keyboard?

Normally, the context menu will be shown at the center of the control when the keyboard is used to invoke the context menu of a control (Shift+F10, for example). You can customize the location as follows. Override WndProc in the grid and check if the Message.Msg is WM_CONTEXTMENU (0x007b) If so, check if the Message.LParam is -1, which means this was due to a keyboard message as opposed to the user right-clicking the mouse. Now, call the associated ContextMenu’s Show method explicitly at the selected row position. Make sure NOT to call the base class after showing the menu explicitly. protected override void WndProc(ref Message m) { if(m.Msg == 0x007B /*WM_CONTEXTMENU*/) { // LParam == -1 means that this is due to a keyboard message if((int)m.LParam == -1) { this.contextMenu.Show(); return; } } } [VB.Net] Protected Overrides Sub WndProc(ByRef m As Message) If m.Msg = 0x007B Then ’WM_CONTEXTMENU ’ LParam == -1 means that this is due to a keyboard message If (CType(m.LParam,Integer)) = -1 Then Me.contextMenu.Show() Return End If End If End Sub

In C++, the code ‘MyClass ht;’ creates an object ht on the stack frame. But in C#, this same code compiles, but gives a runtime error. Why

MyClass ht; does not create any object. Instead, it creates a variable (a reference) of type MyClass, and sets its value to null. No object is created. To create an object, you need to explicitly call the class constructor with a new. MyClass ht = new MyClass(); You can also use ht to refer to an instance of MyClass that has been created (with a new) at some other point in your code. MyClass myClass = new MyClass(); …… MyClass ht; …… ht = myClass; // both ht and myClass are references to the same object…

When I add a destructor to a class, why isn’t it hit when my instantiated object goes out of scope

Your managed code doesn’t have a destructor, just a finalizer. The difference is a destructor (as in C++) fires immediately when an object goes out of scope, but a finalizer is run when the CLR’s garbage collector (GC) gets to your object. It’s not deterministic when this will occur, but it’s very unlikely to occur right after the object goes out of scope. It will happen at a later time, however. (from [email protected] on microsoft.public.dotnet.framework.windowsforms)

How do I control the state of my custom verb in my designer?

You have to store a reference to the DesignerVerb instance you create to represent the custom verb. You can then update the state of the verb through this reference. Here is an example: public class MyControlDesigner : ParentControlDesigner { private DesignerVerb removeVerb; private DesignerVerbCollection verbs; … public override /*ParentControlDesigner*/ void Initialize(IComponent component) { //… // Update your designer verb whenever ComponentChanged event occurs. iComponentChangeService = (IComponentChangeService) this.GetService(typeof(IComponentChangeService)); if (iComponentChangeService != null) iComponentChangeService.ComponentChanged += new ComponentChangedEventHandler(this.ComponentChanged); } protected override void Dispose(bool disposing) { … if (iComponentChangeService != null) iComponentChangeService.ComponentChanged -= new ComponentChangedEventHandler(this.ComponentChanged); } public override DesignerVerbCollection Verbs { get { if (this.verbs == null) { this.removeVerb = new DesignerVerb(‘Remove Tab’, new EventHandler(this.OnRemove)); this.verbs = new DesignerVerbCollection(); this.verbs.Add(this.removeVerb); } this.removeVerb.Enabled = (this.Control.Controls.Count > 0); return this.verbs; } } private void UpdateVerbStatus() { if (this.removeVerb != null) this.removeVerb.Enabled = (this.Control.Controls.Count > 0); } private void CheckVerbStatus(object sender, ComponentChangedEventArgs e) { this.UpdateVerbStatus(); } }