473,425 Members | 1,983 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,425 software developers and data experts.

Scrollbar position - it can't be determined !

Hello experts, this is a repost but I have been (much) more clear.

I want to know the position of the horizontal scrollbar in a textbox
as a percentage

- if the horizontal scrollbar is hard left,
I want to display 0% on the form.
- if the horizontal scrollbar is smack in the middle,
I want to display 50% on the form.
- if the horizontal scrollbar is 2/3rd along the X-axis,
I want to display 66% on the form.
- if the horozontal scrollbar is hard right,
I want to display 100% on the form.

etc.

I can't figure out how to do it and, currently, think it can't be
done.

These are the steps I have used to create my application.
1. Launch Visual Studio 2003 and create a new project
"Form1" will show.
2. Move the cursor to the toolbox, select a textbox, and
draw one on the form.
3. Go to the properties and set "Scrollbars" to "Horizontal",
"WordWrap" to "False", and "MultiLine" to "True"
4. Type in a sentence "the quick brown fox jumps over the
lazy dog..". Eventually the horizontal scrollbar will
appear.
Now how on earth do I get the current scrollbar position, and the
maximum position, to determine the percentage
(currentScrollbarPositionX/maxScrollbarPositionX)*100/1 ?

When I Google search microsoft.public.dotnet.languages.vb, no luck.
I'd rather have someone post "It can't be done" rather than the thread
sit there with one entry, mine :( So, can it be done?

Thanks, a desperate Colin !
Nov 20 '05 #1
6 10913
'-- Get String width
Dim sz as SizeF = e.Graphics.MeasureString(TextBox1.Text,TextBox.Fon t)

'-- Then divide
Textbox1.width / sz.width

"Colin McGuire" <co***********@lycos.co.uk> wrote in message
news:ab**************************@posting.google.c om...
Hello experts, this is a repost but I have been (much) more clear.

I want to know the position of the horizontal scrollbar in a textbox
as a percentage

- if the horizontal scrollbar is hard left,
I want to display 0% on the form.
- if the horizontal scrollbar is smack in the middle,
I want to display 50% on the form.
- if the horizontal scrollbar is 2/3rd along the X-axis,
I want to display 66% on the form.
- if the horozontal scrollbar is hard right,
I want to display 100% on the form.

etc.

I can't figure out how to do it and, currently, think it can't be
done.

These are the steps I have used to create my application.
1. Launch Visual Studio 2003 and create a new project
"Form1" will show.
2. Move the cursor to the toolbox, select a textbox, and
draw one on the form.
3. Go to the properties and set "Scrollbars" to "Horizontal",
"WordWrap" to "False", and "MultiLine" to "True"
4. Type in a sentence "the quick brown fox jumps over the
lazy dog..". Eventually the horizontal scrollbar will
appear.
Now how on earth do I get the current scrollbar position, and the
maximum position, to determine the percentage
(currentScrollbarPositionX/maxScrollbarPositionX)*100/1 ?

When I Google search microsoft.public.dotnet.languages.vb, no luck.
I'd rather have someone post "It can't be done" rather than the thread
sit there with one entry, mine :( So, can it be done?

Thanks, a desperate Colin !

Nov 20 '05 #2
No - this is not what he wants,. Th only returns a constant for a certain
text in a textbox - if the HScrollbar is half way across a long line, same
constant, if the HScrollbar is hard left to use his words, same constant.

Colin I don't have an answer - gut feeling is that you should subclass the
textbox and play around with the properties AutoScrollPosition and Location.

Here to help and be helped.
Frederic Marč

"Brian" <no****@prairie.lakes.com> wrote in message
news:vn************@corp.supernews.com...
'-- Get String width
Dim sz as SizeF = e.Graphics.MeasureString(TextBox1.Text,TextBox.Fon t)

'-- Then divide
Textbox1.width / sz.width

"Colin McGuire" <co***********@lycos.co.uk> wrote in message
news:ab**************************@posting.google.c om...
Hello experts, this is a repost but I have been (much) more clear.

I want to know the position of the horizontal scrollbar in a textbox
as a percentage

- if the horizontal scrollbar is hard left,
I want to display 0% on the form.
- if the horizontal scrollbar is smack in the middle,
I want to display 50% on the form.
- if the horizontal scrollbar is 2/3rd along the X-axis,
I want to display 66% on the form.
- if the horozontal scrollbar is hard right,
I want to display 100% on the form.

etc.

I can't figure out how to do it and, currently, think it can't be
done.

These are the steps I have used to create my application.
1. Launch Visual Studio 2003 and create a new project
"Form1" will show.
2. Move the cursor to the toolbox, select a textbox, and
draw one on the form.
3. Go to the properties and set "Scrollbars" to "Horizontal",
"WordWrap" to "False", and "MultiLine" to "True"
4. Type in a sentence "the quick brown fox jumps over the
lazy dog..". Eventually the horizontal scrollbar will
appear.
Now how on earth do I get the current scrollbar position, and the
maximum position, to determine the percentage
(currentScrollbarPositionX/maxScrollbarPositionX)*100/1 ?

When I Google search microsoft.public.dotnet.languages.vb, no luck.
I'd rather have someone post "It can't be done" rather than the thread
sit there with one entry, mine :( So, can it be done?

Thanks, a desperate Colin !


Nov 20 '05 #3
I think you could do some experiementation and find the empirical data you
need.

Try filling a combo box with 10, 100, 200 and 400 strings. Thenwork out how
many clicks it takes to reach the end. This way you could get a round
percentage if it is a linear function.

OHM
Colin McGuire wrote:
Hello experts, this is a repost but I have been (much) more clear.

I want to know the position of the horizontal scrollbar in a textbox
as a percentage

- if the horizontal scrollbar is hard left,
I want to display 0% on the form.
- if the horizontal scrollbar is smack in the middle,
I want to display 50% on the form.
- if the horizontal scrollbar is 2/3rd along the X-axis,
I want to display 66% on the form.
- if the horozontal scrollbar is hard right,
I want to display 100% on the form.

etc.

I can't figure out how to do it and, currently, think it can't be
done.

These are the steps I have used to create my application.
1. Launch Visual Studio 2003 and create a new project
"Form1" will show.
2. Move the cursor to the toolbox, select a textbox, and
draw one on the form.
3. Go to the properties and set "Scrollbars" to "Horizontal",
"WordWrap" to "False", and "MultiLine" to "True"
4. Type in a sentence "the quick brown fox jumps over the
lazy dog..". Eventually the horizontal scrollbar will
appear.
Now how on earth do I get the current scrollbar position, and the
maximum position, to determine the percentage
(currentScrollbarPositionX/maxScrollbarPositionX)*100/1 ?

When I Google search microsoft.public.dotnet.languages.vb, no luck.
I'd rather have someone post "It can't be done" rather than the thread
sit there with one entry, mine :( So, can it be done?

Thanks, a desperate Colin !

Nov 20 '05 #4
Sorry, I was thinking vertical.

One Handed Man wrote:
I think you could do some experiementation and find the empirical
data you need.

Try filling a combo box with 10, 100, 200 and 400 strings. Thenwork
out how many clicks it takes to reach the end. This way you could get
a round percentage if it is a linear function.

OHM
Colin McGuire wrote:
Hello experts, this is a repost but I have been (much) more clear.

I want to know the position of the horizontal scrollbar in a textbox
as a percentage

- if the horizontal scrollbar is hard left,
I want to display 0% on the form.
- if the horizontal scrollbar is smack in the middle,
I want to display 50% on the form.
- if the horizontal scrollbar is 2/3rd along the X-axis,
I want to display 66% on the form.
- if the horozontal scrollbar is hard right,
I want to display 100% on the form.

etc.

I can't figure out how to do it and, currently, think it can't be
done.

These are the steps I have used to create my application.
1. Launch Visual Studio 2003 and create a new project
"Form1" will show.
2. Move the cursor to the toolbox, select a textbox, and
draw one on the form.
3. Go to the properties and set "Scrollbars" to "Horizontal",
"WordWrap" to "False", and "MultiLine" to "True"
4. Type in a sentence "the quick brown fox jumps over the
lazy dog..". Eventually the horizontal scrollbar will
appear.
Now how on earth do I get the current scrollbar position, and the
maximum position, to determine the percentage
(currentScrollbarPositionX/maxScrollbarPositionX)*100/1 ?

When I Google search microsoft.public.dotnet.languages.vb, no luck.
I'd rather have someone post "It can't be done" rather than the
thread sit there with one entry, mine :( So, can it be done?

Thanks, a desperate Colin !

Nov 20 '05 #5
Sorry for my first bone headed response. This is what you need. You have to
inherit a text box and the override the wndProc.
Here's the code that you need. Please note that the max position and the
thumb position won't be the same at the end.
This is what happened (when i tried it) when the scroll bar is at the start
and at very end.

Example: Begin Scroll min = 0 End Scroll min =0
max=184
max = 184
npos =0
npos =111 ' Diff of page 184-111 = 73 (close enough)
page =74
page = 74

Imports System.Runtime.InteropServices.Marshal

Public Class UserControl1
Inherits System.Windows.Forms.TextBox
'-- Declare
Private Declare Function GetScrollInfo Lib "user32" (ByVal hWnd As
IntPtr, ByVal n As Integer, ByRef lpScrollInfo As SCROLLINFO) As Integer

'-- Const
Private Const WM_HSCROLL = &H114 '276
Private Const SB_HORZ = 0
Private Const SIF_TRACKPOS = &H10
Private Const SIF_RANGE = &H1
Private Const SIF_POS = &H4
Private Const SB_THUMBTRACK = 5
Private Const SIF_PAGE = &H2
Private Const SIF_ALL = SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS

'-- Info Struct
Private Structure SCROLLINFO
Public cbSize As Integer
Public fMask As Integer
Public nMin As Integer
Public nMax As Integer
Public nPage As Integer
Public nPos As Integer
Public nTrackPos As Integer
End Structure

'-- Variable
Dim i As New SCROLLINFO()
'-- Override the windows procedure
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

'-- If scrolling ---------
If m.Msg = WM_HSCROLL Then

'-- Set Mask to all
i.fMask = SIF_ALL

'-- Set size of structure
i.cbSize = SizeOf(i)

'-- Get the info
GetScrollInfo(m.HWnd, 0, i)

'-- Min Value
Debug.WriteLine(i.nMin.ToString)

'-- Max Value
Debug.WriteLine(i.nMax.ToString)

'-- Page Info
Debug.WriteLine(i.nPage.ToString)

'-- Position
Debug.WriteLine(i.nPos)

End If

'-- Call Base
MyBase.WndProc(m)

End Sub
End Class

"Colin McGuire" <co***********@lycos.co.uk> wrote in message
news:ab**************************@posting.google.c om...
Hello experts, this is a repost but I have been (much) more clear.

I want to know the position of the horizontal scrollbar in a textbox
as a percentage

- if the horizontal scrollbar is hard left,
I want to display 0% on the form.
- if the horizontal scrollbar is smack in the middle,
I want to display 50% on the form.
- if the horizontal scrollbar is 2/3rd along the X-axis,
I want to display 66% on the form.
- if the horozontal scrollbar is hard right,
I want to display 100% on the form.

etc.

I can't figure out how to do it and, currently, think it can't be
done.

These are the steps I have used to create my application.
1. Launch Visual Studio 2003 and create a new project
"Form1" will show.
2. Move the cursor to the toolbox, select a textbox, and
draw one on the form.
3. Go to the properties and set "Scrollbars" to "Horizontal",
"WordWrap" to "False", and "MultiLine" to "True"
4. Type in a sentence "the quick brown fox jumps over the
lazy dog..". Eventually the horizontal scrollbar will
appear.
Now how on earth do I get the current scrollbar position, and the
maximum position, to determine the percentage
(currentScrollbarPositionX/maxScrollbarPositionX)*100/1 ?

When I Google search microsoft.public.dotnet.languages.vb, no luck.
I'd rather have someone post "It can't be done" rather than the thread
sit there with one entry, mine :( So, can it be done?

Thanks, a desperate Colin !

Nov 20 '05 #6
Sorry Brian - yes thank you very much. I am using it right now.
Colin

"Brian" <no****@prairie.lakes.com> wrote in message news:<vn************@corp.supernews.com>...
Sorry for my first bone headed response. This is what you need. You have to
inherit a text box and the override the wndProc.
Here's the code that you need. Please note that the max position and the
thumb position won't be the same at the end.
This is what happened (when i tried it) when the scroll bar is at the start
and at very end.

Example: Begin Scroll min = 0 End Scroll min =0
max=184
max = 184
npos =0
npos =111 ' Diff of page 184-111 = 73 (close enough)
page =74
page = 74

Imports System.Runtime.InteropServices.Marshal

Public Class UserControl1
Inherits System.Windows.Forms.TextBox
'-- Declare
Private Declare Function GetScrollInfo Lib "user32" (ByVal hWnd As
IntPtr, ByVal n As Integer, ByRef lpScrollInfo As SCROLLINFO) As Integer

'-- Const
Private Const WM_HSCROLL = &H114 '276
Private Const SB_HORZ = 0
Private Const SIF_TRACKPOS = &H10
Private Const SIF_RANGE = &H1
Private Const SIF_POS = &H4
Private Const SB_THUMBTRACK = 5
Private Const SIF_PAGE = &H2
Private Const SIF_ALL = SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS

'-- Info Struct
Private Structure SCROLLINFO
Public cbSize As Integer
Public fMask As Integer
Public nMin As Integer
Public nMax As Integer
Public nPage As Integer
Public nPos As Integer
Public nTrackPos As Integer
End Structure

'-- Variable
Dim i As New SCROLLINFO()
'-- Override the windows procedure
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

'-- If scrolling ---------
If m.Msg = WM_HSCROLL Then

'-- Set Mask to all
i.fMask = SIF_ALL

'-- Set size of structure
i.cbSize = SizeOf(i)

'-- Get the info
GetScrollInfo(m.HWnd, 0, i)

'-- Min Value
Debug.WriteLine(i.nMin.ToString)

'-- Max Value
Debug.WriteLine(i.nMax.ToString)

'-- Page Info
Debug.WriteLine(i.nPage.ToString)

'-- Position
Debug.WriteLine(i.nPos)

End If

'-- Call Base
MyBase.WndProc(m)

End Sub
End Class

"Colin McGuire" <co***********@lycos.co.uk> wrote in message
news:ab**************************@posting.google.c om...
Hello experts, this is a repost but I have been (much) more clear.

I want to know the position of the horizontal scrollbar in a textbox
as a percentage

- if the horizontal scrollbar is hard left,
I want to display 0% on the form.
- if the horizontal scrollbar is smack in the middle,
I want to display 50% on the form.
- if the horizontal scrollbar is 2/3rd along the X-axis,
I want to display 66% on the form.
- if the horozontal scrollbar is hard right,
I want to display 100% on the form.

etc.

I can't figure out how to do it and, currently, think it can't be
done.

These are the steps I have used to create my application.
1. Launch Visual Studio 2003 and create a new project
"Form1" will show.
2. Move the cursor to the toolbox, select a textbox, and
draw one on the form.
3. Go to the properties and set "Scrollbars" to "Horizontal",
"WordWrap" to "False", and "MultiLine" to "True"
4. Type in a sentence "the quick brown fox jumps over the
lazy dog..". Eventually the horizontal scrollbar will
appear.
Now how on earth do I get the current scrollbar position, and the
maximum position, to determine the percentage
(currentScrollbarPositionX/maxScrollbarPositionX)*100/1 ?

When I Google search microsoft.public.dotnet.languages.vb, no luck.
I'd rather have someone post "It can't be done" rather than the thread
sit there with one entry, mine :( So, can it be done?

Thanks, a desperate Colin !

Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: alvinpoon | last post by:
Hello, I have a problem setting the scrollbar position of a div region on a webpage which is posted at http://www.geocities.com/virtuosity999/Logon.htm If the page is loaded with Netscape,...
4
by: Paul T. RONG | last post by:
Dear all, Can one control the subform scrollbar through vba? For example, I would like to make two command buttons on the main form to control the subform scrollbar. Click 1st button the...
1
by: gmtongar | last post by:
Hi, I've made a custom scrollbar which consists of three buttons and a panel. My problem is: How do I move it like a scrollbar slider? I've tried DoDragDrop, but it does not appear to be the same,...
0
by: ZenMaster | last post by:
Hello, can anyone help me figure out what may be wrong with my code - In VC++ 6.0 Ive created a ScrollBar using : -------------------------------------------- hwndScrollHue = CreateWindowEx...
6
by: Jorge Luzarraga Castro | last post by:
Hey, hope you can help with this. I have an aspx page which contains several User Control. At the beggining there´s only one visible User Control but after working with the page additional UC...
5
by: Frank Rizzo | last post by:
I reload the items in the listview on a regular schedule (i.e. clear the listview, then load it up with fresh values). I want add a convinience to the user whereby my application remembers the...
0
by: onzinnig | last post by:
Hello, I have a problem where a frame does not repaint a part of a window when using the horizontal scrollbar. Easier then explaining is to try out the two html pages at the bottom of this...
1
by: qhimq | last post by:
Hi, I have a lot of edit child windows and text painted on a windows application made from the API all at runtime. How do I go about making the scrollbar to move them all? What I attempted: ...
2
by: Appu2008 | last post by:
Hi, Iam using Python 2.5 and developing an application using Tkinter. I want a listbox with scrollbar. I tried to combine both but it gets filled in the entire screen. Here is the code.. ...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.