Control zoom level of WinForms using mouse sroll wheel and Ctrl in VB.NET -
if have winform, may know how can control zoom level of font in application (as application window obviously) using ctrl + mouse scroll wheel? see there delta in scroll wheel event, not sure how works. there code sample can into?
thanks help!
you'll have handle keydown , keyup event in order determine whether or not ctrl key being held down. value should stored @ class-level because used other subroutines besides keydown , keyup events.
you write code handle form's mousewheel event. scrolling downwards (towards you) causes negative value delta property of mouseeventargs. scrolling upwards reverse. value of delta property 120.
microsoft's reason value follows:
currently, value of 120 standard 1 detent. if higher resolution mice introduced, definition of wheel_delta might become smaller. applications should check positive or negative value rather aggregate total.
in context you'll check sign of delta , perform action.
here sample code implementing basic 'zoom' functionality:
public class form1 enum zoomdirection none down end enum dim ctrlisdown boolean dim zoomvalue integer sub new() ' call required designer. initializecomponent() ' add initialization after initializecomponent() call. zoomvalue = 100 end sub private sub form1_keydown_keyup(byval sender object, _ byval e keyeventargs) _ handles me.keydown, me.keyup ctrlisdown = e.control end sub private sub form1_mousewheel(byval sender object, byval e mouseeventargs) _ handles me.mousewheel 'check if control being held down if ctrlisdown 'evaluate delta's sign , call appropriate zoom command select case math.sign(e.delta) case < 0 zoom(zoomdirection.down) case > 0 zoom(zoomdirection.up) case else zoom(zoomdirection.none) end select end if end sub private sub zoom(byval direction zoomdirection) 'change zoom value based on direction passed select case direction case zoomdirection.up zoomvalue += 1 case zoomdirection.down zoomvalue -= 1 case else 'do nothing end select me.text = zoomvalue.tostring() end sub end class read on following more information question:
Comments
Post a Comment