473,403 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Block Selection in RichTextBox

5
Hey hi! all
Is it possible to implement block selection (Like available with ms word hold down alt key and drag mouse arrow) this will select specific area and text under that region. this feature is also available with vs IDE.

Any one having any idea regarding how to do it please respond. i have posted this problem in may forums but i did not get any reply....

Thanks,
chirag
Mar 7 '07 #1
9 3213
kenobewan
4,871 Expert 4TB
Maybe you need to think about why noone responds... What progress have you made and what is your platform?
Mar 7 '07 #2
cdave
5
Maybe you need to think about why noone responds... What progress have you made and what is your platform?
its an application development (Windows.forms application) where the control on which i am trying to make this block selection available is RichTextBox control.
Mar 15 '07 #3
AricC
1,892 Expert 1GB
its an application development (Windows.forms application) where the control on which i am trying to make this block selection available is RichTextBox control.
I think Kenobewan means what code do you have, what have you tried you need to be specific. If you have code that isn't working post it.
Mar 15 '07 #4
cdave
5
Expand|Select|Wrap|Line Numbers
  1. Imports System.Drawing
  2. Imports System.Runtime.InteropServices
  3.  
  4.  
  5. Public Class Form1
  6.  
  7.     Inherits System.Windows.Forms.Form
  8.  
  9.  
  10. #Region " Windows Form Designer generated code "
  11.  
  12.     Public Sub New()
  13.         MyBase.New()
  14.  
  15.         'This call is required by the Windows Form Designer.
  16.         InitializeComponent()
  17.  
  18.         'Add any initialization after the InitializeComponent() call
  19.  
  20.     End Sub
  21.  
  22.     'Form overrides dispose to clean up the component list.
  23.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  24.         If disposing Then
  25.             If Not (components Is Nothing) Then
  26.                 components.Dispose()
  27.             End If
  28.         End If
  29.         MyBase.Dispose(disposing)
  30.     End Sub
  31.  
  32.     'Required by the Windows Form Designer
  33.     Private components As System.ComponentModel.IContainer
  34.  
  35.     'NOTE: The following procedure is required by the Windows Form Designer
  36.     'It can be modified using the Windows Form Designer.  
  37.     'Do not modify it using the code editor.
  38.     Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
  39.     Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
  40.     Friend WithEvents OpenFileMenuItem As System.Windows.Forms.MenuItem
  41.     Friend WithEvents CloseFileMenuItem As System.Windows.Forms.MenuItem
  42.     Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
  43.     Friend WithEvents zRTB As System.Windows.Forms.RichTextBox
  44.     Friend WithEvents DrawingPaletteButton As System.Windows.Forms.Button
  45.     Friend WithEvents StatusBar1 As System.Windows.Forms.StatusBar
  46.     Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
  47.     Friend WithEvents TransparentRichTextBox1 As RichTextboxandGDI.AlphaRichTextBox.TransparentRichTextBox
  48.     Friend WithEvents Label1 As System.Windows.Forms.Label
  49.     Friend WithEvents ShowGuidesMenuItem As System.Windows.Forms.MenuItem
  50.  
  51.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  52.         Me.components = New System.ComponentModel.Container
  53.         Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
  54.         Me.DrawingPaletteButton = New System.Windows.Forms.Button
  55.         Me.zRTB = New System.Windows.Forms.RichTextBox
  56.         Me.MainMenu1 = New System.Windows.Forms.MainMenu(Me.components)
  57.         Me.MenuItem1 = New System.Windows.Forms.MenuItem
  58.         Me.OpenFileMenuItem = New System.Windows.Forms.MenuItem
  59.         Me.CloseFileMenuItem = New System.Windows.Forms.MenuItem
  60.         Me.MenuItem2 = New System.Windows.Forms.MenuItem
  61.         Me.ShowGuidesMenuItem = New System.Windows.Forms.MenuItem
  62.         Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
  63.         Me.StatusBar1 = New System.Windows.Forms.StatusBar
  64.         Me.TransparentRichTextBox1 = New RichTextboxandGDI.AlphaRichTextBox.TransparentRichTextBox
  65.         Me.Label1 = New System.Windows.Forms.Label
  66.         Me.SuspendLayout()
  67.         '
  68.         'DrawingPaletteButton
  69.         '
  70.         Me.DrawingPaletteButton.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
  71.         Me.DrawingPaletteButton.Location = New System.Drawing.Point(704, 8)
  72.         Me.DrawingPaletteButton.Name = "DrawingPaletteButton"
  73.         Me.DrawingPaletteButton.Size = New System.Drawing.Size(104, 23)
  74.         Me.DrawingPaletteButton.TabIndex = 1
  75.         Me.DrawingPaletteButton.Text = "Drawing Palette"
  76.         '
  77.         'zRTB
  78.         '
  79.         Me.zRTB.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
  80.                     Or System.Windows.Forms.AnchorStyles.Left) _
  81.                     Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
  82.         Me.zRTB.AutoWordSelection = True
  83.         Me.zRTB.Font = New System.Drawing.Font("Courier New", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  84.         Me.zRTB.HideSelection = False
  85.         Me.zRTB.ImeMode = System.Windows.Forms.ImeMode.AlphaFull
  86.         Me.zRTB.Location = New System.Drawing.Point(0, 48)
  87.         Me.zRTB.Name = "zRTB"
  88.         Me.zRTB.ShowSelectionMargin = True
  89.         Me.zRTB.Size = New System.Drawing.Size(816, 279)
  90.         Me.zRTB.TabIndex = 2
  91.         Me.zRTB.Text = resources.GetString("zRTB.Text")
  92.         Me.zRTB.WordWrap = False
  93.         '
  94.         'MainMenu1
  95.         '
  96.         Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem2})
  97.         '
  98.         'MenuItem1
  99.         '
  100.         Me.MenuItem1.Index = 0
  101.         Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.OpenFileMenuItem, Me.CloseFileMenuItem})
  102.         Me.MenuItem1.Text = "File"
  103.         '
  104.         'OpenFileMenuItem
  105.         '
  106.         Me.OpenFileMenuItem.Index = 0
  107.         Me.OpenFileMenuItem.Text = "Open"
  108.         '
  109.         'CloseFileMenuItem
  110.         '
  111.         Me.CloseFileMenuItem.Index = 1
  112.         Me.CloseFileMenuItem.Text = "Close"
  113.         '
  114.         'MenuItem2
  115.         '
  116.         Me.MenuItem2.Index = 1
  117.         Me.MenuItem2.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.ShowGuidesMenuItem})
  118.         Me.MenuItem2.Text = "View"
  119.         '
  120.         'ShowGuidesMenuItem
  121.         '
  122.         Me.ShowGuidesMenuItem.Index = 0
  123.         Me.ShowGuidesMenuItem.Text = "Show Guides"
  124.         '
  125.         'StatusBar1
  126.         '
  127.         Me.StatusBar1.Location = New System.Drawing.Point(0, 359)
  128.         Me.StatusBar1.Name = "StatusBar1"
  129.         Me.StatusBar1.Size = New System.Drawing.Size(816, 22)
  130.         Me.StatusBar1.TabIndex = 3
  131.         '
  132.         'TransparentRichTextBox1
  133.         '
  134.         Me.TransparentRichTextBox1.Enabled = False
  135.         Me.TransparentRichTextBox1.Location = New System.Drawing.Point(8, -48)
  136.         Me.TransparentRichTextBox1.Name = "TransparentRichTextBox1"
  137.         Me.TransparentRichTextBox1.Size = New System.Drawing.Size(768, 96)
  138.         Me.TransparentRichTextBox1.TabIndex = 4
  139.         Me.TransparentRichTextBox1.Text = ""
  140.         '
  141.         'Label1
  142.         '
  143.         Me.Label1.AutoSize = True
  144.         Me.Label1.Location = New System.Drawing.Point(72, 336)
  145.         Me.Label1.Name = "Label1"
  146.         Me.Label1.Size = New System.Drawing.Size(39, 13)
  147.         Me.Label1.TabIndex = 5
  148.         Me.Label1.Text = "Label1"
  149.         '
  150.         'Form1
  151.         '
  152.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
  153.         Me.ClientSize = New System.Drawing.Size(816, 381)
  154.         Me.Controls.Add(Me.Label1)
  155.         Me.Controls.Add(Me.TransparentRichTextBox1)
  156.         Me.Controls.Add(Me.StatusBar1)
  157.         Me.Controls.Add(Me.zRTB)
  158.         Me.Controls.Add(Me.DrawingPaletteButton)
  159.         Me.Menu = Me.MainMenu1
  160.         Me.Name = "Form1"
  161.         Me.Text = "My Editor"
  162.         Me.ResumeLayout(False)
  163.         Me.PerformLayout()
  164.  
  165.     End Sub
  166.  
  167. #End Region
  168.  
  169.     Dim LinePen As Pen
  170.     Dim LineBrush As Brush
  171.     Dim MeGraphics As Graphics
  172.     Dim XOffset As Integer = 6
  173.     Dim YOffset As Integer = 54
  174.     Dim SolidBrush As New SolidBrush(Color.Black)
  175.     Dim DrawBoxX, DrawBoxY As Integer
  176.     Dim DrawingMode As Boolean = False
  177.     Dim MouseDownDraw As Boolean = False
  178.     Dim StartX, StartY, BoxWidth, BoxHeight As Integer
  179.     Dim GraphicxLoc, GraphicyLoc As Integer
  180.     Friend DrawingItems As Collection
  181.  
  182.     Dim frmGrapher As Grapher
  183.     Dim GrapherTransparencyKey As Color
  184.     Dim DebugOutputComplete As Boolean = False
  185.     Public start As Integer
  186.     Private Declare Function GetScrollInfo Lib "user32" (ByVal hwnd As Long, ByVal n As Long, ByVal lpScrollInfo As SCROLLINFO) As Long
  187.     Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  188.  
  189.     Const SIF_RANGE = &H1
  190.     Const SB_VERT = 1
  191.  
  192.     Dim lHeight As Long, OnePixel As Long
  193.     Dim S As SCROLLINFO
  194.     Private Declare Auto Function SendScrollPosMessage _
  195.                     Lib "user32.dll" Alias "SendMessage" ( _
  196.                     ByVal hWnd As IntPtr, _
  197.                     ByVal Msg As Integer, _
  198.                     ByVal wParam As IntPtr, _
  199.                     ByRef lParam As Point) As Integer
  200.     Private Const WM_USER = &H400
  201.     Private Const EM_GETSCROLLPOS = WM_USER + 221
  202.     Private Const EM_SETSCROLLPOS = WM_USER + 222
  203.  
  204.     Private Structure POINTAPI
  205.         Public X As Integer
  206.         Public Y As Integer
  207.     End Structure
  208.     Private Structure SCROLLINFO
  209.         Public cbSize As Long
  210.         Public fMask As Long
  211.         Public nMin As Long
  212.         Public nMax As Long
  213.         Public nPage As Long
  214.         Public nPos As Long
  215.         Public nTrackPos As Long
  216.     End Structure
  217.  
  218.     Private Declare Function GetCursorPos _
  219.     Lib "user32" (ByVal lpPoint As POINTAPI) As Integer
  220.     Private Declare Function GetDC _
  221.     Lib "user32" (ByVal hwnd As Integer) As Integer
  222.     Private Declare Function GetPixel _
  223.     Lib "gdi32" (ByVal hdc As Integer, _
  224.     ByVal X As Integer, ByVal Y As Integer) As Integer
  225.     Private Declare Function ReleaseDC _
  226.     Lib "user32" (ByVal hwnd As Integer, _
  227.     ByVal hdc As Integer) As Integer
  228.  
  229.     Private lDesktopDC As Integer
  230.  
  231.     Private Sub Timer1_Tick(ByVal sender As Object, _
  232.     ByVal e As System.EventArgs)
  233.  
  234.         Dim tPt As Point, lRGB As Integer
  235.         tPt = MousePosition
  236.         lRGB = GetPixel(lDesktopDC, tPt.X, tPt.Y)
  237.         If lRGB <> -1 Then
  238.             Me.BackColor = ColorTranslator.FromWin32(lRGB)
  239.         End If
  240.  
  241.     End Sub
