home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / lineco1a / form1.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-09-30  |  4.2 KB  |  122 lines

  1. VERSION 5.00
  2. Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "RICHTX32.OCX"
  3. Begin VB.Form Form1 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Line Count Example"
  6.    ClientHeight    =   4740
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   5085
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   4740
  14.    ScaleWidth      =   5085
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.Timer Timer1 
  17.       Interval        =   25
  18.       Left            =   1680
  19.       Top             =   4200
  20.    End
  21.    Begin VB.PictureBox picLines 
  22.       AutoRedraw      =   -1  'True
  23.       BorderStyle     =   0  'None
  24.       BeginProperty Font 
  25.          Name            =   "MS Serif"
  26.          Size            =   6.75
  27.          Charset         =   0
  28.          Weight          =   400
  29.          Underline       =   0   'False
  30.          Italic          =   0   'False
  31.          Strikethrough   =   0   'False
  32.       EndProperty
  33.       Height          =   4740
  34.       Left            =   0
  35.       ScaleHeight     =   4740
  36.       ScaleWidth      =   495
  37.       TabIndex        =   1
  38.       TabStop         =   0   'False
  39.       Top             =   0
  40.       Width           =   495
  41.    End
  42.    Begin RichTextLib.RichTextBox RichTextBox1 
  43.       Height          =   4695
  44.       Left            =   480
  45.       TabIndex        =   0
  46.       Top             =   0
  47.       Width           =   4575
  48.       _ExtentX        =   8070
  49.       _ExtentY        =   8281
  50.       _Version        =   393217
  51.       Enabled         =   -1  'True
  52.       ScrollBars      =   3
  53.       TextRTF         =   $"Form1.frx":0000
  54.    End
  55. Attribute VB_Name = "Form1"
  56. Attribute VB_GlobalNameSpace = False
  57. Attribute VB_Creatable = False
  58. Attribute VB_PredeclaredId = True
  59. Attribute VB_Exposed = False
  60. 'This Code was Created By Bryan Cairns
  61. 'Also this code is FREE so please do with it as you see fit
  62. 'The procedure is really simple, just use a timer control to call
  63. 'the Drawlines Sub which counts the current lines in a Rich text box
  64. 'and finds the 1st visible line, and the current line
  65. 'then it uses the print function to display the line numbers.
  66. 'Also to speed things up, the Drawlines Sub is called when the user
  67. 'interacts with the Rich text Box.
  68. 'have fun :) Bryan Cairns
  69. 'http://www.html-helper.com
  70. 'cairnsb@html-helper.com
  71. Option Explicit
  72. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  73. Private Const EM_GETLINECOUNT = &HBA
  74. Private Const EM_LINEINDEX = &HBB
  75. Private Const EM_LINELENGTH = &HC1
  76. Private Const EM_GETFIRSTVISIBLELINE = &HCE
  77. Private Sub DrawLines(picTo As PictureBox, RTF As RichTextBox)
  78. Dim iLine As Long, cLine As Long, vLine As Long
  79. 'count the lines
  80. iLine = SendMessage(RTF.hwnd, EM_GETLINECOUNT, ByVal 0&, ByVal 0&)
  81. 'current line
  82. cLine = 1 + RTF.GetLineFromChar(RTF.SelStart)
  83. 'first visible line
  84. vLine = SendMessage(RTF.hwnd, EM_GETFIRSTVISIBLELINE, ByVal 0&, ByVal 0&)
  85. picTo.Cls
  86. picTo.Font = RTF.Font
  87. picTo.ForeColor = &H8000000C
  88. Dim I As Integer
  89. For I = vLine + 1 To iLine
  90. If I <> cLine Then
  91. picTo.ForeColor = &H8000000C
  92. picTo.Print I
  93. If I = cLine Then
  94. picTo.ForeColor = &H80000018
  95. picTo.Print I
  96. End If
  97. End If
  98. Next I
  99. End Sub
  100. Private Sub Form_Load()
  101. RichTextBox1.SelText = RichTextBox1.SelText & "This is an example of how to display" & vbCrLf
  102. RichTextBox1.SelText = RichTextBox1.SelText & "the line count and current line in a Rich Text Box." & vbCrLf
  103. RichTextBox1.SelText = RichTextBox1.SelText & vbCrLf
  104. RichTextBox1.SelText = RichTextBox1.SelText & "cairnsb@html-helper.com"
  105. RichTextBox1.SelStart = 0
  106. picLines.Top = RichTextBox1.Top + 50
  107. picLines.Height = RichTextBox1.Height
  108. DrawLines picLines, RichTextBox1
  109. End Sub
  110. Private Sub RichTextBox1_Change()
  111. DrawLines picLines, RichTextBox1
  112. End Sub
  113. Private Sub RichTextBox1_KeyPress(KeyAscii As Integer)
  114. DrawLines picLines, RichTextBox1
  115. End Sub
  116. Private Sub RichTextBox1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  117. DrawLines picLines, RichTextBox1
  118. End Sub
  119. Private Sub Timer1_Timer()
  120. DrawLines picLines, RichTextBox1
  121. End Sub
  122.