c# - After setting tree node height, treeview scroll incorrectly -
public form2() { initializecomponent(); } private void form2_load(object sender, eventargs e) { dictionary<int, treenode> map = new dictionary<int, treenode>(); (int = 0; < 100; i++) { treenode node = new treenode(i.tostring()); if (i % 10 == 0) _tree.nodes.add(node); map.add(i, node); if (i % 10 != 0) { map[convert.toint32(math.floor(i / 10.0)) * 10].nodes.add(node); node.setnodeheight(2); } } } } public static class treeviewextendmethod { [structlayout(layoutkind.sequential)] struct tvitemex { public mask mask; public intptr item; public uint state; public uint statemask; public intptr psztext; public int cchtextmax; public int iimage; public int iselectedimage; public int ichildren; public intptr lparam; public int iintegral; // ... plus windows 6+ crap } [flags] enum mask : uint { text = 1, image = 2, param = 4, state = 8, handle = 16, selectedimage = 32, children = 64, integral = 128, } public static int getnodeheight(this treenode tn) { tvitemex tvix = new tvitemex(); tvix.mask = mask.handle | mask.integral; tvix.item = tn.handle; tvix.iintegral = 0; intptr hparam=marshal.allochglobal(marshal.sizeof(tvix)); marshal.structuretoptr(tvix, hparam, false); win32.sendmessage(tn.treeview.handle, win32.tvm_getitem, intptr.zero, hparam); return tvix.iintegral; } public static void setnodeheight(this treenode tn, int height) { tvitemex tvix = new tvitemex(); tvix.mask = mask.handle | mask.integral; tvix.item = tn.handle; tvix.iintegral = height; intptr hparam=marshal.allochglobal(marshal.sizeof(tvix)); marshal.structuretoptr(tvix, hparam, false); win32.sendmessage(tn.treeview.handle, win32.tvm_setitem, intptr.zero, hparam); } }
the above sample code, after using pinv change node height manually, when click in bottom of scroll bar, treeview scroll should not scroll @ click.
at first, think may caused scroll bar, doesn't work expected after set scroll msg para (8) end scroll. @ last, while catching scroll msg (0x115), exits wndproc, , works. have no idea going on can't find msg can cancel scroll except setting wparam 8 not work.
i find solution, though not elegant, should works. here solution,
protected override void wndproc(ref message m) { if (m.msg == 0x115) { if (((int)m.wparam & 5) == (5) || ((int)m.wparam & 4) == (4) ) { int para = (int)m.wparam; int temp = (para - (para % 2 == 0 ? 4 : 5)) >> 16; // store current position, if position doesn't change, no need handle if (temp == pos) return; else pos = temp; } if (((int)m.wparam & 8) == 8) return; //debug.writeline(m.wparam); //if (disablescroll) // return; // //m.wparam = (intptr)8; //scrollinfo si = new scrollinfo(); //si.cbsize = marshal.sizeof(si); //si.fmask = (int)(scrollinfomask.sif_pos | scrollinfomask.sif_page | scrollinfomask.sif_range | scrollinfomask.sif_trackpos); //getscrollinfo(this.handle, 1, ref si); ////debug.writeline(string.format("max pos:{0}, min pos: {1}", si.nmin, si.nmax)); //debug.writeline(string.format("wparam:{0} hparam:{1}", m.wparam, m.lparam)); //debug.writeline(string.format("it page size: {0}, position: {1}, range: {2}, track pos: {3}", si.npage, si.npos, si.npage, si.ntrackpos)); //if (si.npage + math.max(si.npos, si.ntrackpos) >= si.nmax) //{ // return; //} } base.wndproc(ref m); }
Comments
Post a Comment