NeuroCypher
Messages postés29Date d'inscriptionvendredi 20 janvier 2006StatutMembreDernière intervention24 octobre 2007
-
30 janv. 2007 à 15:30
NeuroCypher
Messages postés29Date d'inscriptionvendredi 20 janvier 2006StatutMembreDernière intervention24 octobre 2007
-
31 janv. 2007 à 12:08
Bonjour,
Je veux recuperer la position de la VerticalScrollBar d'un RichTextBox
lorsque cette meme scrollbar a fini de bouger...
J'ai donc commence par creer une classe ScrollingRichtTextBox qui herite de RichTextBox
qui contient un override de WndProc qui me permet de recevoir les events sur la scrollbar:
protected override void WndProc(ref Message msg)
{
if (msg.Msg == WM_VSCROLL)
{
if (Scrolled != null)
{
ScrollInfoStruct si = new ScrollInfoStruct();
si.fMask = SIF_ALL;
si.cbSize = (uint)Marshal.SizeOf(si);
GetScrollInfo(msg.HWnd, SB_VERT, ref si);
if (msg.WParam.ToInt32() == SB_ENDSCROLL)
{
ScrollEventArgs sargs = new ScrollEventArgs(
ScrollEventType.EndScroll, si.nPos);
Scrolled(this, sargs);
}
}
}
base.WndProc(ref msg);
}
Pour etre le plus clair et proche de la realite possible,
j'ai declare les macros en const dans la classe (cf: msdn, winuser.h, google....):
private const int WM_HSCROLL = 0x114;
private const int WM_VSCROLL = 0x115;
private const int SB_HORZ = 0;
private const int SB_VERT = 1;
private const int SB_LINELEFT = 0;
private const int SB_LINERIGHT = 1;
private const int SB_PAGELEFT = 2;
private const int SB_PAGERIGHT = 3;
private const int SB_THUMBPOSITION = 4;
private const int SB_THUMBTRACK = 5;
private const int SB_LEFT = 6;
private const int SB_RIGHT = 7;
private const int SB_ENDSCROLL = 8;
private const int SIF_TRACKPOS = 0x10;
private const int SIF_RANGE = 0x1;
private const int SIF_POS = 0x4;
private const int SIF_PAGE = 0x2;
private const int SIF_ALL = SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS;
J'ai aussi declare un event "Scrolled" :
[Category("Action")]
public event ScrollEventHandler Scrolled = null;
Cette event est alors manage dans mon designer de Form qui appele une methode de la FormClass, comme suit:
this._viewBox.Scrolled += new System.Windows.Forms.ScrollEventHandler(this._viewBoxScrolled);
Et voici la methode:
private void _viewBoxScrolled(object sender, System.Windows.Forms.ScrollEventArgs e)
{
System.Windows.Forms.MessageBox.Show("okk\n" +
e.OldValue.ToString() + "\n" +
e.Type.ToString() + "\n" +
e.ToString() + "\n" +
e.ScrollOrientation.ToString() + "\n"
);
}
<hr size="2" width="100%" />
Tout ce code "fonctionne"...
Seulement le probleme est le suivant:
La methode est bien appelee lorsqu'un ENDSCROLL sur la VerticalScrollBar est emis...
Mais en argument je recois les informations de la HorizontalScrollBar.
Pourtant dans le GetScrollInfo je precise bien en 2e argument un SB_VERT (0x1 = 1)
qui est la flag correspondant a la VerticalBar....
Cela fait un moment que je cherche...
J'ai essaye tout ce qui me passait par la tete je suis vraiment depite la.
J'ai peut-etre fait une erreur toute bete, en tout cas je ne la vois pas.
Je sollicite donc votre aide.
Merci par avance.
---
NeuroCypher
Etudiant en 3e annee d'un cursus de 5ans
Programmation et Reseaux {EPITECH}
A voir également:
GetScrollInfo sur VerticalScrollBar d'un RichTextBox
Lutinore
Messages postés3246Date d'inscriptionlundi 25 avril 2005StatutMembreDernière intervention27 octobre 201241 31 janv. 2007 à 07:20
Salut, ça donne quoi avec cette classe..
public class MyRichTextBox : RichTextBox
{
private enum SIF
{
RANGE = 0x0001,
PAGE = 0x0002,
POS = 0x0004,
DISABLENOSCROLL = 0x0008,
TRACKPOS = 0x0010,
ALL = RANGE | PAGE | POS | TRACKPOS
}
[ StructLayout( LayoutKind.Sequential ) ]
private struct SCROLLINFO
{
public uint cbSize;
public uint fMask;
public int nMin;
public int nMax;
public uint nPage;
public int nPos;
public int nTrackPos;
}
NeuroCypher
Messages postés29Date d'inscriptionvendredi 20 janvier 2006StatutMembreDernière intervention24 octobre 20071 31 janv. 2007 à 12:08
Bonjour Lutinore,
Deja merci de m'avoir repondu...
En lisant ton code je me suis rendu compte qu'en effet je n'avais pas regarder
les differents constructeurs de ScrollEventArgs, car j'etais focaliser sur le GetScrollInfo.
Mon erreur etait en fait toute bete...
J'affichais OldValue au lieu de NewValue et comme tu l'as precise je n'avais pas defini le OldValue...
Et comme je n'avais pas preciser le VerticalBar non plus l 'affichage de Horizontal me perturbait.
Merci beaucoup.
---
NeuroCypher
Etudiant en 3e annee d'un cursus de 5ans
Programmation et Reseaux {EPITECH}