微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

重拾VB623:Fonts, Print, Format, and Selected Text

来自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. Working with Fonts

(1) When you select a TrueType font,it is rendered into the selected point size and displayed as a bitmap on the screen.

When printing,the selected TrueType font or fonts are rendered into the appropriate size and then sent to the printer. Therefore,there is no need for separate screen and printer fonts.

(2) One way to avoid font problems is to distribute the necessary fonts with your application.

You can also program your application to check among the fonts available in the operating system for the fonts you use.

Another way to avoid font problems is to use fonts users are most likely to have on their systems.

(3) Creating Your Own Font Types: The Font class is derived from the StdFont base class and is supported by all controls.

Dim MyFont As New StdFont
With MyFont
. Bold = True
. Name = "Arial"
End With
Set Text1 . Font = MyFont

2. Setting Font characteristics

(1) Name,Size,Bold,Italic,StrikeThrough,Underline,Weight

(2) The order in which you select font properties is important,because not all fonts support all font variations. Set the Name property first. Then you can set any of the Boolean properties,such as Bold and Italic,to True or False.

(3) Some fonts do not support the sizes smaller than 8 points. When you set the Size property for one of these fonts to a size smaller than 8 points,either the Name property or the Size property will automatically change to a different font or a different size.

(4) If the text is specified by a property (such as Text or Caption),then changing a font property applies to all the text in that control.

If the application shows text with the Print method,then changing a font property affects all uses of Print after the property change.

Because changes in font properties apply to all the text in text Boxes and labels,you cannot mix fonts in these controls.

(5) Forms and picture Boxes have an additional font property,FontTransparent. When FontTransparent is True,the background shows through any text displayed on the form or picture Box.

3. displaying Text on Forms and Picture Boxes

(1) To display text on a form or picture Box,use the Print method,preceded by the name of the form or picture Box. To send output text to a printer,use the Print method on the Printer object.

(2) If the form or picture Box is too small to display all the text,the text is cut off.

When you print text to a form,the text appears in a layer behind any controls that have been placed on the form.

(3) Use a semicolon (;) or a comma (,) to separate one item from the next. If you use a semicolon,Visual Basic prints one item after another,without intervening spaces. If you use a comma,Visual Basic skips to the next tab column.

(4) By default,each Print method prints the text and moves to the next line. If there are no items,Print simply skips a line.

By placing a semicolon (or comma) at the end of the first statement,however,you cause the output of the next Print statement to appear on the same line

(5) You can control placement of Print output by specifying the drawing coordinates,using either or both of these techniques:

a) Use the Cls (clear) method to erase a form or picture Box and reset the drawing coordinates to the origin (0,0).

b) Set drawing coordinates with the CurrentX and CurrentY properties.

(6) To erase text selectively,draw a Box with the Line method and fill it with the background color.

By default,forms and picture Boxes use a coordinate system where each unit corresponds to a twip (1,440 twips equal an inch,and approximately 567 twips equal a centimeter). You may want to change the ScaleMode property of the form,picture Box,or Printer object from twips to points,because text height is measured in points.

(7) Before using the Print method,you can use the TextHeight and TextWidth methods to determine where to position the CurrentX and CurrentY properties. TextHeight returns the height of a line of text,taking into account the object’s font size and style.The TextWidth method returns the width of a string,taking into account the object’s font size and style.

4. Formatting Numbers,Dates,and Times

(1) The Format function converts the numeric value to a text string and gives you control over the string’s appearance.

(2) Visual Basic provides several standard formats to use with the Format function. Instead of designating symbols in the format argument,you specify these formats by name in the format argument of the Format function. Always enclose the format name in double quotation marks ("").

(3) To print formatted dates and times,use the Format function with symbols representing date and time.

5. Working with Selected Text

(1) You can control what text is selected by setting the SelStart and SelLength properties.

(2) If you assign a new string to SelText,that string replaces the selected text,and the insertion point is placed just after the end of the newly inserted text.

6. Transferring Text and Graphics with the Clipboard Object

(1) The Clipboard object has no properties or events,but it has several methods that allow you to transfer data to and from the environment’s Clipboard. The Clipboard methods fall into three categories. The GetText and SetText methods are used to transfer text. The GetData and SetData methods transfer graphics. The GetFormat and Clear methods work with both text and graphic formats.

