GetScrollInfo doesn't work

A

Alex Fu

I create a utility class, and call

GetScrollInfo(txtHelp, (int)ScrollBarDirection.SB_VERT);

txtHelp is a RichTextBox component instance.





Please tell me why GetScrollInfo doesn't work. Thanks.



-------------------------------------

using System;

using System.Runtime.InteropServices;



namespace Alex.Plan

{

[StructLayout(LayoutKind.Sequential)]

public struct SCROLLINFO

{

public int cbSize;

public uint fMask;

public int nMin;

public int nMax;

public uint nPage;

public int nPos;

public int nTrackPos;

}



public enum ScrollBarDirection

{

SB_HORZ = 0,

SB_VERT = 1,

SB_CTL = 2,

SB_BOTH = 3

}



public enum ScrollInfoMask

{

SIF_RANGE = 0x1,

SIF_PAGE = 0x2,

SIF_POS = 0x4,

SIF_DISABLENOSCROLL = 0x8,

SIF_TRACKPOS = 0x16,

SIF_ALL = SIF_RANGE + SIF_PAGE + SIF_POS + SIF_TRACKPOS

}





/// <summary>

/// Summary description for NativeUtil.

/// </summary>

public class NativeUtil

{

[DllImport("user32.dll")]

private static extern bool GetScrollInfo(IntPtr hwnd, int fnBar,
ref SCROLLINFO ScrollInfo);



public static SCROLLINFO
GetScrollInfo(System.Windows.Forms.RichTextBox richtxt, int fnBar)

{

SCROLLINFO info = new SCROLLINFO();

info.cbSize = Marshal.SizeOf(info);

info.fMask = (int) ScrollInfoMask.SIF_ALL;

GetScrollInfo(richtxt.Handle, fnBar, ref info);

return info;

}

}

}





Regards



Alex
 
C

Claes Bergefall

Alex Fu said:
public enum ScrollInfoMask
{
SIF_RANGE = 0x1,
SIF_PAGE = 0x2,
SIF_POS = 0x4,
SIF_DISABLENOSCROLL = 0x8,
SIF_TRACKPOS = 0x16,
SIF_ALL = SIF_RANGE + SIF_PAGE + SIF_POS + SIF_TRACKPOS
}


[System.Flags]
public enum ScrollInfoMask
{
SIF_RANGE = 0x1,
SIF_PAGE = 0x2,
SIF_POS = 0x4,
SIF_DISABLENOSCROLL = 0x8,
SIF_TRACKPOS = 0x10,
SIF_ALL = SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS
}


/claes
 
D

Dustin Campbell

public enum ScrollInfoMask
{

SIF_RANGE = 0x1,

SIF_PAGE = 0x2,

SIF_POS = 0x4,

SIF_DISABLENOSCROLL = 0x8,

SIF_TRACKPOS = 0x16,

SIF_ALL = SIF_RANGE + SIF_PAGE + SIF_POS + SIF_TRACKPOS

}

You have translated your ScrollInfoMask enum incorrectly to C#. The SIF_TRACKPOS
element should be 0x10 -- not 0x16.


Best Regards,
Dustin Campbell
Developer Express Inc.
 
A

Alex Fu

Thank you, Mr. Bergefall. The method can work well now. I made two mistakes,
one is 0x16 should be 0x10; the other is RichTextBox.ScrollBars had been set
into NONE by legacy code. This method won’t work well unless the scrollbars
became visible.



Best Regards,



Alex Fu
 
A

Alex Fu

Thank you, Mr. Campbell. The method can work well now. I made two mistakes,
one is 0x16 should be 0x10; the other is RichTextBox.ScrollBars had been set
into NONE by legacy code. This method won't work well unless the scrollbars
became visible. I add some code to show scrollbars before I call the method;
and hide them after the calling.



Best Regards,



Alex Fu
 

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

Similar Threads


Top