转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> VB.NET程序 >> 正文
旋转的文本         ★★★★

旋转的文本

作者:闵涛 文章来源:闵涛的学习笔记 点击数:556 更新时间:2009/4/23 18:58:00
<!--StartFragment-->在VB中利用Windows的API函数可以实现很多的VB无法实现的扩展功能,下面的程序介绍的是如何通过调用Windows中的API函数实现文本旋转显示的特级效果。
  首先建立一个工程文件,然后选菜单中的Project | Add Class Module 加入一个新的类文件,并将这个类的Name属性改变为APIFont,然后在类的代码窗口中加入以下的代码:
  Option Explicit
  
  Private Declare Function SelectClipRgn Lib “gdi32”(ByVal hdc As Long, ByVal hRgn As _
  Long) As Long
  Private Declare Function CreateRectRgn Lib “gdi32”(ByVal X1 As Long, ByVal Y1 As _
  Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
  Private Declare Function SetTextColor Lib “gdi32”(ByVal hdc As Long, ByVal crColor As _
  Long) As Long
  Private Declare Function DeleteObject Lib “gdi32”(ByVal hObject As Long) As Long
  Private Declare Function CreateFontIndirect Lib “gdi32” Alias “CreateFontIndirectA” _
  (lpLogFont As LOGFONT) As Long
  Private Declare Function SelectObject Lib “gdi32”(ByVal hdc As Long, ByVal hObject As _
  Long) As Long
  Private 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 Long
  Private Declare Function SetTextAlign Lib “gdi32”(ByVal hdc As Long, ByVal wFlags _
  As Long) As Long
  
  Private Type RECT
   Left As Long
   Top As Long
   Right As Long
   Bottom As Long
  End Type
  
  Private Const TA_LEFT = 0
  Private Const TA_RIGHT = 2
  Private Const TA_CENTER = 6
  Private Const TA_TOP = 0
  Private Const TA_BOTTOM = 8
  Private Const TA_BASELINE = 24
  
  Private Type LOGFONT
   lfHeight As Long
   lfWidth As Long
   lfEscapement As Long
   lfOrientation As Long
   lfWeight As Long
   lfItalic As Byte
   lfUnderline As Byte
   lfStrikeOut As Byte
   lfCharSet As Byte
   lfOutPrecision As Byte
   lfClipPrecision As Byte
   lfQuality As Byte
   lfPitchAndFamily As Byte
   lfFaceName As String * 50
  End Type
  
  Private m_LF As LOGFONT
  Private NewFont As Long
  Private OrgFont As Long
  Public Sub CharPlace(o As Object, txt$, X, Y)
   Dim Throw As Long
   Dim hregion As Long
   Dim R As RECT
  
   R.Left = X
   R.Right = X + o.TextWidth(txt$) * 2
   R.Top = Y
   R.Bottom = Y + o.TextHeight(txt$) * 2
  
   hregion = 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 Sub
  Public Sub SetAlign(o As Object, Top, BaseLine, Bottom, Left, Center, Right)
   Dim Vert As Long
   Dim Horz As Long
  
   If Top = True Then Vert = TA_TOP
   If BaseLine = True Then Vert = TA_BASELINE
   If Bottom = True Then Vert = TA_BOTTOM
   If Left = True Then Horz = TA_LEFT
   If Center = True Then Horz = TA_CENTER
   If Right = True Then Horz = TA_RIGHT
   SetTextAlign o.hdc, Vert Or Horz
  End Sub
  Public Sub setcolor(o As Object, CValue As Long)
   Dim Throw As Long
  
   Throw = SetTextColor(o.hdc, CValue)
  End Sub
  Public Sub SelectOrg(o As Object)
   Dim Throw As Long
  
   NewFont = SelectObject(o.hdc, OrgFont)
   Throw = DeleteObject(NewFont)
  End Sub
  Public 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 Long
  
   Throw = TextOut(o.hdc, XX, YY, text$, Len(text$))
  End Sub
  
  Public Property Get Width() As Long
   Width = m_LF.lfWidth
  End Property
  
  Public Property Let Width(ByVal W As Long)
   m_LF.lfWidth = W
  End Property
  
  Public Property Get Height() As Long
   Height = m_LF.lfHeight
  End Property
  
  Public Property Let Height(ByVal vNewValue As Long)
   m_LF.lfHeight = vNewValue
  End Property
  
  Public Property Get Escapement() As Long
   Escapement = m_LF.lfEscapement
  End Property
  
  Public Property Let Escapement(ByVal vNewValue As Long)
   m_LF.lfEscapement = vNewValue
  End Property
  
  Public Property Get Weight() As Long
   Weight = m_LF.lfWeight
  End Property
  
  Public Property Let Weight(ByVal vNewValue As Long)
   m_LF.lfWeight = vNewValue
  End Property
  
  Public Property Get Italic() As Byte
   Italic = m_LF.lfItalic
  End Property
  
  Public Property Let Italic(ByVal vNewValue As Byte)
   m_LF.lfItalic = vNewValue
  End Property
  
  Public Property Get UnderLine() As Byte
   UnderLine = m_LF.lfUnderline
  End Property
  
  Public Property Let UnderLine(ByVal vNewValue As Byte)
   m_LF.lfUnderline = vNewValue
  End Property
  
  Public Property Get StrikeOut() As Byte
   StrikeOut = m_LF.lfStrikeOut
  End Property
  
  Public Property Let StrikeOut(ByVal vNewValue As Byte)
   m_LF.lfStrikeOut = vNewValue
  End Property
  
  Public Property Get FaceName() As String
   FaceName = m_LF.lfFaceName
  End Property
  
  Public Property Let FaceName(ByVal vNewValue As String)
   m_LF.lfFaceName = vNewValue
  End Property
  
  Private Sub Class_Initialize()
   m_LF.lfHeight = 30
   m_LF.lfWidth = 10
   m_LF.lfEscapement = 0
   m_LF.lfWeight = 400
   m_LF.lfItalic = 0
   m_LF.lfUnderline = 0
   m_LF.lfStrikeOut = 0
   m_LF.lfOutPrecision = 0
   m_LF.lfClipPrecision = 0
   m_LF.lfQuality = 0
   m_LF.lfPitchAndFamily = 0
   m_LF.lfCharSet = 0
   m_LF.lfFaceName = "Arial" + Chr(0)
  End Sub
  在工程文件的Form1中加入一个PictureBox和一个CommandButton控件,然后在Form1的代码窗口中加入以下的代码:
  Option Explicit
  
  Dim AF As APIFont
  Dim X, Y As Integer
  
  Private Sub Command1_Click()
   Dim i As Integer
  
   Set AF = Nothing
   Set AF = New APIFont
   Picture2.Cls
   For i = 0 To 3600 Step 360
   AF.Escapement = i
   AF.SelectFont Picture2
   X = Picture2.ScaleWidth / 2
   Y = Picture2.ScaleHeight / 2
   ''''在字符串后面要加入7个空格
   AF.FontOut “电脑商情报第42期 ”, Picture2, X, Y
   AF.SelectOrg Picture2
   Next i
  End Sub
  
  Private Sub Form_Load()
   Picture2.ScaleMode = 3
  End Sub
  


没有相关教程
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台