重拾VB626:color, picutre object, printing

来自MSDN-2001-OCT: Visual Tools and Languages/Visual Studio 6.0 Documentation/Visual Basic Documentation/Using Visual Basic/Programmer’s Guide/Part 2: What Can You Do With Visual Basic/Working with Text and Graphics/

1. Color Value

(1) Visual Basic uses a consistent system for all color properties and graphics methods. A color is represented by a Long integer,and this value has the same meaning in all contexts that specify a color.

(2) There are four ways to specify a color value at run time: RGB function,QBColor function,intrinsic constants,Enter a color value directly. 另外,还可以用system colors(随系统设定而变化)。

2. Color Palette

(1) Visual Basic displays metafiles using the default palette of 16 VGA colors.

(2) The hardware palette contains 256 entries defining the actual RGB values that will be displayed on screen. The system halftone palette is a predefined set of 256 RGB values made available by Windows itself. A logical palette is a set of up to 256 RGB values contained within a bitmap or other image.

Windows can draw using the 256 colors in the hardware palette. Twenty of these 256 colors,called static colors,are reserved by the system and cannot be changed by an application. Static colors include the 16 colors in the default VGA palette (the same as the colors defined by Visual Basic’s QBColor function),plus four additional shades of gray. The system halftone palette always contains these static colors.

The foreground window (the window with focus) determines the 236 nonstatic colors in the hardware palette. Each time the hardware palette is changed,all background windows are redrawn using these colors. If the colors in a background window’s logical palette don’t perfectly match those currently in the hardware palette,Windows will assign the closest match.

On true-color (16-million color) displays,Visual Basic always uses the correct color. On monochrome or 16-color displays,Visual Basic will dither background colors and colors set with the FillColor property. Dithering is a process used to simulate colors not available from the video adapter and display driver.

With 256-color video drivers,you can use up to 256 colors with graphics methods. By default,the 256 colors available in Visual Basic are those in the system halftone palette. Although you can specify an exact color using the RGB function,the actual color displayed will be the closest match from the halftone palette.

Although the default palette for Visual Basic is the system halftone palette,you can also control the display of colors with the PaletteMode and Palette properties of forms,user controls,and user documents. In this case,the color match is much the same,except that colors will be matched to the closest color in the hardware palette.

(3) The PaletteMode property only applies to 256-color displays. On high-color or true-color displays,color selection is handled by the video driver using a palette of 32,000 or 16 million colors respectively. Even if you’re programming on a system with a high-color or true-color display,you still may want to set the PaletteMode,because many of your users may be using 256-color displays.

(4) 总之,为256色系统设计时,在调色板方面有许多需要额外考虑的问题。

3. Using the Picture Object

(1) You could think of the Picture object as a invisible picture box that you can use as a staging area for images:

Private Sub Command1_Click()
   Dim objPic As Picture
   Set objPic = LoadPicture("Butterfly.gif")
   Set Picture1.Picture = objPic
End Sub

(2) There are lots of things you can do with bitmaps,icons,or metafiles in the Windows API,but the Picture object already does most of them for you.

There are now two completely different ways to paint graphics on a window (or blit). You can use BitBlt or StretchBlt on the hDC of an object,or you can use the PaintPicture method on the Picture object or property. If you have an Image control,you can only use PaintPicture because Image controls do not have an hDC.

There is no direct relationship between a Picture.Handle and a PictureBox.hDC. The hDC property of the picture box is the handle provided by the operating system to the device context of the picture box control. The Handle property of the Picture object is actually the handle of the GDI object that is contained in the Picture object.

4. Printing

(1) The code in your application determines the type and quality of print output available from your application. But the users’ printer drivers and printers also impact print quality.

(2) 从程序里打印有3种方法:printform,用打印机列表(控制面板里列出的)里的printer,或者用printer object.

其中Printer object打印效果最好。不过它用起来也最麻烦,要写最多的代码,打图的时候也比较占资源。详见:Printing with the Printer Object。

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...