How to get the hyperlink and the hyperlink text dragged from IE in my Control’s drag-drop event?

Compiled from the newsgroup posts by Andy Fish and Brian: You can do this in the DragDrop event handler of your control: [C#] try { //Use e.Data.GetData(‘UniformResourceLocator’) to get the URL System.IO.Stream ioStream= (System.IO.Stream)e.Data.GetData(‘FileGroupDescriptor’); byte[] contents = new Byte[512]; ioStream.Read(contents,0,512); ioStream.Close(); StringBuilder sb = new StringBuilder(); //The magic number 76 is the size of that part of the //FILEGROUPDESCRIPTOR structure before the filename starts – cribbed //from another usenet post. for (int i=76; contents[i] != 0; i++) { sb.Append((char)contents[i]); } if (!sb.ToString(sb.Length-4,4).Equals(‘.url’)) { throw new Exception(‘filename does not end in ’.url’’); } filename = sb.ToString(0,sb.Length-4); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } [VB.Net] Try ’Use e.Data.GetData(‘UniformResourceLocator’) to get the URL System.IO.Stream ioStream= CType(e.Data.GetData(‘FileGroupDescriptor’), System.IO.Stream) Dim contents() As Byte = New Byte(512) {} ioStream.Read(contents,0,512) ioStream.Close() Dim sb As StringBuilder = New StringBuilder() ’The magic number 76 is the size of that part of the ’FILEGROUPDESCRIPTOR structure before the filename starts – cribbed ’from another usenet post. Dim i As Integer For i = 76 To contents(i) 0 Step i + 1 sb.Append(CType(contents(i), Char)) Next If Not sb.ToString(sb.Length-4,4).Equals(‘.url’) Then Throw New Exception(‘filename does not end in ’.url’’) End If filename = sb.ToString(0,sb.Length-4) Catch ex As Exception MessageBox.Show(ex.ToString()) End Try

How come some of the objects are not initialized during deserialization?

This is possible in this case: Say your object graph contains an object A, which has a reference to the object B. Then while deserializing A, the reference B might not be initialized yet. This is because while deserializing, references are deserialized one at a time and when A is deserialized, B might not have been deserialized, yet. You should follow the workaround as follows: [C#] protected MyCustomConstrucotr(SerializationInfo info, StreamingContext context) { this.cachedRefToB = (B)info.GetValue(‘B’, typeof(B)); // At this point cachedRefToB might not be initialized. } // But when this method gets called, after complete serialization, the cachedRefToB will be initialized void IDeserializationCallback.OnDeserialization(object sender) { // At this point cachedRefToB will be initialized. } [VB.Net] protected MyCustomConstrucotr(ByVal info As SerializationInfo, ByVal context As StreamingContext) As Protected Me.cachedRefToB = CType(info.GetValue(‘B’, Type.GetType(B)), B) ’ At this point cachedRefToB might not be initialized. End Function ’ But when this method gets called, after complete serialization, the cachedRefToB will be initialized ’ Your class should implement IDeserializationCallback Sub OnDeserialization(ByVal sender As Object) as IDeserializationCallback.OnDeserialization ’ At this point cachedRefToB will be initialized. End Sub

How do I make my child Form fill the entire mdi client without being maximized?

Here is how it can be done. This takes into account all docked controls (including menus) in the mdi parent form. [C#] private void FillActiveChildFormToClient() { Form child = this.ActiveMdiChild; Rectangle mdiClientArea = Rectangle.Empty; foreach(Control c in this.Controls) { if(c is MdiClient) mdiClientArea = c.ClientRectangle; } child.Bounds = mdiClientArea; } [VB.Net] Private Sub FillActiveChildFormToClient() Dim child As Form = Me.ActiveMdiChild Dim mdiClientArea As Rectangle = Rectangle.Empty Dim c As Control For Each c In Me.Controls If TypeOf c Is MdiClient Then mdiClientArea = c.ClientRectangle End If Next child.Bounds = mdiClientArea End Sub

How do I get a count of the gdi handles currently in use in my application?

You can do so using the native GetGuiResources api. Here is a sample: /// /// uiFlags: 0 – Count of GDI objects /// uiFlags: 1 – Count of USER objects /// – Win32 GDI objects (pens, brushes, fonts, palettes, regions, device contexts, bitmap headers) /// – Win32 USER objects: /// – WIN32 resources (accelerator tables, bitmap resources, dialog box templates, font resources, menu resources, raw data resources, string table entries, message table entries, cursors/icons) /// – Other USER objects (windows, menus) /// [DllImport(‘User32’)] extern public static int GetGuiResources(IntPtr hProcess, int uiFlags); public static int GetGuiResourcesGDICount() { return GetGuiResources(Process.GetCurrentProcess().Handle, 0); } public static int GetGuiResourcesUserCount() { return GetGuiResources(Process.GetCurrentProcess().Handle, 1); } ’ ’ uiFlags: 0 – Count of GDI objects ’ uiFlags: 1 – Count of USER objects ’ – Win32 GDI objects (pens, brushes, fonts, palettes, regions, device contexts, bitmap headers) ’ – Win32 USER objects: ’ – WIN32 resources (accelerator tables, bitmap resources, dialog box templates, font resources, menu resources, raw data resources, string table entries, message table entries, cursors/icons) ’ – Other USER objects (windows, menus) ’ _ extern Public static Integer GetGuiResources(IntPtr hProcess, Integer uiFlags) Public Shared Function GetGuiResourcesGDICount() As Integer Return GetGuiResources(Process.GetCurrentProcess().Handle,0) End Function Public Shared Function GetGuiResourcesUserCount() As Integer Return GetGuiResources(Process.GetCurrentProcess().Handle,1) End Function