to bakw(凉快狗): 不是!字的宽度得到比较麻烦,可以得到平均宽度,用GetTextMetrics
我是说用GetTextMetrics可以得到字体的平均宽度,不能得到每个字母的宽度!
不晓得你的意思我有一个方法: 如何在程序运行时增加一个新的控件 以VB6为例,加一个Command控件 Private WithEvents NewButton As CommandButton 代码: If NewButton Is Nothing Then Set NewButton = _ Controls.Add("VB.CommandButton", _ "cmdNew", Me) NewButton.Move _ Command1.Left + Command1.Width + 240, _ Command1.Top NewButton.Caption = "New Button" NewButton.Visible = True End If 它的属性如left、Width。Top等你都可以保存在一个数组中! BTW,如果你用的是VB5,那就只有使用动态数组了! 另外你还可以用API函数
讨论点有用得好吗?GetTextMetrics说具体点
GetTextMetrics The GetTextMetrics function fills the specified buffer with the metrics for the currently selected font. BOOL GetTextMetrics( HDC hdc, // handle to device context LPTEXTMETRIC lptm // pointer to text metrics structure );
Parameters hdc Handle to the device context. lptm Pointer to the TEXTMETRIC structure that is to receive the metrics. TEXTMETRIC The TEXTMETRIC structure contains basic information about a physical font. All sizes are given in logical units; that is, they depend on the current mapping mode of the display context. typedef struct tagTEXTMETRIC { // tm LONG tmHeight; LONG tmAscent; LONG tmDescent; LONG tmInternalLeading; LONG tmExternalLeading; LONG tmAveCharWidth; LONG tmMaxCharWidth; LONG tmWeight; LONG tmOverhang; LONG tmDigitizedAspectX; LONG tmDigitizedAspectY; BCHAR tmFirstChar; BCHAR tmLastChar; BCHAR tmDefaultChar; BCHAR tmBreakChar; BYTE tmItalic; BYTE tmUnderlined; BYTE tmStruckOut; BYTE tmPitchAndFamily; BYTE tmCharSet; } TEXTMETRIC;
Members tmHeight Specifies the height (ascent + descent) of characters. tmAscent Specifies the ascent (units above the base line) of characters. tmDescent Specifies the descent (units below the base line) of characters. tmInternalLeading Specifies the amount of leading (space) inside the bounds set by the tmHeight member. Accent s and other diacritical characters may occur in this area. The designer may set this member to zero. tmExternalLeading Specifies the amount of extra leading (space) that the application adds between rows. Since this area is outside the font, it contains no s and is not altered by text output calls in either OPAQUE or TRANSPARENT mode. The designer may set this member to zero. tmAveCharWidth Specifies the average width of characters in the font (generally defined as the width of the letter x). This value does not include the overhang required for bold or italic characters. tmMaxCharWidth Specifies the width of the widest character in the font. tmWeight Specifies the weight of the font. tmOverhang Specifies the extra width per string that may be added to some synthesized fonts. When synthesizing some attributes, such as bold or italic, graphics device interface (GDI) or a device may have to add width to a string on both a per-character and per-string basis. For example, GDI makes a string bold by expanding the spacing of each character and overstriking by an offset value; it italicizes a font by shearing the string. In either case, there is an overhang past the basic string. For bold strings, the overhang is the distance by which the overstrike is offset. For italic strings, the overhang is the amount the top of the font is sheared past the bottom of the font. The tmOverhang member enables the application to determine how much of the character width returned by a GetTextExtentPoint32 function call on a single character is the actual character width and how much is the per-string extra width. The actual width is the extent minus the overhang. tmDigitizedAspectX Specifies the horizontal aspect of the device for which the font was designed. tmDigitizedAspectY Specifies the vertical aspect of the device for which the font was designed. The ratio of the tmDigitizedAspectX and tmDigitizedAspectY members is the aspect ratio of the device for which the font was designed. tmFirstChar Specifies the value of the first character defined in the font. tmLastChar Specifies the value of the last character defined in the font. tmDefaultChar Specifies the value of the character to be substituted for characters not in the font. tmBreakChar Specifies the value of the character that will be used to define word breaks for text justification. tmItalic Specifies an italic font if it is nonzero. tmUnderlined Specifies an underlined font if it is nonzero. tmStruckOut Specifies a strikeout font if it is nonzero. tmPitchAndFamily Specifies information about the pitch, the technology, and the family of a physical font. The four low-order bits of this member specify information about the pitch and the technology of the font. A constant is defined for each of the four bits: Constant Meaning TMPF_FIXED_PITCH If this bit is set the font is a variable pitch font. If this bit is clear the font is a fixed pitch font. Note very carefully that those meanings are the opposite of what the constant name implies. TMPF_VECTOR If this bit is set the font is a vector font. TMPF_TRUETYPE If this bit is set the font is a TrueType font. TMPF_DEVICE If this bit is set the font is a device font. An application should carefully test for qualities encoded in these low-order bits, making no arbitrary assumptions. For example, besides having their own bits set, TrueType and PostScript fonts set the TMPF_VECTOR bit. A monospace bitmap font has all of these low-order bits clear; a proportional bitmap font sets the TMPF_FIXED_PITCH bit. A Postscript printer device font sets the TMPF_DEVICE, TMPF_VECTOR, and TMPF_FIXED_PITCH bits. The four high-order bits of tmPitchAndFamily designate the font's font family. An application can use the value 0xF0 and the bitwise AND operator to mask out the four low-order bits of tmPitchAndFamily, thus obtaining a value that can be directly compared with font family names to find an identical match. For information about font families, see the description of the LOGFONT structure. tmCharSet Specifies the character set of the font. The character set can be one of the following values: ANSI_CHARSETDEFAULT_CHARSETSYMBOL_CHARSETSHIFTJIS_CHARSETHANGUL_CHARSETGB2312_CHARSETCHINESEBIG5_CHARSETOEM_CHARSETJOHAB_CHARSETHEBREW_CHARSETARABIC_CHARSETGREEK_CHARSETTURKISH_CHARSETVIETNAMESE_CHARSETTHAI_CHARSETEASTEUROPE_CHARSETRUSSIAN_CHARSETMAC_CHARSETBALTIC_CHARSET
看见tmAveCharWidth和tmMaxCharWidth了吗? 知道该怎么用了吧
我要VB呀大哥 VB可以做到的,不要否认我要VB代码?我会给你很多分的,另外给你。真的
Dim WithEvents TextBox1 As TextBox Private Sub Command1_Click() Set TextBox1 = Form1.Controls.Add("VB.textbox", "Textbox1") With Form1!TextBox1 .Visible = True .Width = 2000 .Text = "" End With End Sub
msdn中所带的书 hardcore visual basic 5.0的Chapter 9 Writing Code for the Ages 中有一个用vb做的XEditor控件
msdn中所带的书 hardcore visual basic 5.0的Chapter 9 Writing Code for the Ages 中有一个用vb做的XEditor控件
出版社: 中国电力出版社
译作者: Matthcw Curland著
不是!字的宽度得到比较麻烦,可以得到平均宽度,用GetTextMetrics
如何在程序运行时增加一个新的控件
以VB6为例,加一个Command控件
Private WithEvents NewButton As CommandButton
代码:
If NewButton Is Nothing Then
Set NewButton = _
Controls.Add("VB.CommandButton", _
"cmdNew", Me)
NewButton.Move _
Command1.Left + Command1.Width + 240, _
Command1.Top
NewButton.Caption = "New Button"
NewButton.Visible = True
End If
它的属性如left、Width。Top等你都可以保存在一个数组中!
BTW,如果你用的是VB5,那就只有使用动态数组了! 另外你还可以用API函数
The GetTextMetrics function fills the specified buffer with the metrics for the currently selected font. BOOL GetTextMetrics(
HDC hdc, // handle to device context
LPTEXTMETRIC lptm // pointer to text metrics structure
);
Parameters
hdc
Handle to the device context.
lptm
Pointer to the TEXTMETRIC structure that is to receive the metrics. TEXTMETRIC
The TEXTMETRIC structure contains basic information about a physical font. All sizes are given in logical units; that is, they depend on the current mapping mode of the display context. typedef struct tagTEXTMETRIC { // tm
LONG tmHeight;
LONG tmAscent;
LONG tmDescent;
LONG tmInternalLeading;
LONG tmExternalLeading;
LONG tmAveCharWidth;
LONG tmMaxCharWidth;
LONG tmWeight;
LONG tmOverhang;
LONG tmDigitizedAspectX;
LONG tmDigitizedAspectY;
BCHAR tmFirstChar;
BCHAR tmLastChar;
BCHAR tmDefaultChar;
BCHAR tmBreakChar;
BYTE tmItalic;
BYTE tmUnderlined;
BYTE tmStruckOut;
BYTE tmPitchAndFamily;
BYTE tmCharSet;
} TEXTMETRIC;
Members
tmHeight
Specifies the height (ascent + descent) of characters.
tmAscent
Specifies the ascent (units above the base line) of characters.
tmDescent
Specifies the descent (units below the base line) of characters.
tmInternalLeading
Specifies the amount of leading (space) inside the bounds set by the tmHeight member. Accent s and other diacritical characters may occur in this area. The designer may set this member to zero.
tmExternalLeading
Specifies the amount of extra leading (space) that the application adds between rows. Since this area is outside the font, it contains no s and is not altered by text output calls in either OPAQUE or TRANSPARENT mode. The designer may set this member to zero.
tmAveCharWidth
Specifies the average width of characters in the font (generally defined as the width of the letter x). This value does not include the overhang required for bold or italic characters.
tmMaxCharWidth
Specifies the width of the widest character in the font.
tmWeight
Specifies the weight of the font.
tmOverhang
Specifies the extra width per string that may be added to some synthesized fonts. When synthesizing some attributes, such as bold or italic, graphics device interface (GDI) or a device may have to add width to a string on both a per-character and per-string basis. For example, GDI makes a string bold by expanding the spacing of each character and overstriking by an offset value; it italicizes a font by shearing the string. In either case, there is an overhang past the basic string. For bold strings, the overhang is the distance by which the overstrike is offset. For italic strings, the overhang is the amount the top of the font is sheared past the bottom of the font.
The tmOverhang member enables the application to determine how much of the character width returned by a GetTextExtentPoint32 function call on a single character is the actual character width and how much is the per-string extra width. The actual width is the extent minus the overhang. tmDigitizedAspectX
Specifies the horizontal aspect of the device for which the font was designed.
tmDigitizedAspectY
Specifies the vertical aspect of the device for which the font was designed. The ratio of the tmDigitizedAspectX and tmDigitizedAspectY members is the aspect ratio of the device for which the font was designed.
tmFirstChar
Specifies the value of the first character defined in the font.
tmLastChar
Specifies the value of the last character defined in the font.
tmDefaultChar
Specifies the value of the character to be substituted for characters not in the font.
tmBreakChar
Specifies the value of the character that will be used to define word breaks for text justification.
tmItalic
Specifies an italic font if it is nonzero.
tmUnderlined
Specifies an underlined font if it is nonzero.
tmStruckOut
Specifies a strikeout font if it is nonzero.
tmPitchAndFamily
Specifies information about the pitch, the technology, and the family of a physical font.
The four low-order bits of this member specify information about the pitch and the technology of the font. A constant is defined for each of the four bits: Constant Meaning
TMPF_FIXED_PITCH If this bit is set the font is a variable pitch font. If this bit is clear the font is a fixed pitch font. Note very carefully that those meanings are the opposite of what the constant name implies.
TMPF_VECTOR If this bit is set the font is a vector font.
TMPF_TRUETYPE If this bit is set the font is a TrueType font.
TMPF_DEVICE If this bit is set the font is a device font. An application should carefully test for qualities encoded in these low-order bits, making no arbitrary assumptions. For example, besides having their own bits set, TrueType and PostScript fonts set the TMPF_VECTOR bit. A monospace bitmap font has all of these low-order bits clear; a proportional bitmap font sets the TMPF_FIXED_PITCH bit. A Postscript printer device font sets the TMPF_DEVICE, TMPF_VECTOR, and TMPF_FIXED_PITCH bits. The four high-order bits of tmPitchAndFamily designate the font's font family. An application can use the value 0xF0 and the bitwise AND operator to mask out the four low-order bits of tmPitchAndFamily, thus obtaining a value that can be directly compared with font family names to find an identical match. For information about font families, see the description of the LOGFONT structure. tmCharSet
Specifies the character set of the font. The character set can be one of the following values:
ANSI_CHARSETDEFAULT_CHARSETSYMBOL_CHARSETSHIFTJIS_CHARSETHANGUL_CHARSETGB2312_CHARSETCHINESEBIG5_CHARSETOEM_CHARSETJOHAB_CHARSETHEBREW_CHARSETARABIC_CHARSETGREEK_CHARSETTURKISH_CHARSETVIETNAMESE_CHARSETTHAI_CHARSETEASTEUROPE_CHARSETRUSSIAN_CHARSETMAC_CHARSETBALTIC_CHARSET
知道该怎么用了吧
VB可以做到的,不要否认我要VB代码?我会给你很多分的,另外给你。真的
Private Sub Command1_Click()
Set TextBox1 = Form1.Controls.Add("VB.textbox", "Textbox1")
With Form1!TextBox1
.Visible = True
.Width = 2000
.Text = ""
End With
End Sub
Writing Code for the Ages 中有一个用vb做的XEditor控件
Writing Code for the Ages 中有一个用vb做的XEditor控件
[email protected]