Hiding Vertical Scrollbar in Listbox

G

Guest

Hi
I am working on pocket pc and using .NetCF. We disable any stylus operation
to protect the screen from scratches, as a part of which we disable any
vertical scroll bars operation.
Can someone please let me know how I can hide a vertical scroll bar over a
listbox. The below code works fine for a datagrid but not for a list box.

string[] list = {"one","two","three","four","five","six","seven"};
listBox1.DataSource = list;

foreach(Control c in listBox1.Controls)
{
if(c.GetType().Equals(typeof(VScrollBar)))
{
((VScrollBar)c).Width = 0;
((VScrollBar)c).Hide();
}
}

Thanks,
Naresh Mirkhelkar
 
G

Guest

The list box is a windows control and the scroll bar will, I imagine, be an
internal control that is not exposed to developers.

If you don't want to allow scrolling, why not limit the number of entries in
the listbox so that they always fit.

You can remove the VSCROLL flag like this (desktop example):

[DllImport("user32.dll")]
public extern static int SetWindowLong(
IntPtr hwnd, int nIndex, int newLong);

[DllImport("user32.dll")]
public extern static int GetWindowLong(
IntPtr hwnd, int nIndex);

int oldStyle = GetWindowLong(listBox1.Handle, GWL_STYLE);
int newStyle = oldStyle & (~WS_VSCROLL);
SetWindowLong(listBox1.Handle, GWL_STYLE, oldStyle);

but I'm not convinced it is that good an idea, you may need to resize the
window to avoid redraw problems where the scrollbar should be.

If I had to do this I would limit the number of entries so a scroll bar
never appears.

Peter
 
G

Guest

Hi Peter,
Thank you for the response.
Handle property is not available for list boxes in Compact framework, and
also I get a missing method exception for GetWindowLong(...), it seems this
method is not available in user32.dll for pocket PC. I guess (as you have
also metioned), this might work for Desktop and not for Pocket PCs
Thanks,
Naresh
Peter said:
The list box is a windows control and the scroll bar will, I imagine, be an
internal control that is not exposed to developers.

If you don't want to allow scrolling, why not limit the number of entries in
the listbox so that they always fit.

You can remove the VSCROLL flag like this (desktop example):

[DllImport("user32.dll")]
public extern static int SetWindowLong(
IntPtr hwnd, int nIndex, int newLong);

[DllImport("user32.dll")]
public extern static int GetWindowLong(
IntPtr hwnd, int nIndex);

int oldStyle = GetWindowLong(listBox1.Handle, GWL_STYLE);
int newStyle = oldStyle & (~WS_VSCROLL);
SetWindowLong(listBox1.Handle, GWL_STYLE, oldStyle);

but I'm not convinced it is that good an idea, you may need to resize the
window to avoid redraw problems where the scrollbar should be.

If I had to do this I would limit the number of entries so a scroll bar
never appears.

Peter

Naresh Mirkhelkar said:
Hi
I am working on pocket pc and using .NetCF. We disable any stylus operation
to protect the screen from scratches, as a part of which we disable any
vertical scroll bars operation.
Can someone please let me know how I can hide a vertical scroll bar over a
listbox. The below code works fine for a datagrid but not for a list box.

string[] list = {"one","two","three","four","five","six","seven"};
listBox1.DataSource = list;

foreach(Control c in listBox1.Controls)
{
if(c.GetType().Equals(typeof(VScrollBar)))
{
((VScrollBar)c).Width = 0;
((VScrollBar)c).Hide();
}
}

Thanks,
Naresh Mirkhelkar
 
G

Guest

Hi Naresh,

you may want to try using

[DllImport("coredll.dll")]

on the pocket PC.

The window Handle can apparently be accessed like this:

listBox.Capture = true;
IntPtr m_hWnd = GetCapture();
listBox.Capture = false;

GetCapture needs to be p-invoked as well. I'm still not convinced it will
work, though.

Cheers,

Peter

Naresh Mirkhelkar said:
Hi Peter,
Thank you for the response.
Handle property is not available for list boxes in Compact framework, and
also I get a missing method exception for GetWindowLong(...), it seems this
method is not available in user32.dll for pocket PC. I guess (as you have
also metioned), this might work for Desktop and not for Pocket PCs
Thanks,
Naresh
Peter said:
The list box is a windows control and the scroll bar will, I imagine, be an
internal control that is not exposed to developers.

If you don't want to allow scrolling, why not limit the number of entries in
the listbox so that they always fit.

You can remove the VSCROLL flag like this (desktop example):

[DllImport("user32.dll")]
public extern static int SetWindowLong(
IntPtr hwnd, int nIndex, int newLong);

[DllImport("user32.dll")]
public extern static int GetWindowLong(
IntPtr hwnd, int nIndex);

int oldStyle = GetWindowLong(listBox1.Handle, GWL_STYLE);
int newStyle = oldStyle & (~WS_VSCROLL);
SetWindowLong(listBox1.Handle, GWL_STYLE, oldStyle);

but I'm not convinced it is that good an idea, you may need to resize the
window to avoid redraw problems where the scrollbar should be.

If I had to do this I would limit the number of entries so a scroll bar
never appears.

Peter

Naresh Mirkhelkar said:
Hi
I am working on pocket pc and using .NetCF. We disable any stylus operation
to protect the screen from scratches, as a part of which we disable any
vertical scroll bars operation.
Can someone please let me know how I can hide a vertical scroll bar over a
listbox. The below code works fine for a datagrid but not for a list box.

string[] list = {"one","two","three","four","five","six","seven"};
listBox1.DataSource = list;

foreach(Control c in listBox1.Controls)
{
if(c.GetType().Equals(typeof(VScrollBar)))
{
((VScrollBar)c).Width = 0;
((VScrollBar)c).Hide();
}
}

Thanks,
Naresh Mirkhelkar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top