'Code is in continuation (see next post)
Mar 15 '07 #5
cdave
5
Expand|Select|Wrap|Line Numbers
  1. Private Sub frmPixelColor_Load(ByVal sender As Object, _
  2.     ByVal e As System.EventArgs) Handles MyBase.Load
  3.         'TransparentRichTextBox1.Parent = zRTB
  4.         AlphaRichTextBox.TransparentRichTextBox.Block = True
  5.         zRTB.SelectionHangingIndent = 1000
  6.         lDesktopDC = GetDC(0)
  7.         Dim i As Integer = zRTB.SelectionType
  8.  
  9.  
  10.  
  11.  
  12.         Dim word As New Word.Application
  13.         Dim doc As Word.Document
  14.  
  15.  
  16.         'filter which files to open
  17.         Me.OpenFileDialog1.Filter = "Word Docs (*.doc)|*.doc|All files|*.*"
  18.         '  Dim result As DialogResult = OpenFileDialog1.ShowDialog(Me)
  19.  
  20.  
  21.         'If (result = Windows.Forms.DialogResult.OK) Then
  22.  
  23.  
  24.  
  25.         '    doc = word.Documents.Open(Me.OpenFileDialog1.FileName.ToString.Trim)
  26.         '    'doc.Words.Application.System.Parent = Me
  27.  
  28.         '    doc.UpdateStylesOnOpen = True
  29.  
  30.         'End If
  31.         'Timer1.Interval = 100
  32.         'Timer1.Enabled = True
  33.     End Sub
  34.  
  35.     Private Sub frmPixelColor_Closed(ByVal sender As Object, _
  36.     ByVal e As System.EventArgs) Handles MyBase.Closed
  37.  
  38.         Call ReleaseDC(0, lDesktopDC)
  39.     End Sub
  40.  
  41.  
  42.  
  43.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  44.         LinePen = New Pen(SolidBrush, 1)
  45.  
  46.         MeGraphics = Me.zRTB.CreateGraphics
  47.  
  48.         frmGrapher = New Grapher(Me)
  49.  
  50.     End Sub
  51.  
  52.     Private Sub DrawingPaletteButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DrawingPaletteButton.Click
  53.         Try
  54.             Me.zRTB.Cursor = Cursors.Cross
  55.             Me.zRTB.SelectionStart = 1
  56.  
  57.             DrawingMode = True
  58.         Catch exc As Exception
  59.         End Try
  60.     End Sub
  61.  
  62.     Private Sub OpenFileMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenFileMenuItem.Click
  63.         DrawingItems = New Collection
  64.  
  65.         If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
  66.             zRTB.LoadFile(OpenFileDialog1.FileName)
  67.         End If
  68.     End Sub
  69.  
  70.     Dim dummy As New RichTextBox
  71.     Private Sub MainTextRichTextbox_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles zRTB.MouseDown
  72.         DrawBoxX = e.X
  73.         DrawBoxY = e.Y
  74.         zRTB.SelectionStart = zRTB.GetCharIndexFromPosition(New Point(DrawBoxX, DrawBoxY))
  75.         'MainTextRichTextbox.SelectionHangingIndent = 1024
  76.         If DrawingMode Then
  77.             MouseDownDraw = True
  78.             start = zRTB.SelectionStart
  79.         End If
  80.     End Sub
  81.  
  82.     Private Sub MainTextRichTextbox_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles zRTB.MouseMove
  83.         If Not MouseDownDraw Then
  84.             Exit Sub
  85.         End If
  86.         zRTB.SelectionLength = 0
  87.  
  88.  
  89.         If e.X > DrawBoxX Then
  90.             BoxWidth = e.X - DrawBoxX
  91.             StartX = DrawBoxX
  92.         Else
  93.             BoxWidth = DrawBoxX - e.X
  94.             StartX = e.X
  95.         End If
  96.  
  97.         If e.Y > DrawBoxY Then
  98.             BoxHeight = e.Y - DrawBoxY
  99.             StartY = DrawBoxY
  100.         Else
  101.             BoxHeight = DrawBoxY - e.Y
  102.             StartY = e.Y
  103.         End If
  104.         zRTB.Refresh()
  105.         MeGraphics.DrawRectangle(LinePen, StartX, StartY, BoxWidth, BoxHeight)
  106.         zRTB.SelectionLength = 0
  107.  
  108.         IsMultiselectOn = True
  109.     End Sub
  110.     Public Sub ClearScr()
  111.         zRTB.SelectAll()
  112.         zRTB.SelectionBackColor = Color.White
  113.  
  114.  
  115.     End Sub
  116.     Public Function GetLineLength(ByVal line As Integer) As Integer
  117.         Dim linesCount As Integer = zRTB.Lines.Length
  118.         If line <= linesCount Then
  119.             Return zRTB.Lines(line - 1).Length
  120.         End If
  121.     End Function
  122.     Dim IsMultiselectOn As Boolean
  123.     Private Sub MainTextRichTextbox_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles zRTB.MouseUp
  124.  
  125.         DrawingMode = False
  126.         MouseDownDraw = False
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.         If IsMultiselectOn Then
  136.             zRTB.SuspendLayout()
  137.  
  138.  
  139.  
  140.  
  141.             zRTB.SelectionStart = zRTB.GetCharIndexFromPosition(New Point(DrawBoxX, DrawBoxY))
  142.             Dim max As Integer = zRTB.GetCharIndexFromPosition(New Point(DrawBoxX + BoxWidth, DrawBoxY))
  143.             Dim FirstLine As Integer = zRTB.GetLineFromCharIndex(zRTB.GetCharIndexFromPosition(New Point(DrawBoxX + BoxWidth, DrawBoxY)))
  144.             zRTB.SelectionLength = max - zRTB.SelectionStart
  145.             Dim charwidth As Integer = max - zRTB.SelectionStart
  146.             Dim charindex As Integer = zRTB.SelectionStart - zRTB.GetFirstCharIndexFromLine(FirstLine)
  147.             Dim SelWidth As Integer = max - zRTB.SelectionStart
  148.             Dim backcolor As Color = zRTB.SelectionBackColor
  149.             Dim selectionclr As Color = zRTB.SelectionColor
  150.  
  151.             zRTB.SelectionBackColor = Color.Blue
  152.             zRTB.SelectionColor = Color.White
  153.             Dim lines As Integer = zRTB.GetLineFromCharIndex(zRTB.GetCharIndexFromPosition(New Point(DrawBoxX, DrawBoxY + BoxHeight)))
  154.             If (lines - FirstLine > 0) Then
  155.                 'more the one lines selected.
  156.                 While (FirstLine < lines)
  157.                     FirstLine += 1
  158.                     Try
  159.                         zRTB.SelectionStart = zRTB.GetFirstCharIndexFromLine(FirstLine) + charindex
  160.  
  161.                         If (zRTB.SelectedText.Contains(vbLf)) Then
  162.                             zRTB.SelectionLength = (zRTB.SelectedText.IndexOf(vbCrLf) - zRTB.SelectionStart)
  163.                         Else
  164.                             zRTB.SelectionLength = charwidth
  165.                         End If
  166.  
  167.                     Catch ex As Exception
  168.                         Continue While
  169.                     End Try
  170.                     zRTB.SelectionBackColor = Color.Blue
  171.                     zRTB.SelectionColor = Color.White
  172.                 End While
  173.             End If
  174.  
  175.             zRTB.SelectionLength = 0
  176.             zRTB.ResumeLayout()
  177.  
  178.  
  179.             zRTB.ResumeLayout()
  180.             IsMultiselectOn = False
  181.         End If
  182.         'draw area
  183.  
  184.  
  185.     End Sub
  186.  
  187.     Private Sub FillRect()
  188.         Try
  189.             Dim height As Integer = 0
  190.             Dim width As Integer = 0
  191.             MeGraphics = zRTB.CreateGraphics
  192.             While (height <> BoxHeight)
  193.                 While (width <> BoxWidth)
  194.  
  195.                     Dim lRGB As Integer = GetPixel(lDesktopDC, StartX, StartY)
  196.                     Dim col As Color = ColorTranslator.FromWin32(lRGB)
  197.                     If (col = Color.Black) Then
  198.                         MeGraphics.DrawRectangle(Pens.White, StartX, StartY, StartX + 1, StartY + 1)
  199.                     Else
  200.                         MeGraphics.DrawLine(Pens.Yellow, StartX, StartY, StartX + 1, StartY + 1)
  201.                     End If
  202.                     StartY += 1
  203.                     width += 1
  204.  
  205.                 End While
  206.                 StartX += 1
  207.                 height += 1
  208.                 width = 0
  209.             End While
  210.             Call ReleaseDC(0, lDesktopDC)
  211.  
  212.         Catch ex As Exception
  213.  
  214.         End Try
  215.     End Sub
