Click here to Skip to main content
15,916,318 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionCaret Size Pin
Anybloodyid23-Feb-07 7:54
Anybloodyid23-Feb-07 7:54 
AnswerRe: Caret Size Pin
Dave Kreskowiak23-Feb-07 10:25
mveDave Kreskowiak23-Feb-07 10:25 
AnswerRe: Caret Size [modified] Pin
TwoFaced23-Feb-07 11:32
TwoFaced23-Feb-07 11:32 
GeneralRe: Caret Size Pin
Dave Kreskowiak23-Feb-07 14:02
mveDave Kreskowiak23-Feb-07 14:02 
GeneralRe: Caret Size Pin
TwoFaced23-Feb-07 14:31
TwoFaced23-Feb-07 14:31 
GeneralRe: Caret Size Pin
Anybloodyid23-Feb-07 22:53
Anybloodyid23-Feb-07 22:53 
GeneralRe: Caret Size Pin
TwoFaced23-Feb-07 23:51
TwoFaced23-Feb-07 23:51 
GeneralRe: Caret Size Pin
Anybloodyid24-Feb-07 1:22
Anybloodyid24-Feb-07 1:22 
I tried pasting the code into the RTB Class, which already has the Inherits RichTextBox

But still no luck Frown | :(

I have pasted all of the code for the RTB below.

<br />
Option Explicit On<br />
<br />
Imports System<br />
Imports System.Windows.Forms<br />
Imports System.Drawing<br />
Imports System.Runtime.InteropServices<br />
Imports System.Drawing.Printing<br />
<br />
<br />
''' <summary><br />
''' The rich text box print control class was developed by Microsoft, information about<br />
''' this control can be found in your help files at:  <br />
''' ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.KB.v10.en/enu_kbvbnetkb/vbnetkb/811401.htm<br />
''' In general, their intent was to create a rich text box control with print capability<br />
''' embedded into the control.<br />
''' </summary><br />
''' <remarks>This control class replaces the use of the regular RichTextBox control; the<br />
''' purpose of this extension was specifically to facilitate printing the contents<br />
''' of a rich text box control.</remarks><br />
<br />
    Public Class RichTextBoxPrintCtrl<br />
    Inherits RichTextBox<br />
    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)<br />
        If m.Msg = &H444 AndAlso m.WParam.ToInt32 = 1 Then m.WParam = New System.IntPtr(3)<br />
        MyBase.WndProc(m)<br />
    End Sub<br />
        ' Convert the unit that is used by the .NET framework (1/100 inch) <br />
        ' and the unit that is used by Win32 API calls (twips 1/1440 inch)<br />
        Private Const AnInch As Double = 14.4<br />
<br />
        <StructLayout(LayoutKind.Sequential)> _<br />
         Private Structure RECT<br />
            Public Left As Integer<br />
            Public Top As Integer<br />
            Public Right As Integer<br />
            Public Bottom As Integer<br />
        End Structure<br />
<br />
        <StructLayout(LayoutKind.Sequential)> _<br />
        Private Structure CHARRANGE<br />
            Public cpMin As Integer          ' First character of range (0 for start of doc)<br />
            Public cpMax As Integer          ' Last character of range (-1 for end of doc)<br />
        End Structure<br />
<br />
        <StructLayout(LayoutKind.Sequential)> _<br />
        Private Structure FORMATRANGE<br />
            Public hdc As IntPtr             ' Actual DC to draw on<br />
            Public hdcTarget As IntPtr       ' Target DC for determining text formatting<br />
            Public rc As Rect                ' Region of the DC to draw to (in twips)<br />
            Public rcPage As Rect            ' Region of the whole DC (page size) (in twips)<br />
            Public chrg As CHARRANGE         ' Range of text to draw (see above declaration)<br />
        End Structure<br />
<br />
        Private Const WM_USER As Integer = &H400<br />
        Private Const EM_FORMATRANGE As Integer = WM_USER + 57<br />
<br />
        Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wp As IntPtr, ByVal lp As IntPtr) As IntPtr<br />
<br />
        ' Render the contents of the RichTextBox for printing<br />
        '	Return the last character printed + 1 (printing start from this point for next page)<br />
        Public Function Print(ByVal charFrom As Integer, ByVal charTo As Integer, ByVal e As PrintPageEventArgs) As Integer<br />
<br />
            ' Mark starting and ending character <br />
            Dim cRange As CHARRANGE<br />
            cRange.cpMin = charFrom<br />
            cRange.cpMax = charTo<br />
