Windows Develop Bookmark and Share   
 index > Windows Forms Designer > How to Implement functionality for Vertical Scrollbar to scroll text on multiline TextBox in VB?
 

How to Implement functionality for Vertical Scrollbar to scroll text on multiline TextBox in VB?

My basic requirment is to develop an Active X control to edit text in multiline TextBox. For thatone I need a multiline TextBox, Vertical scrollbar and a Button. When User click on theButton, one form will be open .

User canedit text on the form. If he click Ok button onthe form , changes will be reflected to multiline textbox. If he clickCancel on the Form changes will not be reflected to multiline TextBox.

Here is the Code for Usercontrol:-

Private oForm As Form1
Private lineCount As Integer
Private MaxLineCount As Integer
Private Sub Command1_Click()
oForm.Text2.Text = Text1.Text
oForm.strText = Text1.Text
oForm.Show vbModal
Text1.Text = oForm.Text2.Text
End Sub

Private Sub Text1_Change()
lineCount = Len(Text1.Text) - Len(Replace(Text1.Text, vbCrLf, vbCr))
If lineCount - MaxLineCount > 0 Then
VScroll1.Enabled = True
Else
VScroll1.Enabled = False
End If
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If (Text1.SelStart < VScroll1.Max) And VScroll1.Enabled = True Then
VScroll1.Value = Text1.SelStart
End If
End Sub

Private Sub UserControl_Initialize()
VScroll1.Max = (VScroll1.Height - Text1.Height) + 1000
VScroll1.SmallChange = 50
VScroll1.LargeChange = 100
MaxLineCount = 2
VScroll1.Enabled = False
Set oForm = New Form1
End Sub

Private Sub UserControl_Terminate()
Set oForm = Nothing
End Sub


Private Sub VScroll1_Change()
Text1.SelStart = VScroll1.Value
End Sub

Private Sub VScroll1_Scroll()
'Text1.SelStart = VScroll1.Value
End Sub

Here is the Codefor Form:-

Public strText As String

Private Sub Cancel_Click()
Text2.Text = strText
Me.Hide
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 27 Then
Call Cancel_Click
End If
End Sub


Private Sub OK_Click()
Me.Hide
End Sub

Private Sub Text2_GotFocus()
strText = Text2.Text
End Sub

Here implementation for Vscroll is not proper. Could you please help me to implement Vertical Scroll functionality.Remember that I amusing seperate Vertical Scroolbar to scroll the text.

Please help me if you know the functionality of Vertical Scrollbar.

Thanks
Manohar Rudra

Manohar Rudra  Tuesday, May 05, 2009 11:06 AM
Why are you using a separate vertical scrollbar? You can set the TextBox.ScrollBars = Vertical to gain normal scrolling functionality.

/Calle
- Still confused, but on a higher level -
Calle Mellergardh  Thursday, May 07, 2009 11:40 PM
Hi Calle mellergardh,

Thats true. IfI set TextBox.ScrollBars = Vertical, I can not place a button inside multiline TextBox.

Below is the actual GUI which I want.
Where
A--> Multiline TextBox
B--> Button
C--> vertical scrollbar

-----------------------------------------------------
! !B!
!A!!
! -----
! .....!
! ! !
!! !
!!C!
!! !
!! !
!!!
!!!
!!!
!!.... !
------------------------------------------------------

If I set that condition, I cnt place button in the postion B.
Thats why I am using seperate vertical ScrollBar.

Please help to me if you know the implementation of Vertical scrollbar.

Thanks
Manohar Rudra
Manohar Rudra  Monday, May 11, 2009 12:13 PM

I see, but you're going to have to go through a lot of trouble getting that custom vertical scrollbar working. You will have to use Win API to manually scroll the textbox DC (that's easy). And then you need some way of telling when thetextbox is scrolled due to the cursor being moved (that's hard). My suggestion is to find some other way to fit this button of yours into the design. It's just too much work for such a small detail.

/Calle


- Still confused, but on a higher level -
Calle Mellergardh  Monday, May 11, 2009 3:50 PM
Hi Calle,

Is there any way to fit the button in my design.

Thanks
Manohar
Manohar Rudra  Tuesday, May 12, 2009 5:57 AM

Yes, but that means outside the textbox if you need the scrollbar as well. Is it really that bad to have the button somewhere else. I can understand your idea with having the button integrated with the textbox but its going to take you a while to get there :)
Being in VB6 doesn't make it easier. In VB.NET there would have been a chance but theres little or no support for developing fully fledged ActiveX controls in .NET so I guess that's out of the question.

/Calle


- Still confused, but on a higher level -
Calle Mellergardh  Tuesday, May 12, 2009 6:17 AM

You can use google to search for other answers

Custom Search

More Threads

• List type property, designer update problem
• Windows Form with User control and Tab Index / Tab Stop Help
• Bug, anchored control on inherited form, System.Windows.Forms
• Styling in WinForm Applications?
• How to generate "this.components = new System.ComponentModel.Container();" for component ?
• Problem with TableLayoutPanel on localizable forms
• Background image in form MDI
• VS2005 CryptographicException when adding SqlDataAdapter
• Disabling the .NET IDE option
• VS 2005 RTM WINFORM DESIGNER BUG IS DRIVING ME CRAZY