public struct SCROLLINFO
{
public uint cbSize; public uint fMask; public int nMin; public int nMax; public uint nPage; public int nPos; public int nTrackPos;
}
[DllImport("user32.dll", EntryPoint = "GetScrollInfo")]
public static extern bool GetScrollInfo(IntPtr hwnd, int fnBar, ref SCROLLINFO lpsi); [DllImport("user32.dll", EntryPoint = "SetScrollInfo")]
public static extern bool SetScrollInfo(IntPtr hwnd, int fnBar, ref SCROLLINFO lpsi, bool Rush);
//获取句柄
IntPtr intPtr = FindWindow(null, "Form1"); SCROLLINFO si = new SCROLLINFO();
si.cbSize = (uint)Marshal.SizeOf(typeof(SCROLLINFO));
si.fMask = (uint)(ScrollBarInfoFlags.SIF_POS);
si.nPos = 1; //1纵向,0横向
bool result = SetScrollInfo(ss, 1, ref si, true);
当 si.nPos = 0或者没有赋值的时候,返回false;
si.nPos有赋值的时候,返回true,但是滚动条位置没有跟着变化,这是为什么??
谢谢!
{
public uint cbSize; public uint fMask; public int nMin; public int nMax; public uint nPage; public int nPos; public int nTrackPos;
}
[DllImport("user32.dll", EntryPoint = "GetScrollInfo")]
public static extern bool GetScrollInfo(IntPtr hwnd, int fnBar, ref SCROLLINFO lpsi); [DllImport("user32.dll", EntryPoint = "SetScrollInfo")]
public static extern bool SetScrollInfo(IntPtr hwnd, int fnBar, ref SCROLLINFO lpsi, bool Rush);
//获取句柄
IntPtr intPtr = FindWindow(null, "Form1"); SCROLLINFO si = new SCROLLINFO();
si.cbSize = (uint)Marshal.SizeOf(typeof(SCROLLINFO));
si.fMask = (uint)(ScrollBarInfoFlags.SIF_POS);
si.nPos = 1; //1纵向,0横向
bool result = SetScrollInfo(ss, 1, ref si, true);
当 si.nPos = 0或者没有赋值的时候,返回false;
si.nPos有赋值的时候,返回true,但是滚动条位置没有跟着变化,这是为什么??
谢谢!
public int nMin;
public int nMax;