<br />
            ' Calculate the area to render and print<br />
            Dim rectToPrint As RECT<br />
            rectToPrint.Top = e.MarginBounds.Top * AnInch<br />
            rectToPrint.Bottom = e.MarginBounds.Bottom * AnInch<br />
            rectToPrint.Left = e.MarginBounds.Left * AnInch<br />
            rectToPrint.Right = e.MarginBounds.Right * AnInch<br />
<br />
            ' Calculate the size of the page<br />
            Dim rectPage As RECT<br />
            rectPage.Top = e.PageBounds.Top * AnInch<br />
            rectPage.Bottom = e.PageBounds.Bottom * AnInch<br />
            rectPage.Left = e.PageBounds.Left * AnInch<br />
            rectPage.Right = e.PageBounds.Right * AnInch<br />
<br />
            Dim hdc As IntPtr = e.Graphics.GetHdc()<br />
<br />
            Dim fmtRange As FORMATRANGE<br />
            fmtRange.chrg = cRange                 ' Indicate character from to character to <br />
            fmtRange.hdc = hdc                     ' Use the same DC for measuring and rendering<br />
            fmtRange.hdcTarget = hdc               ' Point at printer hDC<br />
            fmtRange.rc = rectToPrint              ' Indicate the area on page to print<br />
            fmtRange.rcPage = rectPage             ' Indicate whole size of page<br />
<br />
            Dim res As IntPtr = IntPtr.Zero<br />
<br />
            Dim wparam As IntPtr = IntPtr.Zero<br />
            wparam = New IntPtr(1)<br />
<br />
            ' Move the pointer to the FORMATRANGE structure in memory<br />
            Dim lparam As IntPtr = IntPtr.Zero<br />
            lparam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmtRange))<br />
            Marshal.StructureToPtr(fmtRange, lparam, False)<br />
<br />
            ' Send the rendered data for printing <br />
            res = SendMessage(Handle, EM_FORMATRANGE, wparam, lparam)<br />
<br />
            ' Free the block of memory allocated<br />
            Marshal.FreeCoTaskMem(lparam)<br />
<br />
            ' Release the device context handle obtained by a previous call<br />
            e.Graphics.ReleaseHdc(hdc)<br />
<br />
            ' Return last + 1 character printer<br />
            Return res.ToInt32()<br />
        End Function<br />
<br />
    End Class<br />
<br />

GeneralRe: Caret Size Pin
TwoFaced24-Feb-07 8:28
TwoFaced24-Feb-07 8:28 
GeneralRe: Caret Size Pin
Anybloodyid24-Feb-07 9:42
Anybloodyid24-Feb-07 9:42 
GeneralRe: Caret Size Pin
TwoFaced24-Feb-07 10:14
TwoFaced24-Feb-07 10:14 
GeneralRe: Caret Size Pin
Anybloodyid24-Feb-07 11:11
Anybloodyid24-Feb-07 11:11 
GeneralRe: Caret Size Pin
TwoFaced24-Feb-07 12:54
TwoFaced24-Feb-07 12:54 
GeneralRe: Caret Size Pin
Anybloodyid24-Feb-07 22:47
Anybloodyid24-Feb-07 22:47 
GeneralRe: Caret Size Pin
TwoFaced24-Feb-07 23:17
TwoFaced24-Feb-07 23:17 
GeneralRe: Caret Size Pin
Anybloodyid25-Feb-07 0:50
Anybloodyid25-Feb-07 0:50 
Questionincluiding calculator in my vb.net application Pin
manni_n23-Feb-07 7:04
manni_n23-Feb-07 7:04 
AnswerRe: incluiding calculator in my vb.net application Pin
Dave Kreskowiak23-Feb-07 7:33
mveDave Kreskowiak23-Feb-07 7:33 
GeneralRe: incluiding calculator in my vb.net application [modified] Pin
manni_n23-Feb-07 8:10
manni_n23-Feb-07 8:10 
GeneralRe: incluiding calculator in my vb.net application Pin
Dave Kreskowiak23-Feb-07 8:29
mveDave Kreskowiak23-Feb-07 8:29 
GeneralRe: incluiding calculator in my vb.net application Pin
manni_n23-Feb-07 8:32
manni_n23-Feb-07 8:32 
GeneralRe: incluiding calculator in my vb.net application Pin
Christian Graus23-Feb-07 10:04
protectorChristian Graus23-Feb-07 10:04 
GeneralRe: incluiding calculator in my vb.net application Pin
manni_n23-Feb-07 12:35
manni_n23-Feb-07 12:35 
GeneralRe: incluiding calculator in my vb.net application Pin
Vikash Yadav23-Feb-07 22:24
Vikash Yadav23-Feb-07 22:24 
GeneralRe: incluiding calculator in my vb.net application Pin
manni_n24-Feb-07 1:01
manni_n24-Feb-07 1:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.