How to Reinitialize extender provider dependencies (the logic within CanExtend) from within the designer

Parse through all the Controls in the designer and call TypeDescriptor.Refresh() on them. // From inside your custom IDesigner implementation: private void UpdateExtendedProperties() { IDesignerHost idh = this.GetService(typeof(IDesignerHost)) as IDesignerHost; foreach (Component comp in idh.Container.Components) { // Ignoring the Form if ((comp is Control) && ((comp is Form) == false)) { Control ctrl = comp as Control; TypeDescriptor.Refresh(ctrl); } } }

How do I desaturate a specific color?

Jon Skeet provided this solution in the MS Windows Forms News Group. [C#] double greyLevel = original.R * 0.299 + original.G * 0.587 + original.B * 0.144; if (greyLevel > 255) { greyLevel = 255; } Color desaturated = new Color.FromArgb((byte)greyLevel, (byte)greyLevel, (byte)greyLevel); [VB.NET] Dim greyLevel As Double = original.R * 0.299 + original.G * 0.587 + original.B * 0.144 If greyLevel > 255 Then greyLevel = 255 End If Dim desaturated As New Color.FromArgb(CByte(greyLevel), CByte(greyLevel), CByte(greyLevel))

How to serialize properties of items that do not implement IComponent in a collection?

You have to set DesignerSerializationVisibility attribute on the property whose type is a strongly-typed collection to Content. You have to ensure the collection is created at startup or on demand. In order to support serialization of items that do not implement IComponent into your code you have to write a TypeConverter for that class that can convert to InstanceDescriptor. See the documentation on InstanceDescriptor for an example.

How can I make sure I don’t open a second instance modeless dialog that is already opened from my main form

One way to do this is to maintain a list of opened modeless dialogs and check this list before you open a new one to see if one is already present. If you open all these modeless dialog’s from the same ‘main’ form, then you can use the Owned Forms property of that main form to maintain this list of opened dialogs. Below are some code snippets that suggest how you must go about this. Note that your dialog forms need to be able to turn off the ownership. This is done below by adding an Owner field to the dialog form. //sample code that either opens a new dialog or displays an already opened dialog private void button1_Click(object sender, System.EventArgs e) { foreach (Form f in this.OwnedForms) { if (f is Form2) { f.Show(); f.Focus(); return; } } //need a new one Form2 f2 = new Form2(); this.AddOwnedForm(f2); f2.Owner = this; f2.Show(); } //code for form2 public class Form2 : System.Windows.Forms.Form { private System.Windows.Forms.Label label1; public Form Owner; //………….. private void Form2_Closing(object sender, System.ComponentModel.CancelEventArgs e) { Owner.RemoveOwnedForm(this); } }

How do I browse for, and read a text file into an TextBox

You use the Frameworks OpenFileDialog to implement this functionality. using System.Text; using System.IO; …. private void button1_Click(object sender, System.EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = ‘Open text file’ ; dlg.InitialDirectory = @’c:\’ ; dlg.Filter = ‘txt files (*.txt)|*.txt|All files (*.*)|*.*’ ; if(dlg.ShowDialog() == DialogResult.OK) { StreamReader sr = File.OpenText(dlg.FileName); string s = sr.ReadLine(); StringBuilder sb = new StringBuilder(); while (s != null) { sb.Append(s); s = sr.ReadLine(); } sr.Close(); textBox1.Text = sb.ToString(); } }