'Continue
Mar 15 '07 #6
cdave
5
Expand|Select|Wrap|Line Numbers
  1. Private Sub DisplayMultiSelection()
  2.         Try
  3.             zRTB.SelectionStart = zRTB.GetCharIndexFromPosition(New Point(DrawBoxX, DrawBoxY))
  4.             Dim max As Integer = zRTB.GetCharIndexFromPosition(New Point(DrawBoxX + BoxWidth, DrawBoxY))
  5.             Dim FirstLine As Integer = zRTB.GetLineFromCharIndex(zRTB.GetCharIndexFromPosition(New Point(DrawBoxX + BoxWidth, DrawBoxY)))
  6.             zRTB.SelectionLength = max - zRTB.SelectionStart
  7.             Dim charwidth As Integer = max - zRTB.SelectionStart
  8.             Dim charindex As Integer = zRTB.SelectionStart - zRTB.GetFirstCharIndexFromLine(FirstLine)
  9.  
  10.  
  11.             Dim backcolor As Color = zRTB.SelectionBackColor
  12.             Dim selectionclr As Color = zRTB.SelectionColor
  13.  
  14.             zRTB.SelectionBackColor = Color.Blue
  15.             zRTB.SelectionColor = Color.White
  16.  
  17.             Dim lines As Integer = zRTB.GetLineFromCharIndex(zRTB.GetCharIndexFromPosition(New Point(DrawBoxX, DrawBoxY + BoxHeight)))
  18.             If (lines - FirstLine > 0) Then
  19.                 'more the one lines selected.
  20.                 While (FirstLine < lines)
  21.                     FirstLine += 1
  22.                     zRTB.SelectionStart = zRTB.GetFirstCharIndexFromLine(FirstLine) + charindex
  23.                     zRTB.SelectionLength = charwidth
  24.                     zRTB.SelectionBackColor = Color.Blue
  25.                     zRTB.SelectionColor = Color.White
  26.                 End While
  27.             End If
  28.             'MainTextRichTextbox.SelectionBackColor = backcolor
  29.             'MainTextRichTextbox.SelectionColor = selectionclr
  30.         Catch ex As Exception
  31.  
  32.         End Try
  33.     End Sub
  34.  
  35.     Private Sub MainTextRichTextbox_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles zRTB.SelectionChanged
  36.         If DrawingMode Then
  37.             Return
  38.             'zRTB.Select(0, 0)
  39.             'MainTextRichTextbox.SelectionLength = 0
  40.         End If
  41.     End Sub
  42.  
  43.     Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
  44.         PaintGraphics()
  45.     End Sub
  46.  
  47.     Friend Sub PaintGraphics()
  48.         Dim ThisDrawItem As New Grapher.DrawingItem
  49.         Dim xLoc, yLoc As Integer
  50.         Dim xEndLoc, yEndLoc As Integer
  51.  
  52.         zRTB.Refresh()
  53.         If Not IsNothing(DrawingItems) Then
  54.  
  55.             For Each ThisDrawItem In DrawingItems
  56.                 With ThisDrawItem
  57.                     .PaletteX = .PaletteX
  58.                     .PaletteY = .PaletteY
  59.                     xLoc = .PaletteX + .StartPostion.X
  60.  
  61.                     xEndLoc = (.PaletteX) + .EndPostion.X
  62.  
  63.                     yLoc = .PaletteY + .StartPostion.Y + (YOffset - 50)
  64.                     yEndLoc = .PaletteY + .EndPostion.Y + (YOffset - 50)
  65.  
  66.                     If Not DebugOutputComplete Then
  67.                         DebugOutputComplete = True
  68.                     End If
  69.  
  70.                     Select Case ThisDrawItem.DrawingMode
  71.                         Case Grapher.DrawingModes.Rectangle
  72.                             'MeGraphics.DrawRectangle(LinePen, xLoc, yLoc, .BoxSize.Width, .BoxSize.Height)
  73.                             MeGraphics.DrawRectangle(LinePen, xLoc, yLoc, .BoxSize.Width, .BoxSize.Height)
  74.                         Case Grapher.DrawingModes.Line
  75.                             MeGraphics.DrawLine(LinePen, xLoc, yLoc, xEndLoc, yEndLoc)
  76.                         Case Else
  77.                     End Select
  78.                 End With
  79.             Next
  80.         End If
  81.  
  82.         'Test guidelines
  83.         If ShowGuidesMenuItem.Checked Then
  84.             MeGraphics.DrawLine(LinePen, 60, 0, 60, Me.Height)
  85.             MeGraphics.DrawLine(LinePen, 0, 60, Me.Width, 60)
  86.         End If
  87.     End Sub
  88.  
  89.     Private Sub ShowGuidesMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowGuidesMenuItem.Click
  90.         If ShowGuidesMenuItem.Checked Then
  91.             ShowGuidesMenuItem.Checked = False
  92.         Else
  93.             ShowGuidesMenuItem.Checked = True
  94.         End If
  95.  
  96.         PaintGraphics()
  97.     End Sub
  98.  
  99.     Private Sub CloseFileMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseFileMenuItem.Click
  100.         DrawingItems = New Collection
  101.         zRTB.ResetText()
  102.     End Sub
  103.  
  104.     Private Sub MainTextRichTextbox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles zRTB.TextChanged
  105.         PaintGraphics()
  106.     End Sub
  107.  
  108.     Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
  109.         If Not MeGraphics Is Nothing Then
  110.             MeGraphics.Dispose()
  111.             MeGraphics = Nothing
  112.         End If
  113.         MeGraphics = Me.zRTB.CreateGraphics
  114.     End Sub
  115.  
  116.     Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
  117.  
  118.     End Sub
  119.  
  120.     Private Sub TransparentRichTextBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
  121.         DrawBoxX = e.X
  122.         DrawBoxY = e.Y
  123.         zRTB.SelectionStart = zRTB.GetCharIndexFromPosition(New Point(DrawBoxX, DrawBoxY))
  124.  
  125.         If DrawingMode Then
  126.             MouseDownDraw = True
  127.         End If
  128.     End Sub
  129.  
  130.     Private Sub TransparentRichTextBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
  131.  
  132.         If Not MouseDownDraw Then
  133.             Exit Sub
  134.         End If
  135.  
  136.         If e.X > DrawBoxX Then
  137.             BoxWidth = e.X - DrawBoxX
  138.             StartX = DrawBoxX
  139.         Else
  140.             BoxWidth = DrawBoxX - e.X
  141.             StartX = e.X
  142.         End If
  143.  
  144.         If e.Y > DrawBoxY Then
  145.             BoxHeight = e.Y - DrawBoxY
  146.             StartY = DrawBoxY
  147.         Else
  148.             BoxHeight = DrawBoxY - e.Y
  149.             StartY = e.Y
  150.         End If
  151.  
  152.         '        Me.Refresh()
  153.  
  154.         ' MeGraphics.DrawRectangle(LinePen, StartX, StartY, BoxWidth, BoxHeight)
  155.     End Sub
  156.  
  157.     Private Sub TransparentRichTextBox1_Move(ByVal sender As System.Object, ByVal e As System.EventArgs)
  158.  
  159.     End Sub
  160.  
  161.     Private Sub TransparentRichTextBox1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
  162.         DrawingMode = False
  163.         MouseDownDraw = False
  164.     End Sub
  165.  
  166.     Private Sub MainTextRichTextbox_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles zRTB.KeyDown
  167.         Try
  168.  
  169.         Catch ex As Exception
  170.  
  171.         End Try
  172.     End Sub
  173.     Private Sub MainTextRichTextbox_VScroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles zRTB.VScroll
  174.         zRTB.Refresh()
  175.     End Sub
  176.  
  177.     Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
  178.  
  179.     End Sub
  180.  
  181.     Private Sub zRTB_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles zRTB.MouseHover
  182.  
  183.     End Sub
  184. End Class
