OVH Cloud OVH Cloud

Supprimer le ScrollBar dans un ListBox

5 réponses
Avatar
Boris Sargos
Salut à tous,

connaissez-vous un moyen pour ne pas afficher le ScrollBar d'un ListBox ?

Merci et à bientôt.

5 réponses

Avatar
Zoury
Salut Boris!

Regarde du côté des propriétés ScrollAlwaysVisible et HorizontalScrollBar du
ListBox

--
Cordialement
Yanick
MVP pour Visual Basic
"Boris Sargos" a écrit dans le message de
news:41e3be23$0$8030$
Salut à tous,

connaissez-vous un moyen pour ne pas afficher le ScrollBar d'un ListBox ?

Merci et à bientôt.


Avatar
Boris Sargos
Zoury a écrit :
Salut Boris!

Regarde du côté des propriétés ScrollAlwaysVisible et HorizontalScrollBar du
ListBox




Merci Zoury,

j'ai en effet d'abord regardé ces propriétés avant de poster ce message.
Mais en fait, ce que je souhiate, c'est que la VerticalScrollBar ne soit
JAMAIS visible, même si le nombre d'items que contient la collection
ListBoxItemCollection est supérieur à celui que la ListBox peut afficher.

La propriété ScollAlwaysVisible ne gère pas cela, mais seulement la
possibilité de TOUJOURS afficher la VerticalScrollBar.

Merci pour ton aide.

Boris.
Avatar
Zoury
Salut Boris!

La propriété ScollAlwaysVisible ne gère pas cela, mais seulement la
possibilité de TOUJOURS afficher la VerticalScrollBar.



ah! c'est le fun à savoir. désolé pour la réponse.

Pour résourdre ce problème, il faudra se tourner du côté des APIs...

Voici un exemple d'utilisation de la foncton ShowScrollBar() qui fera ce que
tu veux :
'***
Option Explicit On

Imports System.Runtime.InteropServices

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Code généré par le Concepteur Windows Form "

Public Sub New()
MyBase.New()

'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()

'Ajoutez une initialisation quelconque après l'appel
InitializeComponent()

End Sub

'La méthode substituée Dispose du formulaire pour nettoyer la liste des
composants.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer

'REMARQUE : la procédure suivante est requise par le Concepteur Windows
Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.ListBox1 = New System.Windows.Forms.ListBox
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'ListBox1
'
Me.ListBox1.Location = New System.Drawing.Point(32, 16)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.ScrollAlwaysVisible = True
Me.ListBox1.Size = New System.Drawing.Size(160, 160)
Me.ListBox1.TabIndex = 0
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(120, 184)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.ListBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Private Const SB_HORZ As Int32 = 0
Private Const SB_VERT As Int32 = 1
Private Const SB_CTL As Int32 = 2
Private Const SB_BOTH As Int32 = 3

'BOOL ShowScrollBar(
' HWND hWnd,
' int wBar,
' BOOL(bShow)
<DllImport("user32.dll")> _
Private Shared Function ShowScrollBar _
( _
ByVal hWnd As IntPtr, _
ByVal wBar As Int32, _
ByVal bShow As Boolean) As Boolean
'
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
' on cache la scrollbar vertical
ShowScrollBar(ListBox1.Handle, SB_VERT, False)
End Sub

End Class
'***

En cliquant sur le bouton, tu devrais voir la barre vertical disparaitre de
la liste...

--
Cordialement
Yanick
MVP pour Visual Basic

Merci pour ton aide.

Boris.


Avatar
Zoury
dooo! c'est ça que ça donne d'avoir trop de liste de groupes en même temps..
;O)

ex c#
//***
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;

namespace ShowScrollBarProject
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null;

private const Int32 SB_HORZ = 0;
private const Int32 SB_VERT = 1;
private const Int32 SB_CTL = 2;
private const Int32 SB_BOTH = 3;

//BOOL ShowScrollBar(
// HWND hWnd,
//int wBar,
// BOOL(bShow)
[DllImport("user32.dll")]
private extern static bool ShowScrollBar(
IntPtr hWnd,
Int32 wBar,
bool bShow);

public Form1()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}


#region Code généré par le Concepteur Windows Form
/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne modifiez
pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private void InitializeComponent()
{
this.listBox1 = new System.Windows.Forms.ListBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// listBox1
//
this.listBox1.Location = new System.Drawing.Point(8, 8);
this.listBox1.Name = "listBox1";
this.listBox1.ScrollAlwaysVisible = true;
this.listBox1.Size = new System.Drawing.Size(168, 160);
this.listBox1.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(104, 176);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button1);
this.Controls.Add(this.listBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
ShowScrollBar(listBox1.Handle, SB_VERT, false);
}
}
}
//***

--
Cordialement
Yanick
MVP pour Visual Basic
"Zoury" <yanick_lefebvre at hotmail dot com> a écrit dans le message de
news:%23yuBI5B%
Salut Boris!

> La propriété ScollAlwaysVisible ne gère pas cela, mais seulement la
> possibilité de TOUJOURS afficher la VerticalScrollBar.

ah! c'est le fun à savoir. désolé pour la réponse.

Pour résourdre ce problème, il faudra se tourner du côté des APIs...

Voici un exemple d'utilisation de la foncton ShowScrollBar() qui fera ce


que
tu veux :
'***
Option Explicit On

Imports System.Runtime.InteropServices

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Code généré par le Concepteur Windows Form "

Public Sub New()
MyBase.New()

'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()

'Ajoutez une initialisation quelconque après l'appel
InitializeComponent()

End Sub

'La méthode substituée Dispose du formulaire pour nettoyer la liste


des
composants.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer

'REMARQUE : la procédure suivante est requise par le Concepteur


Windows
Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.ListBox1 = New System.Windows.Forms.ListBox
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'ListBox1
'
Me.ListBox1.Location = New System.Drawing.Point(32, 16)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.ScrollAlwaysVisible = True
Me.ListBox1.Size = New System.Drawing.Size(160, 160)
Me.ListBox1.TabIndex = 0
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(120, 184)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.ListBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Private Const SB_HORZ As Int32 = 0
Private Const SB_VERT As Int32 = 1
Private Const SB_CTL As Int32 = 2
Private Const SB_BOTH As Int32 = 3

'BOOL ShowScrollBar(
' HWND hWnd,
' int wBar,
' BOOL(bShow)
<DllImport("user32.dll")> _
Private Shared Function ShowScrollBar _
( _
ByVal hWnd As IntPtr, _
ByVal wBar As Int32, _
ByVal bShow As Boolean) As Boolean
'
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
' on cache la scrollbar vertical
ShowScrollBar(ListBox1.Handle, SB_VERT, False)
End Sub

End Class
'***

En cliquant sur le bouton, tu devrais voir la barre vertical disparaitre


de
la liste...

--
Cordialement
Yanick
MVP pour Visual Basic
>
> Merci pour ton aide.
>
> Boris.




Avatar
Boris Sargos
Salut Zoury,

ta solution n'a pas l'air mal. Je la testerai demain.
Merci pour ton aide.
Boris