c# - Scroll panel with image using keyboard (PageDown / PageUp) -


what right way show large image in winforms app scroll-bars , keyboard scroll support? currenty i'm use panel(autoscroll=true) nested piturebox (sizemod = autosize).

i have 2 question:

1) control select drawing image? panel , piturebox cant selected (focused) using tab key. using button autosize = true , flatstyle = flat right solution?

2)how scroll image in panel using keyboard. keyboard events need handle - form, panel or picturebox. may should set panel autoscroll=false , add them hscroll , vscroll, events should handle?

what right way implement elementary app?

(just info, main form have other panel(dock=top) contain controls.)

  • as first question: there no control suited draw on , still can focus. in link below can see how make selectable panel, though.

  • now real problem: how scroll autoscroll panel keyboard..?

this amazingly hard do. here example start:

private void form1_previewkeydown(object sender, previewkeydowneventargs e) {   if (panel1.bounds.contains( this.pointtoclient( cursor.position )  ))   {     if (e.keyvalue == 33) panel1.autoscrollposition =        new point(panel1.autoscrollposition.x, math.abs(panel1.autoscrollposition.y) - 10);      if (e.keyvalue == 34) panel1.autoscrollposition =        new point(panel1.autoscrollposition.x, math.abs(panel1.autoscrollposition.y) + 10);   } } 

i test panel contain mouse. may want play around scroll amount.. replace keyvalues proper keys ;-) set keypreview = true; form!

note: works if there no control on form can focus.

since have such controls, buttons, listboxes etc.. here solution, works in case, believe..:

protected override bool processcmdkey(ref message msg, keys keydata) {     if (panel1.bounds.contains(this.pointtoclient(cursor.position)))     switch (keydata)     {         case keys.pagedown: { scroll(10);  return true; }         case keys.pageup:   { scroll(-10); return true; }        // maybe code more keys..?     }      return base.processcmdkey(ref msg, keydata); }  void scroll(int delta) {     panel1.autoscrollposition =  new point(            panel1.autoscrollposition.x, math.abs(panel1.autoscrollposition.y) + delta); } 

this doesn't need form have keypreview = true;.

here msdn explanation autoscrollposition.

here post suggests using subclass panel and/or picturebox, supposed allow them focus. couldn't work though..(nor seem simpler in end..)


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -