Screen Object for Visual Basic 6.0 Users
The Visual Basic 6.0 Screen object has no direct equivalent in Visual Basic 2005, but most of its functionality can be duplicated using the .NET Framework.
In Visual Basic 6.0, the Screen object provides access to the active form and control in your application, provides information about the screen where the application is being displayed, and allows you to control the appearance of the cursor.
In Visual Basic 2005, there is no direct equivalent for the Screen object, but most of its functionality can be duplicated using the .NET Framework.
Visual Basic 2005 does have a Screen property—My.Computer.Screen. Unlike the Visual Basic 6.0 Screen object, My.Computer.Screen only returns read-only information about the screen, such as its device name, its working area, and its color depth. For more information, see
In Visual Basic 6.0, the ActiveControl property of the Screen object is used to determine the control that has focus. The ActiveControl property can be used in a global capacity, such as in Screen.ActiveControl, where the active control on the currently selected form is returned. If a specific form is referenced, for example, Form2.ActiveControl, ActiveControl specifies the control that will have the focus if the referenced form is active.
In Visual Basic 2005, there is no longer a global ActiveControl property; each instance of a form has its own ActiveControl property. When referencing a specific form, this property works just as it did in Visual Basic 6.0. To determine the active control on the currently selected form, you must first iterate through the OpenForms collection and check the ContainsFocus property to determine which form is active.
In Visual Basic 6.0, the ActiveForm property of the Screen object is used to determine which form currently has the focus. If an MDI parent form has the focus, ActiveForm returns the MDI child form that last had the focus.
In Visual Basic 2005, there is no longer a global ActiveForm property. To determine the active form, you must iterate through the OpenForms collection and find the form with its ContainsFocus property set to True.
Visual Basic 2005 MDI parent forms (any forms with IsMDIContainer set to True) have an ActiveMDIChild property that can be used to return the active child form without using the OpenForms collection.
In Visual Basic 6.0, the MousePointer property of the Screen object is used to change the appearance of the cursor; once set it applies to all forms in the application.
In Visual Basic 2005, there is no longer a global MousePointer property; each form has a Cursor property that can be used to change the appearance of the cursor for that form only.
In Visual Basic 6.0, the TwipsPerPixelX and TwipsPerPixelY properties of the Screen object are used to convert screen measurements from a logical twip (the standard unit of measurement in Visual Basic 6.0) to pixels.
In Visual Basic 2005, pixels are the standard unit of measurement; there is no longer any need for conversion.
Code Changes for the Screen Object
The following examples illustrate differences in coding techniques between Visual Basic 6.0 and Visual Basic 2005.
Code Changes for Determining the Active Control
The following code demonstrates copying the text from the currently selected control on the currently selected form to the Clipboard.
' Visual Basic 6.0 If TypeOf Screen.ActiveControl Is TextBox Then Clipboard.SetText Screen.ActiveControl.Text End If
' Visual Basic 2005 Dim i As Integer For i = 0 To My.Application.OpenForms.Count - 1 If My.Application.OpenForms.Item(i).ContainsFocus Then If TypeOf (My.Application.OpenForms.Item(i).ActiveControl) _ Is TextBox Then My.Computer.Clipboard.SetText(My.Application.OpenForms. _ Item(i).ActiveControl.Text) End If End If Next
Code Changes for Determining the Active Form
The following code demonstrates changing the caption of the currently selected form.
' Visual Basic 6.0 Screen.ActiveForm.Caption = "This is the selected form"
Code Changes for Determining the Active Form in an MDI Application
Screen Object Property Equivalencies
The following table lists Visual Basic 6.0 properties and their Visual Basic 2005 equivalents. Links are provided as necessary to topics explaining differences in behavior. Where there is no direct equivalent in Visual Basic 2005, links are provided to topics that present alternatives.
|Visual Basic 6.0||Visual Basic 2005 Equivalent|
New implementation. The behavior for enumerating fonts is different. For more information, see.
New implementation. For more information, see.
New implementation. In Visual Basic 2005, coordinates are in pixels; twips are not used as a unit of measurement.
When a Visual Basic 6.0 application is upgraded to Visual Basic 2005, any Screen object properties are upgraded to their Visual Basic 2005 equivalent. Where there may be differences in behavior, upgrade comments are inserted into the code.