VB6 Tutorial 64: The Screen Object

Posted On 2018-06-06 by VB6Boy
Keywords: visual,basic,vb6,visualbasic,tutorial,basic,beginner
Tags: VB6 Tutorials 
Views: 35


Looking for the more of the VB6 Tutorial? Here is the tutorial index.

One of the objects you can work with in VB6 is the Screen object. This will allow you to find information about the current screen configuration, which will in turn allow you to position your forms and other output in the correct position on the users screen, regardless of the current resolution or dpi settings.

Object

You have come across many controls throughout this tutorial. All the controls i.e CommandButton, Label, TextBox are objects. Besides the form is also an object.

A Collection is an object. If you need a refresher on collections, check out the lesson about collections

Some more examples are Clipboard, Dictionary object, Drive and folder objects, App object, and printer object. There are many. The Screen object is also an object like them.

What is Screen Object?

The one line answer: The screen object corresponds to the visible desktop.

While working with the form's properties, you have set Left, Top, Height and Width properties with a numeric value. Do you know the unit in which they are expressed? They are in twips.

On the printer, 1 inch = 1,440 twips.

Converting twips values into pixels

You can easily convert twips values into pixels using the TwipsPerPixelX and TwipsPerPixelY properties of the screen object.

Your computer screen's resolution:

sWidth = Screen.Width / Screen.TwipsPerPixelX
sHeight = Screen.Height / Screen.TwipsPerPixelY
MsgBox "Resolution is " & sWidth & " X " & sHeight

This will get you the result in pixels.

Properties to know

Have a look at some more properties of the Screen Object.

MouseIcon

The MouseIcon property sets a custom mouse icon.

The MousePointer property

Changes the mouse pointer. But it applies to the current application only.

Example

Screen.MousePointer = vbCross

FontCount and Font properties

The FontCount property gives you the number of fonts for the current display device, and the Fonts property returns the font names.

The following program shows the font names.

Dim i As Integer
For i = 0 To Screen.FontCount - 1
    Print Screen.Fonts(i)
Next i

The ActiveForm property

This property returns the form that is the active window.

The ActiveControl property

Returns the control that has the focus.

Text1.SetFocus
Screen.ActiveForm.Caption = "New Form"
Screen.ActiveControl.Text = "New text"

The ActiveForm and ActiveControl properties also only applies to the current application.

QuickHint:

All the properties except MouseIcon and MousePointer are read-only properties here.

Looking for the more of the VB6 Tutorial? Here is the tutorial index.


About the Author

has posted a total of 101 articles.


Comments On This Post

No comments on this post yet!


Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.


Your IP address is:54.159.91.117

Before you can post, you need to prove you are human. If you log in, this test goes away.


Code Links