RichTextBox and Millimeter 
Author Message
 RichTextBox and Millimeter

I'm using a richtextbox control as core for our own tiny
word processor that we plan to include in our application.

Is there a way to determine in millimeter or in twips the
position of the pointed character versus the size of the
richtext box itself ?

Best regards
Jean-Claude



Sun, 05 Sep 2004 15:09:44 GMT  
 RichTextBox and Millimeter
have a stab at it with this...

Drop a textbox on the form to run  the code un-alterd..
    TextBox1
And of Course, a RichTextBox
    RichText1

Code is adapted form the Hyperlink example at
    http://www.vb-world.net/demos/hyperlink/CHyperlinks.cls.html

D.

Option Explicit

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

Private Const EM_GETLINE = &HC4
Private Const EM_LINEFROMCHAR = &HC9
Private Const EM_LINEINDEX = &HBB
Private Const MAXLINELENGTH = 512
Public Sub CalcSpot()

Dim strLine As String
Dim lngLine As Long
Dim lngLineIndex As Long
Dim lngSelStart As Long
Dim lngHWnd As Long
Dim bLine(MAXLINELENGTH - 1) As Byte
Dim i As Integer, iPos As Integer
Dim WhichMode As Integer

    lngHWnd = RichTextBox1.hwnd
    lngSelStart = RichTextBox1.SelStart
    'Get the line number we're on
    lngLine = SendMessage(lngHWnd, EM_LINEFROMCHAR, lngSelStart, 0&)
    lngLineIndex = SendMessage(lngHWnd, EM_LINEINDEX, lngLine, 0&)
    lngSelStart = lngSelStart - lngLineIndex

    bLine(0) = MAXLINELENGTH And 255
    bLine(1) = MAXLINELENGTH \ 256
    'get the line and save it in the byte array
    SendMessage lngHWnd, EM_GETLINE, lngLine, bLine(0)
    For i = 0 To MAXLINELENGTH - 1
      If bLine(i) = 0 Then
        Exit For
      End If
      strLine = strLine & Chr$(bLine(i))
    Next

    WhichMode = vbMillimeters
    'WhichMode = vbInches
    Text1.Text = ScaleX(TextWidth(Mid$(strLine, 1, lngSelStart)),
Me.ScaleMode, WhichMode)

End Sub

Private Sub RichTextBox1_SelChange()
    CalcSpot
End Sub


Quote:
> I'm using a richtextbox control as core for our own tiny
> word processor that we plan to include in our application.

> Is there a way to determine in millimeter or in twips the
> position of the pointed character versus the size of the
> richtext box itself ?

> Best regards
> Jean-Claude



Mon, 06 Sep 2004 01:33:38 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Converting Millimeters to Pixels

2. Twips vs. millimeters

3. Echo RichTextBox to RichTextBox

4. Richtextbox control :programmatically formatting

5. Access2000 RichTextBox

6. Paste RichTextBox contents into Word

7. RichTextBox SelBullet property

8. Getting formatted text from Word into Richtextbox

9. Body Messagge To RichTextBox

10. RichTextBox

11. Populating .RTF file into Richtextbox

12. textfragments / richtextbox

 

 
Powered by phpBB® Forum Software