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

Scroll bars in treeview - how can you get onscroll as well as theirposition?

I've looked around msdn for about an hour now and can't figure out how
to place an event when the user scrolls, or even how to get the value of
where the scroll bar is actually placed...

Anyone know how to use this event, or how to get the scroll bar info?

~Benny
Nov 16 '05 #1
3 14686
Hi Benny

I have the same problem that u faced. And I see that there are no replies
with solutions. If you have found the solution please let me know how to go
about it.

Thanks and Regards,
Manu

"Benny Raymond" wrote:
I've looked around msdn for about an hour now and can't figure out how
to place an event when the user scrolls, or even how to get the value of
where the scroll bar is actually placed...

Anyone know how to use this event, or how to get the scroll bar info?

~Benny

Nov 16 '05 #2
Hi Benny and Manu,

I wrote this class to add the scroll event and 2 getters to have the
horizontal and vertical position of the scrollbars.
Assume your Treeview is named myTreeView ( TreeViewScroll myTreeView) :
To get the horizontal position, use myTreeView.HScrollPos (be careful of
the unit. I think it's in pixels)
To get the vertical position use myTreeView.VScrollPos (be careful of the
unit. I think it's in lines)
To add a listener for the scrollbars use myTreeView.Scroll+=new
ScrollEventHandler(myTreeView_Scroll);
This event is almost the same as the usual scroll event for a control. The
only difference is that the newValue is not set when event like
small(de)increment or large(de)increment occurs. If you want so, use the
getters and the scrolltype to determine the newValue or calculate it in the
WndProc. For events like thumbposition or thumbtrack, everything is
correctly filled.

Here is the source code :

using System;
using System.Windows.Forms;
public class TreeViewScroll:TreeView {
private const int SB_HORZ=0;
private const int SB_VERT=1;
[System.Runtime.InteropServices.DllImport("user32.d ll")]
private static extern int GetScrollPos(int hWnd,int nBar);
public int HScrollPos {
get {return GetScrollPos((int)Handle,SB_VERT);}
}
public int VScrollPos {
get {return GetScrollPos((int)Handle,SB_HORZ);}
}
public event ScrollEventHandler Scroll;
protected override void WndProc(ref Message m) {
if (Scroll!=null) {
switch(m.Msg) {
case KERMLSoftware.Helpers.Win32.WinMsg.WM_VSCROLL: {
ScrollEventType
t=(ScrollEventType)Enum.Parse(typeof(ScrollEventTy pe),
(m.WParam.ToInt32()&65535).ToString());
Scroll(m.HWnd,new
ScrollEventArgs(t,((int)(m.WParam.ToInt64()>>16))& 255));
} break;
}
}
base.WndProc (ref m);
}
}

Hope it helps,

Ludovic SOEUR.
"Manu" <Ma**@discussions.microsoft.com> a écrit dans le message de
news:34**********************************@microsof t.com...
Hi Benny

I have the same problem that u faced. And I see that there are no replies
with solutions. If you have found the solution please let me know how to go about it.

Thanks and Regards,
Manu

"Benny Raymond" wrote:
I've looked around msdn for about an hour now and can't figure out how
to place an event when the user scrolls, or even how to get the value of
where the scroll bar is actually placed...

Anyone know how to use this event, or how to get the scroll bar info?

~Benny

Nov 16 '05 #3
I have forgotten to replace all my strings. Instead of
case KERMLSoftware.Helpers.Win32.WinMsg.WM_VSCROLL : {,
use case WM_VSCROLL:case WM_HSCROLL: {
with theses consts :
private const int WM_VSCROLL=0x0115
private const int WM_HSCROLL=0x0114;

Sorry for the mistake.

Hope it helps,

Ludovic SOEUR.

"Ludovic SOEUR" <Lu***********@hotmail.com> a écrit dans le message de
news:Ou**************@TK2MSFTNGP10.phx.gbl...
Hi Benny and Manu,

I wrote this class to add the scroll event and 2 getters to have the
horizontal and vertical position of the scrollbars.
Assume your Treeview is named myTreeView ( TreeViewScroll myTreeView) :
To get the horizontal position, use myTreeView.HScrollPos (be careful of the unit. I think it's in pixels)
To get the vertical position use myTreeView.VScrollPos (be careful of the unit. I think it's in lines)
To add a listener for the scrollbars use myTreeView.Scroll+=new
ScrollEventHandler(myTreeView_Scroll);
This event is almost the same as the usual scroll event for a control. The
only difference is that the newValue is not set when event like
small(de)increment or large(de)increment occurs. If you want so, use the
getters and the scrolltype to determine the newValue or calculate it in the WndProc. For events like thumbposition or thumbtrack, everything is
correctly filled.

Here is the source code :

using System;
using System.Windows.Forms;
public class TreeViewScroll:TreeView {
private const int SB_HORZ=0;
private const int SB_VERT=1;
[System.Runtime.InteropServices.DllImport("user32.d ll")]
private static extern int GetScrollPos(int hWnd,int nBar);
public int HScrollPos {
get {return GetScrollPos((int)Handle,SB_VERT);}
}
public int VScrollPos {
get {return GetScrollPos((int)Handle,SB_HORZ);}
}
public event ScrollEventHandler Scroll;
protected override void WndProc(ref Message m) {
if (Scroll!=null) {
switch(m.Msg) {
case KERMLSoftware.Helpers.Win32.WinMsg.WM_VSCROLL: {
ScrollEventType
t=(ScrollEventType)Enum.Parse(typeof(ScrollEventTy pe),
(m.WParam.ToInt32()&65535).ToString());
Scroll(m.HWnd,new
ScrollEventArgs(t,((int)(m.WParam.ToInt64()>>16))& 255));
} break;
}
}
base.WndProc (ref m);
}
}

Hope it helps,

Ludovic SOEUR.
"Manu" <Ma**@discussions.microsoft.com> a écrit dans le message de
news:34**********************************@microsof t.com...
Hi Benny

I have the same problem that u faced. And I see that there are no replies with solutions. If you have found the solution please let me know how to

go
about it.

Thanks and Regards,
Manu

"Benny Raymond" wrote:
I've looked around msdn for about an hour now and can't figure out how
to place an event when the user scrolls, or even how to get the value of where the scroll bar is actually placed...

Anyone know how to use this event, or how to get the scroll bar info?

~Benny


Nov 16 '05 #4

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

Similar topics

12
by: Arlie Rahn | last post by:
I would like to ad a custom scroll bar control to my app that has a customizable and "flat" look to it (not the normal VB look). Does anyone have any ideas on where to find a good one?
2
by: GrantS | last post by:
I am trying to convert the VB.Net code example povided by http://authors.aspalliance.com/JimRoss/Articles/MaintainScrollPos.aspx into C# (ASP.Net)without success. No errors are thrown in the VB...
8
by: Yaron C. | last post by:
Hi, I would like to ask for your help. Please look at the code below. I would like to keep the location of the buttons while scrolling to the right but I can't get a smoth scroll (without...
1
by: Dino M. Buljubasic | last post by:
I have two controls, a panel holding check boxes and a treeview beside the panel. I use buttons to scroll both of thes up and down at the same time but I'd like to make scroll bars on the...
2
by: usenet | last post by:
When I open a form design window in Access 2003 it *always* has scroll bars, this is even when the form itself is tiny. It's as if the 'page' on which the form is being designed is very large. ...
69
by: RC | last post by:
I know how to do this in JavaScript by window.open("newFile.html", "newTarget", "scrollbars=no,resizable=0,width=200,height=200"); The browser will open a new window size 200x200, not allow...
2
by: ayebegum | last post by:
Hello, I have a problem : ( I have two grids both of which have scrollbars which as i understand it, are automatically handled by wxGrid. What i need is to bind the scrollbars so when one is...
1
by: jonceramic | last post by:
Hi all, I've tried finding an answer in the history, but only find a lot of historical posts where people didn't get answers to the same problem up to 5 or 6 years ago! I'm having a problem...
0
by: luqman | last post by:
Is it possible to display Scroll Bars in TreeView in VS 2005 ? If so, How? Best Regards, Luqman
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.