How can I Invoke a private interface implementations of an instance using reflection?

Make sure to preface the method/property name with the fully qualified interface name that it belongs to, like this: // In C# // Where someType implements ISomeInterface’s SomeMethod as a private implementation. Type someType = someInstance.GetType(); MethodInfo mi = someType.GetMethod(‘System.Windows.Forms.ISomeInterface.SomeMethod’, BindingFlags.NonPublic | BindingFlags.Instance); if(mi != null) { mi.Invoke(someInsance, new object[]{}); } ’ In VB.Net ’ Where someType implements ISomeInterface’s SomeMethod as a private implementation. Dim someType As Type = someInstance.GetType() MethodInfo mi = someType.GetMethod(‘System.Windows.Forms.ISomeInterface.SomeMethod’, BindingFlags.NonPublic | BindingFlags.Instance) If Not mi Is Nothing Then ’ Assuming no arguments for SomeMethod. mi.Invoke(someInsance, Nothing) End If

How do I implement a Folder Browser class

Below is a technique that uses FolderNameEditor and FolderBrowser classes to implement a solution. You can also use iterop to get a solution. Both the FolderNameEditor and FolderBrowser classes used in this solution are described in the Docs as ‘This type supports the .NET Framework infrastructure and is not intended to be used directly from your code.’ // add a reference to System.Design.DLL using System.Windows.Forms.Design; …………. public class DirBrowser : FolderNameEditor { FolderBrowser fb = new FolderBrowser(); public string Description { set { _description = value; } get { return _description; } } public string ReturnPath { get { return _returnPath; } } public DirBrowser() { } public DialogResult ShowDialog() { fb.Description = _description; fb.StartLocation = FolderBrowserFolder.MyComputer; DialogResult r = fb.ShowDialog(); if (r == DialogResult.OK) _returnPath = fb.DirectoryPath; else _returnPath = String.Empty; return r; } private string _description = ‘Choose Directory’; private string _returnPath = String.Empty; } (Posted by Ryan Farley on the microsoft.public.dotnet.language.csharp newsgroup)

How can I make a ReadOnly TextBox ignore the mousedowns so that you cannot scroll the text or set the cursor

You can do this by deriving the TextBox, overriding the WndProc method and ignoring these mousedowns. [C#] public class MyTextBox : TextBox { protected override void WndProc(ref System.Windows.Forms.Message m) { // WM_NCLBUTTONDOWN WM_LBUTTONDOWN if(this.ReadOnly && (m.Msg == 0xa1 || m.Msg == 0x201)) { return; //ignore it } base.WndProc(ref m); } } [VB.NET] Public Class MyTextBox Inherits TextBox Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) ’ WM_NCLBUTTONDOWN WM_LBUTTONDOWN If Me.ReadOnly AndAlso(m.Msg = &HA1 OrElse m.Msg = &H201) Then Return ’ignore it End If MyBase.WndProc(m) End Sub ’WndProc End Class ’MyTextBox

In an MDI application, the MDI child’s MaximumSize and MinimumSize properties don’t seem to take effect. How can I restrict the size of my MDI child?

It appears that this behavior is a bug that will be corrected in a future .NET release. You can control the size of your child form by adding a Layout event handler for it. Here is a code snippet that imposes the minimum size that you set in its properties. You can also handle it by overriding the form’s WndProc method as explained in this Microsoft KB article. [C#] private void Document_Layout(object sender, System.Windows.Forms.LayoutEventArgs e) { if(this.Bounds.Width < this.MinimumSize.Width) this.Size = new Size(this.MinimumSize.Width, this.Size.Height); if(this.Bounds.Height < this.MinimumSize.Height) this.Size = new Size(this.Size.Width, this.MinimumSize.Height); } [VB.NET] Private Sub Document_Layout(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LayoutEventArgs) Handles MyBase.Layout If (Me.Bounds.Width < Me.MinimumSize.Width) Then Me.Size = New Size(Me.MinimumSize.Width, Me.Size.Height) End If If (Me.Bounds.Height < Me.MinimumSize.Height) Then Me.Size = New Size(Me.Size.Width, Me.MinimumSize.Height) End If End Sub