(2)

Private Sub mnucopy_Click ()
Clipboard . Clear
Clipboard . SetText Text1 . SelText
End Sub

Private Sub mnuCut_Click ()
Clipboard . Clear
Clipboard . SetText Text1 . SelText
Text1 . SelText = ""
End Sub

Private Sub mnuPaste_Click ()
Text1 . SelText = Clipboard . GetText()
End Sub

(3) You can actually place several pieces of data on the Clipboard at the same time,as long as each piece is in a different format.

(4) You can use the GetFormat method to determine whether the data on the Clipboard is in a particular format.

7. Understanding the Coordinate System

(1) Every graphical operation described in this chapter (including resizing,moving,and drawing) uses the coordinate system of the drawing area or container.

(2)

(3) When you move or resize a control,you use the coordinate system of the control’s container. If you draw the object directly on the form,the form is the container. If you draw the control inside a frame or picture Box,the frame or the control is the container.

(4) Statements that resize or move a form always express the form’s position and size in twips. When you create code to resize or move a form,you should first check the Height and Width properties of the Screen object to make sure the form will fit on the screen.

(5) The upper-left corner of the screen is always (0,0). The default coordinate system for any container starts with the (0,0) coordinate in the upper-left corner of the container.

(6) twip : By default,all Visual Basic movement,sizing,and graphical-drawing statements use a unit of one twip. A twip is 1/20 of a printer’s point (1,440 twips equal one inch,and 567 twips equal one centimeter). These measurements designate the size an object will be when printed. Actual physical distances on the screen vary according to the monitor size.

8. Changing an Object's Coordinate System

(1) 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.

(2) 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.

(3) 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) 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.

或者这样写更方便:Scale (100,100)-(200,200)

(5) Use the ScaleX and ScaleY methods to convert from one scale mode to another scale mode.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强制返回为文本 -------------------------------- 数字类型的格式化 --------------------------------     固定格式参数:     General Number 普通数字,如可以用来去掉千位分隔号     format$("100,1
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办法, Format 或者FormatDateTime 竟然结果和系统设置的区域语言的日期和时间格式相关。意思是尽管你用诸如 Format(Now, "MM/dd/yyyy"),如果系统的设置格式区域语言的日期和时间格式分隔符是"-",那他还会显示为 MM-dd-yyyy     只有拼凑: <%response.write
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace My ‘全局错误处理,新的解决方案直接添加本ApplicationEvents.vb 到工程即可 ‘添加后还需要一个From用来显示错误。如果到这步还不会则需要先打好基础啦 ‘======================================================== ‘以下事件
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用的爽呀,这篇文章写与2011年,看来我以前没有认真去找这个方法呀。 https://blog.csdn.net/chzjxgd/article/details/6176325 金蝶K3 BOS的插件官方是用VB6编写的,如果  能用.Net下的语言工具开发BOS插件是一件很愉快的事情,其中缘由不言而喻,而本文则是个人首创,实现在了用V
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选中的单元格进行处理 Dim m As Range, tmpStr As String, s As String Dim x As Integer, y As Integer, subStr As String If MsgBox("确定要分列处理吗?请确定分列的数据会覆盖它后面的单元格!", _
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single) 2 Dim path As String, hash As String 3 For Each fil
  Imports MySql.Data.MySqlClient Public Class Form1 ‘ GLOBAL DECLARATIONS Dim conString As String = "Server=localhost;Database=net2;Uid=root;Pwd=123456;" Dim con As New MySqlConnection
‘導入命名空間 Imports ADODB Imports Microsoft.Office.Interop   Private Sub A1() Dim Sql As String Dim Cnn As New ADODB.Connection Dim Rs As New ADODB.Recordset Dim S As String   S = "Provider=OraOLEDB.Oracl
Imports System.IO Imports System.Threading Imports System.Diagnostics Public Class Form1 Dim A(254) As String    Function ping(ByVal IP As Integer) As String Dim IPAddress As String IPAddress = "10.0.
VB运行EXE程序,并等待其运行结束 参考:https://blog.csdn.net/useway/article/details/5494084 Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long Pr