Featured post
c# - Manually telling my ListBox's scrollbar where to be -
private void button2_click(object sender, eventargs e) { listbox1.autoscrolloffset.y = 10; }
i'm trying manually set location of vertical scrollbar using code during runtime. i've tried.
the .y property says: "gets or sets y coordinate of point". why doesn't compile , give me exception:
error 1 cannot modify return value of 'system.windows.forms.control.autoscrolloffset' because not variable
this crucial difference between value types , reference types. autoscrolloffset of type point, struct makes value type. when use property getter, copy of value. setting y property sets property on copy. c# compiler can recognize particular usage problem. not one:
private void button2_click(object sender, eventargs e) { var offset = listbox1.autoscrolloffset; offset.y = 10; // compiles, doesn't work }
to make work if have assign property value of type point:
private void button2_click(object sender, eventargs e) { listbox1.autoscrolloffset = new point(listbox1.autoscrolloffset.x, 10); }
which not work scroll listbox, affect position of control when embedded in scrollable container, panel. check scrollcontrolintoview reference.
assign topindex property instead.
- Get link
- X
- Other Apps
Comments
Post a Comment