在compact framwork中add horizontal scroll to listbox遇到的一个Issue...

A0_嘟嘟飞_0A 2007-11-22 06:23:34

我在XdaII(多普达696英文版)中作应用程序开发,其中涉及到为listbox添加水平滚动条。核心代码如下:



const int GWL_STYLE = (-16);

const int LB_SETHORIZONTALEXTENT = 0x0194;

const long WS_HSCROLL = 0x00100000L;

const int SWP_FRAMECHANGED = 0x0020;

const int SWP_NOMOVE = 0x0002;

const int SWP_NOSIZE = 0x0001;

const int SWP_NOZORDER = 0x0004;

const int WM_VSCROLL = 0x0115;

const int SB_BOTTOM = 7;



[DllImport("coredll.dll")]

static extern IntPtr GetCapture();

[DllImport("coredll.dll")]

static extern uint SendMessage(IntPtr hwnd, int msg, int wParam, int lParam);

[DllImport("coredll.dll")]

static extern uint GetWindowLong(IntPtr hwnd, int index);

[DllImport("coredll.dll")]

static extern uint SetWindowLong(IntPtr hwnd, int index,uint dwNewLong);

[DllImport("coredll.dll")]

static extern uint SetWindowPos(IntPtr hwnd, IntPtr hWndInsertAfter,int x,int y,int cx,int cy,uint uFlags);

private void ModifyStyle(uint addStyle, uint removeStyle)

{ // Get current window style

uint windowStyle = GetWindowLong(GetCapture(), GWL_STYLE);

if (addStyle != 0)

{ // Modify style

SetWindowLong(GetCapture(), GWL_STYLE, windowStyle | addStyle);

}

else

{

// Remove style

SetWindowLong(GetCapture(), GWL_STYLE, windowStyle & ~removeStyle);

}

// Let the window know

SetWindowPos(GetCapture(), IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOZORDER | SWP_NOSIZE | SWP_FRAMECHANGED);



}

private void FrmDispatchJob_Load(object sender, System.EventArgs e)

{

this.listBox_Job.Capture=true;

IntPtr handle=GetCapture();

SendMessage(handle, LB_SETHORIZONTALEXTENT, 250,0);

SendMessage(handle, WM_VSCROLL, SB_BOTTOM,0);

ModifyStyle((uint)WS_HSCROLL, 0);

this.listBox_Job.Capture=false;

}

但是莫名的遇见下列行为异常:

Ok, on this screen, it is normal. Without touching anything.




On this screen, I tapped the white part of the scroll bar in GREEN. The text will shift to the right, but the indicator (IN RED) does not move to the right. It stays on the left side.





并且我在.net framework 中也做了相应的测试,行为还是如上异常。

我搜罗,对比了一下,并且发现在vb6.0中用如下所述http://www.freevbcode.com/ShowCode.asp?ID=5362&NoBox=True

实现add horizontal scroll to listbox 结果一切正常。二者之间没有本质的区别呀?为什么我用c#实现出来的add horizontal scroll to listbox 行为会有问题呢?很是不解,所以拿来跟大家一起探讨,还请各位不吝赐教!
...全文
60 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
A0_嘟嘟飞_0A 2007-12-18
  • 打赏
  • 举报
回复
挂了这么久?怎么连个回复的都没有?只好结贴了!

110,525

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