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 make some properties not browsable in the designer, but browsable in the editor?
Provide the following attributes to your Property: [Browsable(false), EditorBrowsable(EditorBrowsableState.Always)] public bool YourProperty{get{}set{}}
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(); } }
I would like to prevent validation in my textbox when the user clicks on my Cancel button, how do I do this?
Say textBox1 and cancelButton and the control names, then this is how you could do this: [C#] // Handler to the Validating event of the TextBox. private void TextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) { if (!this.cancelButton.Focused) { // Do this only when the cancel button is not clicked. if(invalidState) e.Cancel = true; } } [VB.Net] ’ Handler to the Validating event of the TextBox. Private Sub TextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) If Not Me.cancelButton.Focused Then ’ Do this only when the cancel button is not clicked. If invalidState Then e.Cancel = True End If End If End Sub
Why should I provide a Non-Client border to my Control derived class?
Providing a border in the non-client region of your control rather than in the ClientRectangle has very many advantages: When you include a scrollbar in your control, the scrollbar will appear inside the border, rather than to the outside if you drew the border in the client area. When you allow custom painting of the control, your user will not draw over the NC border. Your own client painting code will be simplified in that you will not have to bother about taking the border into account while painting the client area. The next faq will tell you how to include a non-client border.