How To Capture a Text Size Change Within an ActiveX Control (260578)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 3.0
  • Microsoft Internet Explorer (Programming) 3.01
  • Microsoft Internet Explorer (Programming) 3.02
  • Microsoft Internet Explorer (Programming) 4.0
  • Microsoft Internet Explorer (Programming) 4.01
  • Microsoft Internet Explorer (Programming) 4.01 SP1
  • Microsoft Internet Explorer (Programming) 4.01 SP2
  • Microsoft Internet Explorer (Programming) 5
  • Microsoft Internet Explorer (Programming) 5.01
  • Microsoft Internet Explorer (Programming) 5.5

This article was previously published under Q260578

SUMMARY

When you open a page in Microsoft Internet Explorer and you use the Text Size option from the View menu to change text size, multiple properties on the page change.

This article describes how you can catch the property changed event from within an ActiveX Control.

MORE INFORMATION

Microsoft Foundation Classes (MFC) Control

In an MFC control, the AmbientPropertyChange's dispatch ID (DISPID) will be DISPID_UNKNOWN. The following steps show how you can tell if the font changed.

  1. Declare a Private variable in the control:
    LPFONTDISP orgFont;
    					
  2. In the constructor of the control, for example, CMFCControlCtrl, add the following code:
    	if (0 != GetAmbientProperty(DISPID_AMBIENT_FONT, VT_FONT , &orgFont))
    		AfxMessageBox("Ambient property is supported in this container");
    					
  3. Modify OnAmbientPropertyChange as follows:
    void CMFCControlCtrl::OnAmbientPropertyChange(DISPID dispid) 
    {
    
        if (DISPID_UNKNOWN == dispid)
    	{
    		LPFONTDISP pFont = AmbientFont();
    		if (pFont != orgFont)
    			AfxMessageBox("Font Changed");
    	}
    	
    	COleControl::OnAmbientPropertyChange(dispid);
    }
    					

Microsoft Visual Basic Control

In a Visual Basic control, the PropertyName of the AmbientChanged event is an empty string. The following code demonstrates how you can use code to create the empty string with Visual Basic.
Option Explicit
Private orgFontSize As Currency

Private Sub UserControl_AmbientChanged(PropertyName As String)
   If PropertyName = "" Then
       If orgFontSize <> Ambient.Font.Size Then
           MsgBox orgFontSize & " font changed to " & Ambient.Font.Size
           orgFontSize = Ambient.Font.Size
       End If
   End If
       
End Sub

Private Sub UserControl_Show()
   orgFontSize = Ambient.Font.Size
End Sub
				

REFERENCES

For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

Modification Type:MajorLast Reviewed:5/11/2006
Keywords:kbCtrl kbhowto KB260578