Click here to Skip to main content
16,005,467 members
Home / Discussions / Visual Basic
   

Visual Basic

 
Questioncolulmn based selection in multi-line text box? Pin
madfiddlerchris26-May-05 0:45
madfiddlerchris26-May-05 0:45 
AnswerRe: colulmn based selection in multi-line text box? Pin
Christian Graus26-May-05 16:07
protectorChristian Graus26-May-05 16:07 
GeneralRe: colulmn based selection in multi-line text box? Pin
madfiddlerchris1-Jul-05 2:29
madfiddlerchris1-Jul-05 2:29 
GeneralRe: colulmn based selection in multi-line text box? Pin
Christian Graus1-Jul-05 20:10
protectorChristian Graus1-Jul-05 20:10 
GeneralRe: colulmn based selection in multi-line text box? Pin
madfiddlerchris4-Jul-05 1:07
madfiddlerchris4-Jul-05 1:07 
GeneralRe: colulmn based selection in multi-line text box? Pin
Christian Graus4-Jul-05 13:14
protectorChristian Graus4-Jul-05 13:14 
GeneralRe: colulmn based selection in multi-line text box? Pin
madfiddlerchris5-Jul-05 2:04
madfiddlerchris5-Jul-05 2:04 
GeneralRe: colulmn based selection in multi-line text box? Pin
madfiddlerchris15-Jul-05 3:23
madfiddlerchris15-Jul-05 3:23 
Slow progress so far.

I've just started to try and capture the mouse selection by subclassing the textbox control and using WndProc (code is below)

So I've got to the point of trynig to draw a rectangle covering the area selected by the mouse but the rectangle appears way to the right and below where it should be. try puttin the control on a form, make it quite big and specify it as multi-line and you'll see what I mean.

I suspect the cursor position is not relative to my control, but I can;t figure it out for the life of me. Anyone have any ideas?




Public Class CSTextBox
Inherits System.Windows.Forms.TextBox

#Region " Component Designer generated code "

Public Sub New()
MyBase.New()

' This call is required by the Component Designer.
InitializeComponent()

End Sub

'Control overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
FileClose(1)
MyBase.Dispose(disposing)
End Sub

'Required by the Control Designer
Private components As System.ComponentModel.IContainer

' NOTE: The following procedure is required by the Component Designer
' It can be modified using the Component Designer. Do not modify it
' using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
End Sub

#End Region

Protected Overrides Sub OnPaint(ByVal pe As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(pe)
'Add your custom paint code here
End Sub

Private Const WM_MOUSEMOVE = &H200
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202

Private startpoint As Point
Private endpoint As Point
Private selectionMode As Boolean = False

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Select Case m.Msg
Case WM_LBUTTONDOWN
startpoint = Me.Cursor.Position
endpoint = startpoint
selectionMode = True
Case WM_MOUSEMOVE
MyBase.WndProc(m)
If selectionMode Then
endpoint = Me.Cursor.Position
End If
Case WM_LBUTTONUP
endpoint = Me.Cursor.Position
DrawRect()
selectionMode = False
Case Else
MyBase.WndProc(m)
End Select
End Sub

Private Sub DrawRect()
If selectionMode Then
Dim x As Long, y As Long, w As Long, h As Long
If startpoint.X <= endpoint.X Then
x = startpoint.X
w = endpoint.X - startpoint.X
Else
x = endpoint.X
w = startpoint.X - endpoint.X
End If
If startpoint.Y <= endpoint.Y Then
y = startpoint.Y
h = endpoint.Y - startpoint.Y
Else
y = endpoint.Y
h = startpoint.Y - endpoint.Y
End If
Me.CreateGraphics.DrawRectangle(New Pen(Color.Red), New Rectangle(x, y, w, h))
End If
End Sub


End Class


GeneralRe: colulmn based selection in multi-line text box? Pin
madfiddlerchris24-Jul-05 23:18
madfiddlerchris24-Jul-05 23:18 
GeneralWM_SETTEXT Pin
Axonn Echysttas25-May-05 21:32
Axonn Echysttas25-May-05 21:32 
QuestionHow to rebuild the resource? Pin
rushing25-May-05 21:27
rushing25-May-05 21:27 
GeneralImporting namespace / Dll Pin
C.Sathish25-May-05 21:27
C.Sathish25-May-05 21:27 
GeneralRe: Importing namespace / Dll Pin
toxcct25-May-05 22:35
toxcct25-May-05 22:35 
Questionmovi gif in vb6? Pin
a_yosef25-May-05 21:14
a_yosef25-May-05 21:14 
GeneralCRUD Application Pin
imshally8125-May-05 20:53
imshally8125-May-05 20:53 
GeneralRe: CRUD Application Pin
C.Sathish26-May-05 2:27
C.Sathish26-May-05 2:27 
GeneralCapture Date and Time Pin
imshally8125-May-05 20:50
imshally8125-May-05 20:50 
GeneralRe: Capture Date and Time Pin
Rizwan Bashir25-May-05 21:28
Rizwan Bashir25-May-05 21:28 
GeneralRe: Capture Date and Time Pin
imshally8126-May-05 0:01
imshally8126-May-05 0:01 
Generalmaped network drives Pin
_tasleem25-May-05 19:32
_tasleem25-May-05 19:32 
GeneralRe: maped network drives Pin
madfiddlerchris26-May-05 0:49
madfiddlerchris26-May-05 0:49 
GeneralBig Bug in ComboBox control Pin
rushing25-May-05 17:38
rushing25-May-05 17:38 
GeneralRe: Big Bug in ComboBox control Pin
Christian Graus25-May-05 17:40
protectorChristian Graus25-May-05 17:40 
GeneralRe: Big Bug in ComboBox control Pin
rushing25-May-05 18:26
rushing25-May-05 18:26 
GeneralRe: Big Bug in ComboBox control Pin
Christian Graus25-May-05 18:31
protectorChristian Graus25-May-05 18:31 

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.