VB API Seventh Lesson font application four

Source: Internet
Author: User
Tags textout

SelectClipRgn

Function: Select a new clipping region for a region

Declare Function selectcliprgn Lib "gdi32" Alias "SelectClipRgn" (ByVal hdc as Long, ByVal hRgn as long) as long

Parameter HDC: Device environment handle. HRGN: Identifies the selected region. Return value: Returns a clipping region complexity, which can be one of the following values. Nullregion: the area is empty; Simpleregion: The region is a single rectangle; Complexregion: The region is a plurality of rectangles; Error: Errors occur (previous clipping areas are unaffected).

CreateRectRgn

Create a rectangular area described by points x1,y1 and X2,y2 declare Function createrectrgn Lib "gdi32" (ByVal X1 as Long, ByVal Y1 as Long, ByVal X2 as Long, ByVal Y2 as Long) as long parameter x1,y1 long, upper left corner of the rectangle x, y coordinates x2,y2 long, lower right corner of the rectangle x, y coordinate return value execution succeeds to zone handle, failure is zerosettextalignThe function sets the text alignment for the specified device environment declare function settextalign Lib "gdi32" Alias "SetTextAlign" (ByVal hdc as Long, ByVal wflags as Long) A s long parameter HDC hdc,//device environment handle UINT fmode//Text alignment options Ta_baseline datum points are on the baseline of the body. The Ta_bottom datum point is on the lower boundary of the bounding rectangle. The Ta_top datum point is on the upper boundary of the bounding rectangle. The Ta_center datum points align horizontally with the center of the bounding rectangle. The Ta_left datum point is on the left edge of the bounding rectangle. The Ta_right datum point is on the right edge of the bounding rectangle. Ta_rtlreading for Middle East windows, the text is in right-to-left reading order, as opposed to the default left-to-right. This value is only useful if the selected font is Hebrew or Arabic. TA_NOUPDATECP the current datum point does not change after each text output call. A datum point is the location that is transferred to the body output function. TA_UPDATECP the current datum point changes after each text output call. The current position as the datum point. If the current font has a default vertical baseline (such as kanji), the following values are used in place of the ta_baseline and Ta_center, meaning: The Vta_baseline datum points are on the baseline of the body. The Vta_center datum points are aligned vertically with the center of the bounding rectangle. The default values are Ta_left, Ta_top, and TA_NOUPDATECP. If the function call succeeds, the return value is the previous setting for the text alignment; If the function call fails, the return value is the Gdi_error text application example
Option explicitprivate Declare Function selectcliprgn Lib"GDI32"(ByVal hdc as Long, ByVal hRgn as Long) as Longprivate Declare Function createrectrgn Lib"GDI32"(ByVal X1 as Long, ByVal Y1 as Long, ByVal X2 as Long, ByVal Y2 as Long) as Longprivate Declare Function SetTextColor Lib"GDI32"(ByVal hdc as Long, ByVal crcolor as Long) as Longprivate Declare Function DeleteObject Lib"GDI32"(ByVal hobject as Long) as Longprivate Declare Function createfontindirect Lib"GDI32"Alias"createfontindirecta"(lpLogFont as LOGFONT) as Longprivate Declare Function SelectObject Lib"GDI32"(ByVal hdc as Long, ByVal hobject as Long) as Longprivate Declare Function settextalign Lib"GDI32"(ByVal hdc as Long, ByVal wflags as Long) as Longprivate Declare Function TextOut Lib"GDI32"Alias"Textouta"(ByVal hdc As Long, ByVal x as Long, ByVal y as Long, ByVal lpstring as String, ByVal ncount as Long) as Longprivate Type Rectleft as longtop as longright as longbottom as Longend Type Private Const ta_left=0Private Const ta_right=2Private Const Ta_center=6Private Const ta_top=0Private Const Ta_bottom=8Private Const ta_baseline= -Private Type logfontlfheight as longlfwidth as longlfescapement as longlforientation as longlfweight as Longlfitalic A S bytelfunderline as bytelfstrikeout as bytelfcharset as bytelfoutprecision as bytelfclipprecision as BytelfQuality as Byt Elfpitchandfamily as bytelffacename as String* -End typeprivate M_lf as Logfontprivate NewFont as Longprivate Orgfont as Longpublic Sub charplace (o as Object, txt, x, Y) Dim Throw as Longdim hregion as Longdim R as rectr. Left=x r.right= x + o.textwidth (TXT) *2R.top=Yr.bottom= y + o.textheight (TXT) *2hregion=createrectrgn (R.left, R.top, R.right, R.bottom) Throw=selectcliprgn (O.HDC, hregion) Throw=TextOut (O.HDC, x, y, txt, Len (TXT)) DeleteObject (hregion) End subpublic Sub setalign (o as Object, Top, BaseLine, Botto M, left, Center, right) Dim Vert as Longdim Horz as Longif Top= True Then Vert =ta_topif BaseLine= True Then Vert =Ta_baselineif Bottom= True Then Vert =TA_BOTTOMIF Left= True Then Horz =ta_leftif Center= True Then Horz =Ta_centerif Right= True Then Horz =ta_rightsettextalign o.hdc, Vert Or horzend Sub public Sub setcolor (o as Object, cvalue as Long) Dim Throw as Longt Hrow=SetTextColor (O.HDC, cvalue) End subpublic Sub selectorg (o as Object) Dim Throw as Longnewfont=SelectObject (O.HDC, Orgfont) Throw=DeleteObject (NewFont) End subpublic Sub selectfont (o as Object) NewFont=CreateFontIndirect (M_LF) Orgfont=SelectObject (O.HDC, NewFont) End Sub Public Sub Fontout (text, o as Control, XX, YY) Dim Throw as Longthrow=TextOut (O.HDC, XX, YY, Text, Len (text)) End SubPublic Property Get Width () as Longwidth=M_lf.lfwidthend Property, public property, let Width (ByVal W as Long) m_lf.lfwidth=Wend PropertyPublic Property Get Height () as Longheight=M_lf.lfheightend Property, public property, let Height (ByVal vnewvalue as Long) m_lf.lfheight=vnewvalueend PropertyPublic Property Get escapement () as Longescapement=M_lf.lfescapementend Property, escapement (ByVal vnewvalue as Long) m_lf.lfescapement=vnewvalueend PropertyPublic Property Get Weight () as Longweight=M_lf.lfweightend Property, Weight (ByVal vnewvalue as Long) m_lf.lfweight=vnewvalueend PropertyPublic Property Get Italic () as Byteitalic=M_lf.lfitalicend Property Italic (ByVal vnewvalue as Byte) m_lf.lfitalic=Vnewvalueend PropertyPublic Property Get underline () as Byteunderline=M_lf.lfunderlineend Property Underline (ByVal Vnewvalue as Byte) M_lf.lfunderline=Vnewvalueend PropertyPublic Property Get strikeout () as Bytestrikeout=M_lf.lfstrikeoutend Property Strikeout (ByVal Vnewvalue as Byte) m_lf.lfstrikeout=vnewvalueend PropertyPublic Property Get FaceName () as Stringfacename=m_lf.lffacenameend FaceName (ByVal vnewvalue as String) M_lf.lffacename=vnewvalueend propertyprivate Sub class_initialize () m_lf.lfheight= theM_lf.lfwidth= them_lf.lfescapement=0M_lf.lfweight= -M_lf.lfitalic=0M_lf.lfunderline=0M_lf.lfstrikeout=0m_lf.lfoutprecision=0m_lf.lfclipprecision=0m_lf.lfquality=0m_lf.lfpitchandfamily=0M_lf.lfcharset=0M_lf.lffacename="Arial"+ CHR (0) End Sub

