Microsoft KB Archive/885446

From BetaArchive Wiki

Article ID: 885446

Article Last Modified on 12/3/2007



APPLIES TO

  • Microsoft .NET Framework 1.1 Service Pack 1




SYMPTOMS

When you use the Show method in a COM client application to show a Microsoft Windows Form, the form may not work as expected. This issue occurs if the computer is running the Microsoft .NET Framework 1.1 Service Pack 1 (SP1).

For example, when you show a Windows Form through a Microsoft Visual Basic 6.0 application or through a Microsoft Foundation Classes (MFC) application, you may experience one or more of the following symptoms:

  • When you press TAB, the control focus does not change from one control to another control.
  • When you press ENTER while a command button has focus, the button's Click event does not occur.

You may experience other unexpected behavior for keystrokes or for mouse activity.

CAUSE

This behavior occurs because the message loop that the Windows Forms uses and the message loop that the COM client applications provide are different. Windows Forms were initially not designed to be used in COM client applications. We made a design change to address this behavior. For more information about other ways to show a Windows Forms form in a COM client application, click the following article number to view the article in the Microsoft Knowledge Base:

839076 You experience unexpected behavior when you use Windows Forms in COM client applications


RESOLUTION

Software update information

A supported software update is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This software update may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next Microsoft .NET Framework 1.1 service pack that contains this software update.

To resolve this problem immediately, contact Microsoft Product Support Services to obtain the software update. For a complete list of Microsoft Product Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:

Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.

Prerequisites

You must have the Microsoft .NET Framework 1.1 installed to apply this software update.

Restart requirement

You do not have to restart the computer after you apply this software update.

Software update replacement information

This software update does not replace any other software updates.

File information

The English version of this software update has the file attributes (or later file attributes) that are listed in the following table. The dates and times for these files are listed in Coordinated Universal Time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.

   Date         Time   Version        Size       File name
   ----------------------------------------------------------------------
   14-Oct-2004  02:43  1.1.4322.2038  2,052,096  System.windows.forms.dll

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