copy and paste this code and press platter button and try to select area you will be able to select in block mode but its not perfect as avaiable with other editors
Mar 15 '07 #7
kenobewan
4,871 Expert 4TB
Boy that's alot of code to paste, I think that AricC meant only the code that you had tried to solve this requirement and was causing you problems...

Here is a blog that will get you started:
XAML, WPF, .NET, Office 2007, Windows
For actual user selection behaviour you may need a custom control or dhtml behaviour. HTH.
Mar 15 '07 #8
CDave,
Did you get any solution for the "richtextbox" block selection.
Looking for the same, but no luck.
Oct 23 '09 #9
tlhintoq
3,525 Expert 2GB
A RichTextBox doesn't select like that. You could make a custom control that inherits from RTB and handle the mousedown/mouseup events to create a custom control with the behavior you want.

You might also look around at the various .NET custom control making software companies for something already made that does what you want. Sometimes its cheaper to buy for $50 than your time for 10 hours to figure it out. Of course you don't learn by buying.
Oct 23 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: deko | last post by:
Problem: why doesn't this With block work? is it possible to have a For Each loop within a With block? With objWord .Documents.Add Template:=strTemplate, NewTemplate:=False, DocumentType:=0...
1
by: Sun Of Man | last post by:
Is there anyway to set the BackColor of selected text in a RichTextBox? There's no problem doing it for the ForeColor. Thanks in advance.
2
by: Leon Friesema | last post by:
Hiyall! I have a RichTextBox inside a UserControl which should be able to indent a block off text (or UnIndent for that matter) like the SourceEditor of VS2003 or WinWord does. All controls on...
0
by: Nadeem | last post by:
Hi, I have a richtexbox and in that I am selecting some text in a button's click event. This is working fine but the problem is if selection is consisted of may pages it takes me to the end of...
1
by: Leon Friesema | last post by:
Hi, I'm working on a RichTextBox with some "in-program" style-features (e.g. *no way* becomes bold : like MS Word does). Got everything working fine, flickerfree and reasonable fast, but in...
0
by: =?Utf-8?B?Q29yZXlNY0s=?= | last post by:
I'm working on a TextBox control (in C# using .NET 2.0) that allows fields (like MS Office's mail merge feature). I want the editor to treat the field as though it was a single character. The user...
0
by: jj | last post by:
I'm going mad! I'm exporting a query to excel, and afterwards calculating a field, and a sum of all fields in Excel from a sub procedure in a Module in Access. First I used ...
2
by: Whasigga | last post by:
Hello I am working on a project to export data from a query into an Excel file. I have a form with a button on it and the button when clicked runs a function that is supposed to run the query and...
1
by: kpr2009 | last post by:
How to achieve block selection effect in winforms, Richtextbox. Block selection: 1. Open a MS word document and type few lines. 2. Keep the cursor at middle of the first line 3. Press ALT + drag...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.