Message response function

Option Explicitdim af as Apifontdim x, y as Integerprivate Sub cmdangle_click () Dim i as IntegerSet af=NothingSet af=New apifontpicture1.cls for i=0To3600Step -af. escapement=IAF. Selectfont picture1x= Picture1.scalewidth/2y= Picture1.scaleheight/2af. Fontout"Comrade Studio", Picture1, X, Yaf. selectorg picture1next iend subprivate Sub cmdheight_click () Dim i as IntegerSet af=NothingSet af=New apifontpicture1.cls for i=0To theStep1Picture1.Clsaf.Height=IAF. Selectfont picture1x= Picture1.scalewidth/2y= Picture1.scaleheight/2af. Fontout"Comrade Studio", Picture1, X, Yaf. selectorg picture1next iend subprivate Sub cmdweight_click () Dim I as Integeri=0Set af=NothingSet af=New apifontpicture1.cls for i=0To3600Step1Picture1.Clsaf.Weight= i *5af. Selectfont picture1x= Picture1.scalewidth/2y= Picture1.scaleheight/2af. Fontout"Comrade Studio", Picture1, X, Yaf. selectorg picture1next iend subprivate Sub cmdwidth_click () Dim i as IntegerSet af=NothingSet af=New apifontpicture1.cls for i=0To theStep1Picture1.Clsaf.Width=IAF. Selectfont picture1x= Picture1.scalewidth/2y= Picture1.scaleheight/2'to add 5 spaces after a stringAf. Fontout"Gay Studio", Picture1, X, Yaf. selectorg picture1next iend subprivate Sub form_load () Picture1.scalemode=3End Sub

Run results

VB API Seventh Lesson font application four

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.