Pixel (pixels)
The smallest element that can be displayed on a screen or printer. Pixels are independent of the screen.
Design of various display types
Microsoft Windows is device-independent-window-based applications can run on many computers with different display resolutions and color concentrations. Similarly, applications written in Visual Basic also run on different types of monitors, which you need to consider when designing your application.
Designing a resolution-independent form
By default, when you change the screen resolution, Microsoft Visual Basic does not change the size of the form and control. This means that a form designed on a screen with a resolution of 640 x 768 will extend beyond the bounds of the screen when running on a screen with a resolution of 480. If you want to create forms and controls that can have the same proportions regardless of the screen resolution you use, you must design the form at the lowest resolution, or add code that changes the form to the program.
The simplest way to avoid size problems is to design the form at a resolution of 640 X 480. If you prefer to work at a higher resolution, you still need to consider how the form will appear at a lower resolution. The way to do this is to preview the size and position of the form using the Form Layout window. You can also use "Resolution Guides" to see which parts of the screen are visible at low resolution. To switch to Resolution Guides, you can right-click in the Form Layout window and select the Resolution Guides menu item from the pop-up menu.
At run time, Visual Basic places the form according to its location at design time. If the design is run at a resolution of X 768 and the form is placed in the lower-right corner of the screen, the form may not be visible when it is running at a lower resolution. To avoid this, you can set the startup position of the form by selecting the Startup Position menu item from the pop-up menu in the form Layout window at design time. Similarly, you can set the position of the form at run time with the code in the following form Load event:
Private Sub Form_Load ()
Me.move 0, 0
End Sub
If you set the left and Top properties of the form to 0, the same effect can be achieved, but the move method can be done in one step.
Visual Basic uses device-independent units of measure, twips, which are used to calculate dimensions and positions. The two properties of the screen object Twipsperpixelx and twipsperpixely can be used to determine the display size of the runtime. By applying these properties, you can write code to adjust the size and position of the form and the control.
Private Sub Setcontrols ()
Dim X as Integer
Dim Y as Integer
X = Screen.twipsperpixelx
Y = screen.twipsperpixely
Select Case X, Y
Case 15, 15
' Resize the control and move the control.
Txtname.height = 200
Txtname.width = 500
Txtname.move 200, 200
' Add code written for other resolutions.
...
End Sub
You also need to know the location of the Visual Basic's own window at design time. If you put the Project window to the right of the screen at high resolution, you will find that it is no longer accessible when you open the project at low resolution.
Design different concentrations of colors
When you design your application, you also need to consider the possible color display capabilities of running application computers. Some computers can display 256 colors or more, while others show only 16 colors. If you design a form with a 256-color palette, dithering (one way to mimic an invalid color) causes some elements on the form to disappear when displayed on a 16-color display.
To avoid this, it is best to limit the colors used by the application to the Windows standard 16 colors. These colors are represented by the color constants of Visual Basic (such as Vbblack, Vbblue, Vbcyan, and so on). If you need more than 16 colors in your application, you should still stick to the standard color for text, buttons, and other interface elements.
"twip" Chinese translation into "twips", which is a screen -independent length unitTo keep the application elements in a consistent way of computing when they are output to different devices. A point of the printer, that we say "pound", equivalent to 20 twips, an inch equivalent to 1440 twips, a centimeter is equivalent to 567 twips, that is, if the length of an object on the screen is 1440 TWIP, will be printed an inch. Since we are accustomed to using "pixels" (that is, the DPI of the screen resolution we often speak) on the screen, the system can set various DPI values, so we must convert "pixels" into "twip" when we enter the numbers directly. When the DPI is set to 96 o'clock (system default), 1 pixels = (1/96) *1440=15 Twip; When DPI is set to 120, 1 pixels = (1/120) *1440=12 Twip. When the DPI is 96 o'clock, if you want the height of the form to be "400" pixels, the width is "300" pixels, the setting value of the property is: height=400x15=6000 twip,width =300x15=4500 Twip. In an VisualBasic application, the screen is an object. The width and Height properties of the screen are reflected in TWIP. The two properties of Twipsperpixelx and twipsperpixely are only hardware-related, regardless of the resolution that can be set on the screen. Dividing width by Twipsperpixelx calculates the horizontal resolution (number of pixels) of the screen, and also divides the height by twipsperpixely to calculate the vertical resolution of the screen. To maintain the physical size of a window or control, simply calculate the ratio between the resolution of the design and the actual runtime, and then adjust the size and relative position of the window and the controls within it, as well as the displayed font size, based on this ratio. You can maintain the physical appearance of windows of the same application under different systems (of course, only the proportions remain the same on different size monitors, the physical size is different). 1, twips (twips) (twips: Unit of measurement, equal to "pound" of 1/20, inches of 1/1,440. There are 567 twips in a centimeter.
Pixel (Pixels): smallest unit of monitor or printer resolution
Right-click the desktop, select Properties, select the Settings tab, and click the Advanced button.
The DPI setting appears inside. Typically "normal size (in. dpi)".
DPI means dpi (Dots per Inch). So we can get the following conversion formula
1 Pixel = 1440 tpi/96 DPI = twips
1 TWIP = dpi/1440 TPI = 0.0666667 Pixels 2,
A general function for converting twips and pixels to each other
Here, by the way, the conversion relationship of several other units in ACCESS
LBS: the unit of measure for the height of the printed character. 1 pounds equals 1/72 inches, or approximately equals 1 centimeters of 1/28.
Inches: 2.54 cm
In general: 1 cm = 8505 pixels
Option
Compare Database
Option
Explicit
Private
Declare
Function
apiGetDC
Lib
"user32"
Alias
"GetDC"
_
(
ByVal
hwnd
As
Long
)
As
Long
Private
Declare
Function
apiReleaseDC
Lib
"user32"
Alias
"ReleaseDC"
_
(
ByVal
hwnd
As
Long
,
ByVal
hdc
As
Long
)
As
Long
Private
Declare
Function
apiGetDeviceCaps
Lib
"gdi32"
Alias
"GetDeviceCaps"
_
(
ByVal
hdc
As
Long
,
ByVal
nIndex
As
Long
)
As
Long
Private
Const
LOGPIXELSX = 88
Private
Const
LOGPIXELSY = 90
Public
Const
DIRECTION_VERTICAL = 1
Public
Const
DIRECTION_HORIZONTAL = 0
‘===============================================================================
‘-函数名称: gFunTwipsToPixels
‘-功能描述: 转换堤到像素
‘-输入参数说明: 参数1:rlngTwips Long 需要转换的堤
‘ 参数2:rlngDirection Long DIRECTION_VERTICAL是Y方向 DIRECTION_HORIZONTAL为X方向
‘-返回参数说明: 转换后像素值
‘-使用语法示例: gFunTwipsToPixels 50,DIRECTION_VERTICAL
‘-参考:
‘-使用注意:
‘-兼容性: 97,2000,XP compatible
‘-作者: 王宇虹(参考微软KB),改进:王宇虹
‘-更新日期: 2002-08-26 ,2002-11-15
‘===============================================================================
Function
gFunTwipsToPixels(rlngTwips
As
Long
, rlngDirection
As
Long
)
As
Long
On
Error
GoTo
Err_gFunTwipsToPixels
Dim
lngDeviceHandle
As
Long
Dim
lngPixelsPerInch
As
Long
lngDeviceHandle = apiGetDC(0)
If
rlngDirection = DIRECTION_HORIZONTAL
Then
‘水平X方向
lngPixelsPerInch = apiGetDeviceCaps(lngDeviceHandle, LOGPIXELSX)
Else
‘垂直Y方向
lngPixelsPerInch = apiGetDeviceCaps(lngDeviceHandle, LOGPIXELSY)
End
If
lngDeviceHandle = apiReleaseDC(0, lngDeviceHandle)
gFunTwipsToPixels = rlngTwips / 1440 * rlngPixelsPerInch
Exit_gFunTwipsToPixels:
On
Error
Resume
Next
Exit
Function
Err_gFunTwipsToPixels:
MsgBox Err.Description, vbOKOnly + vbCritical,
"Error: "
& Err.Number
Resume
Exit_gFunTwipsToPixels
End
Function
‘===============================================================================
‘-函数名称: gFunPixelsToTwips
‘-功能描述: 转换像素到堤
‘-输入参数说明: 参数1:rlngPixels Long 需要转换的像素
‘ 参数2:rlngDirection Long DIRECTION_VERTICAL是Y方向 DIRECTION_HORIZONTAL为X方向
‘-返回参数说明: 转换后堤值
‘-使用语法示例: gFunPixelsToTwips 50,DIRECTION_VERTICAL
‘-参考:
‘-使用注意:
‘-兼容性: 97,2000,XP compatible
‘-作者: 王宇虹(参考微软KB),改进:王宇虹
‘-更新日期: 2002-08-26 ,2002-11-15
‘===============================================================================
Function
gFunPixelsToTwips(rlngPixels
As
Long
, rlngDirection
As
Long
)
As
Long
On
Error
GoTo
Err_gFunPixelsToTwips
Dim
lngDeviceHandle
As
Long
Dim
lngPixelsPerInch
As
Long
lngDeviceHandle = apiGetDC(0)
If
rlngDirection = DIRECTION_HORIZONTAL
Then
‘水平X方向
lngPixelsPerInch = apiGetDeviceCaps(lngDeviceHandle, LOGPIXELSX)
Else
‘垂直Y方向
lngPixelsPerInch = apiGetDeviceCaps(lngDeviceHandle, LOGPIXELSY)
End
If
lngDeviceHandle = apiReleaseDC(0, lngDeviceHandle)
gFunPixelsToTwips = rlngPixels * 1440 / rlngPixelsPerInch
Exit_gFunPixelsToTwips:
On
Error
Resume
Next
Exit
Function
Err_gFunPixelsToTwips:
MsgBox Err.Description, vbOKOnly + vbCritical,
"Error: "
& Err.Number
Resume
Exit_gFunPixelsToTwips
End
Function
Twip and Pixel