Steps to reproduce the behavior

  1. Start Microsoft Visual Studio .NET 2003.
  2. Create a class library. To do this, follow these steps:
    1. Use Visual Basic .NET 2003 to create a Class Library project. Name the project NetFormsLib.
    2. In Solution Explorer, right-click NetFormsLib, and then click Properties.
    3. In the NetFormsLib property page, click Configuration Properties, click Build, click Register for COM Interop, and then click OK.
    4. In Solution Explorer, rename the Class.vb file. Name the file ComClass.vb.
    5. In Solution Explorer, double-click ComClass.vb. Replace the existing code with the following code sample.

      Imports System.Threading
      Imports System.Windows.Forms
       
      <ComClass(ComClass.ClassId, ComClass.InterfaceId, ComClass.EventsId)> _
      Public Class ComClass
       
      #Region "COM GUIDs"
          ' These  GUIDs provide the COM identity for this class 
          ' and its COM interfaces. If you change these GUIDs, existing 
          ' clients will no longer be able to access the class.
          Public Const ClassId As String = "4545D4A2-E761-45a8-934E-6165AE6C79CF"
          Public Const InterfaceId As String = "51D0003D-8E72-4bd4-99BC-9E763B2B823B"
          Public Const EventsId As String = "1FBAF934-960E-49a3-9E05-47BAAA04C414"
      #End Region
       
          Private netfrm As NetForm
       
          ' A creatable COM class must have a Public Sub New object 
          ' that has no parameters. Otherwise, the class will not be 
          ' registered in the COM registry and cannot be created 
          ' by using the CreateObject method.
          Public Sub New()
              MyBase.New()
          End Sub
       
          Public Sub ShowNETForm()
       
              If ShowNetFormFlag = False Then
                  netfrm = New NetForm
                  netfrm.Show()
                  ShowNetFormFlag = True
              Else
                  netfrm.Activate()
              End If
          End Sub
      End Class
    6. On Project menu, click Module. Name the module Flag.vb. Click Open.
    7. Replace the existing code with the following code sample.

      Module Flag
          Friend ShowNetFormFlag As Boolean = False
      End Module
    8. On the Project menu, click Add Windows Form. Name the form NetForm.vb. Click Open.
    9. Replace the existing code with the following code sample.

       
      Imports System.Windows.Forms
       
      Friend Class NetForm
          Inherits System.Windows.Forms.Form
       
      #Region " Windows Form Designer generated code "
       
          Public Sub New()
              MyBase.New()
       
              'Windows Forms Designer requires this call.
              InitializeComponent()
       
              'Add any initialization after the InitializeComponent method call.
       
          End Sub
       
          'The form overrides the dispose method to clean up the component list.
          Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
              If disposing Then
                  If Not (components Is Nothing) Then
                      components.Dispose()
                  End If
              End If
              MyBase.Dispose(disposing)
          End Sub
       
          'Windows Forms Designer requires the following. 
          Private components As System.ComponentModel.IContainer
       
          'NOTE: Windows Forms Designer requires the following procedure.
          'You can modify the procedure by using Windows Forms Designer.  
          'Do not modify the procedure by using the code editor.
          Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
          Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
          Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
          Friend WithEvents cmdHello As System.Windows.Forms.Button
          <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
              Me.TextBox1 = New System.Windows.Forms.TextBox
              Me.TextBox2 = New System.Windows.Forms.TextBox
              Me.TextBox3 = New System.Windows.Forms.TextBox
              Me.cmdHello = New System.Windows.Forms.Button
              Me.SuspendLayout()
              '
              'TextBox1
              '
              Me.TextBox1.Location = New System.Drawing.Point(96, 56)
              Me.TextBox1.Name = "TextBox1"
              Me.TextBox1.Size = New System.Drawing.Size(104, 20)
              Me.TextBox1.TabIndex = 0
              Me.TextBox1.Text = "TextBox1"
              '
              'TextBox2
              '
              Me.TextBox2.Location = New System.Drawing.Point(96, 96)
              Me.TextBox2.Name = "TextBox2"
              Me.TextBox2.Size = New System.Drawing.Size(104, 20)
              Me.TextBox2.TabIndex = 1
              Me.TextBox2.Text = "TextBox2"
              '
              'TextBox3
              '
              Me.TextBox3.Location = New System.Drawing.Point(96, 136)
              Me.TextBox3.Name = "TextBox3"
              Me.TextBox3.Size = New System.Drawing.Size(104, 20)
              Me.TextBox3.TabIndex = 2
              Me.TextBox3.Text = "TextBox3"
              '
              'cmdHello
              '
              Me.cmdHello.Location = New System.Drawing.Point(88, 184)
              Me.cmdHello.Name = "cmdHello"
              Me.cmdHello.Size = New System.Drawing.Size(128, 24)
              Me.cmdHello.TabIndex = 3
              Me.cmdHello.Text = "Hello"
              '
              'NetForm
              '
              Me.AcceptButton = Me.cmdHello
              Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
              Me.ClientSize = New System.Drawing.Size(296, 269)
              Me.Controls.Add(Me.cmdHello)
              Me.Controls.Add(Me.TextBox3)
              Me.Controls.Add(Me.TextBox2)
              Me.Controls.Add(Me.TextBox1)
              Me.Name = "NetForm"
              Me.Text = "NetForm"
              Me.ResumeLayout(False)
       
          End Sub
       
      #End Region
       
          Private Sub cmdHello_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdHello.Click
              MessageBox.Show("Hello from .Net Form")
          End Sub
       
          Private Sub NetForm_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
              ShowNetFormFlag = False
          End Sub
      End Class
    10. On the Build menu, click Build Solution. This step also registers the project for COM interop on this computer.
  3. Create an executable file. To do this, follow these steps:
    1. Start Microsoft Visual Basic 6.0.
    2. Create a standard EXE project.
    3. On the Project menu, click References.
    4. Add a reference to the NetFormsLib type library that was generated when you built the Visual Basic .NET solution in step 2j. If you do not see the NetFormsLib type library in the list, click Browse to manually locate the NetFormsLib type library (.tlb) file.
    5. Add a command button to the form. Change the caption of the button to Show NetForm.
    6. In Form1, replace the existing code with the following code sample.

      Option Explicit
        Private netform As NetFormsLib.ComClass
        
      Private Sub Command1_Click()
        netform.ShowNETForm
      End Sub
       
      Private Sub Form_Load()
        Set netform = New NetFormsLib.ComClass
      End Sub
    7. On the File menu, click Make EXE to compile the project.
  4. Run the compiled Visual Basic 6.0 executable file.
  5. Click Show NetForm. The Windows Form that you created in step 2 appears.
  6. Click inside one of the TextBox controls on the Windows Form, and then press TAB to move between the controls.

    Notice the behavior that is mentioned in the "Symptoms" section.

For more information, click the following article number to view the article in the Microsoft Knowledge Base:

824684 Description of the standard terminology that is used to describe Microsoft software updates


Keywords: kbqfe kbhotfixserver kbbug kbfix kbpubtypekc KB885446