Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Pixels not Twips?

Posted on 1999-06-28
2
Medium Priority
?
1,150 Views
Last Modified: 2008-03-03
Is there a way that I can stop using twips and start using pixels?

I want to start a new project and want to be able to type the width, height, and x,y coordinates in pixels instead of twips.

When I enter width = 320 and height =  240 into the property fields for an object, I want the object to be 320 pixels by 240 pixels. I am sick of twips.
0
Comment
Question by:mtriviso
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
VBGuru earned 200 total points
ID: 1520317
Have checked the scale maode property?(for forms). There you get the option to do the same. If you want all the forms yoiu add in your project to have the setting Twips by default. Then add your form into the templates. at
C:\Program Files\DevStudio\VB\Template\Forms
and
C:\Program Files\DevStudio\VB\Template\Projects

You set the coordinate system for a particular object (form or control) using the object’s scale properties and the Scale method. You can use the coordinate system in one of three different ways:
·      Use the default scale.
·      Select one of several standard scales.
·      Create a custom scale.
      
Changing the scale of the coordinate system can make it easier to size and position graphics on a form. For example, an application that creates bar charts in a picture box can change the coordinate system to divide the control into four columns, each representing a bar in the chart. The following sections explain how to set default, standard, and custom scales to change the coordinate system.
Using the Default Scale
Every form and picture box has several scale properties (ScaleLeft, ScaleTop, ScaleWidth, ScaleHeight, and ScaleMode) and one method (Scale) you can use to define the coordinate system. The default scale for objects in Visual Basic places the coordinate (0,0) at the upper-left corner of the object. The default scale uses twips.
If you want to return to the default scale, use the Scale method with no arguments.
Selecting a Standard Scale
Instead of defining units directly, you can define them in terms of a standard scale by setting the ScaleMode property to one of the settings shown in the following table.
ScaleMode setting      Description

0      User-defined. If you set ScaleWidth, ScaleHeight, ScaleTop, or ScaleLeft directly, the ScaleMode property is automatically set to 0.
1      Twips. This is the default scale. There are 1,440 twips to one inch.
2      Points. There are 72 points to one inch.
3      Pixels. A pixel is the smallest unit of resolution on the monitor or printer. The number of pixels per inch depends on the resolution of the device.
4      Characters. When printed, a character is 1/6 of an inch high and 1/12 of an inch wide.
5      Inches.
6      Millimeters.
7      Centimeters.
      
All of the modes in the table, except for 0 and 3, refer to printed lengths. For example, an item that is two units long when ScaleMode is set to 7 is two centimeters long when printed.
' Set scale to inches for this form.
ScaleMode = 5
' Set scale to pixels for picPicture1.
picPicture1.ScaleMode = 3
      
Setting a value for ScaleMode causes Visual Basic to redefine ScaleWidth and ScaleHeight so that they are consistent with the new scale. ScaleTop and ScaleLeft are then set to 0. Directly setting ScaleWidth, ScaleHeight, ScaleTop, or ScaleLeft automatically sets ScaleMode to 0.
Creating a Custom Scale
You can use an object’s ScaleLeft, ScaleTop, ScaleWidth, and ScaleHeight properties to create a custom scale. Unlike the Scale method, these properties can be used either to set the scale or to get information about the current scale of the coordinate system.
Using ScaleLeft and ScaleTop
The ScaleLeft and ScaleTop properties assign numeric values to the upper-left corner of an object. For example, these statements set the value of the upper-left corner for the current form and upper-left corner for a picture box named picArena.
ScaleLeft = 100
ScaleTop = 100
picArena.ScaleLeft = 100
picArena.ScaleTop = 100
      
These scale values are shown in Figure 12.4.
Figure 12.4   The ScaleLeft and ScaleTop properties for a form and a control

      
These statements define the upper-left corner as (100, 100). Although the statements don’t directly change the size or position of these objects, they alter the effect of subsequent statements. For example, a subsequent statement that sets a control’s Top property to 100 places the object at the very top of its container.
Using ScaleWidth and ScaleHeight
The ScaleWidth and ScaleHeight properties define units in terms of the current width and height of the drawing area. For example:
ScaleWidth = 1000
ScaleHeight = 500
      
These statements define a horizontal unit as 1/1,000 of the current internal width of the form and a vertical unit as 1/500 of the current internal height of the form. If the form is later resized, the units remain the same.
Note   ScaleWidth and ScaleHeight define units in terms of the internal dimensions of the object;  these dimensions do not include the border thickness or the height of the menu or caption. Thus, ScaleWidth and ScaleHeight always refer to the amount of room available inside the object. The distinction between internal and external dimensions (specified by Width and Height) is particularly important with forms, which can have a thick border. The units can also differ: Width and Height are always expressed in terms of the container’s coordinate system; ScaleWidth and ScaleHeight determine the coordinate system of the object itself.
      
Setting Properties to Change the Coordinate System
All four of these scale properties can include fractions and they can also be negative numbers. Negative settings for the ScaleWidth and ScaleHeight properties change the orientation of the coordinate system.
The scale shown in Figure 12.5 has ScaleLeft, ScaleTop, ScaleWidth, and Scale Height all set to 100.
Figure 12.5   Scale running from (100, 100) to (200, 200)

      
Using the Scale Method to Change the Coordinate System
A more efficient way to change the coordinate system, other than setting individual properties, is to use the Scale method. You specify a custom scale using this syntax:
[object.]Scale (x1, y1) – (x2, y2)
      
The values of x1 and y1 determine the settings of the ScaleLeft and ScaleTop properties. The differences between the two x-coordinates and the two y-coordinates determine the settings of ScaleWidth and ScaleHeight, respectively. For example, suppose you set the coordinate system for a form by setting end points (100, 100) and (200, 200):
Scale (100, 100)-(200, 200)
      
This statement defines the form as 100 units wide and 100 units high. With this scale in place, the following statement moves a shape control one-fifth of the way across the form:
shpMover.Left = shpMover.Left + 20
      
Specifying a value of x1 > x2 or y1 > y2 has the same effect as setting ScaleWidth or ScaleHeight to a negative value.


0
 
LVL 2

Expert Comment

by:BeedleGuis
ID: 1520318
A twip is a device-independant unit of measurement where as the size of a pixel may change depending upon the resolution of the end-users computer, which is why VB uses only twip's for design time unit of measurment.  Your only other options for using pixels is the TwipsperpixelX and twipsperpixelY properties of the screen object.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question