Click here to Skip to main content
15,886,422 members
Home / Discussions / C#
   

C#

 
GeneralRe: DGVPrinter how to print Logo and a frame in the text Pin
Member 141432998-Feb-19 3:04
Member 141432998-Feb-19 3:04 
GeneralRe: DGVPrinter how to print Logo and a frame in the text Pin
OriginalGriff8-Feb-19 3:10
mveOriginalGriff8-Feb-19 3:10 
QuestionDisable focus in button with arrow right left up down Pin
Member 114269867-Feb-19 2:29
Member 114269867-Feb-19 2:29 
AnswerRe: Disable focus in button with arrow right left up down Pin
Ralf Meier7-Feb-19 2:41
mveRalf Meier7-Feb-19 2:41 
GeneralRe: Disable focus in button with arrow right left up down Pin
Member 114269867-Feb-19 2:53
Member 114269867-Feb-19 2:53 
GeneralRe: Disable focus in button with arrow right left up down Pin
Richard MacCutchan7-Feb-19 4:40
mveRichard MacCutchan7-Feb-19 4:40 
GeneralRe: Disable focus in button with arrow right left up down Pin
Richard MacCutchan7-Feb-19 6:10
mveRichard MacCutchan7-Feb-19 6:10 
AnswerRe: Disable focus in button with arrow right left up down Pin
Alan N7-Feb-19 5:22
Alan N7-Feb-19 5:22 
Some of this key handling stuff is not obvious and I'm no expert! In this case you have to tell the Button control not to give the arrow keys special handling. To do this override the IsInputKey method.

My example also overrides OnKeyDown to make buttons of this class move in response to the arrow keys. I imagine that you would want to have that functionality in a separate KeyDown event handler.


C#
public class AnnoyingButton : Button {

  protected override bool IsInputKey(Keys keyData) {
    return keyData == Keys.Up || keyData == Keys.Down ||
           keyData == Keys.Left || keyData == Keys.Right;
  }

  protected override void OnKeyDown(KeyEventArgs args) {
    Point newLocation = Location;

    switch (args.KeyCode) {
      case Keys.Right:
        newLocation.Offset(1, 0);
        Location = newLocation;
        break;
      case Keys.Left:
        newLocation.Offset(-1, 0);
        Location = newLocation;
        break;
      case Keys.Down:
        newLocation.Offset(0, 1);
        Location = newLocation;
        break;
      case Keys.Up:
        newLocation.Offset(0, -1);
        Location = newLocation;
        break;
      default:
        base.OnKeyDown(args);
    }
  }
}


I did have a good link about this stuff but as I'm moving computer I don't know where it is at the moment.

EDIT: HERE IS THAT LINK
Exploring Secrets of .NET Keystroke Handling[^]

Alan.

modified 11-Feb-19 7:24am.

GeneralRe: Disable focus in button with arrow right left up down Pin
BillWoodruff9-Feb-19 19:56
professionalBillWoodruff9-Feb-19 19:56 
AnswerRe: Disable focus in button with arrow right left up down Pin
Gerry Schmitz7-Feb-19 6:22
mveGerry Schmitz7-Feb-19 6:22 
GeneralRe: Disable focus in button with arrow right left up down Pin
BillWoodruff10-Feb-19 9:07
professionalBillWoodruff10-Feb-19 9:07 
QuestionC# GUI for plotting real time MPU(acceleration) scensors Pin
Member 141421336-Feb-19 7:23
Member 141421336-Feb-19 7:23 
AnswerRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
Gerry Schmitz6-Feb-19 8:01
mveGerry Schmitz6-Feb-19 8:01 
GeneralRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
Member 141421336-Feb-19 8:41
Member 141421336-Feb-19 8:41 
GeneralRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
Gerry Schmitz6-Feb-19 16:59
mveGerry Schmitz6-Feb-19 16:59 
GeneralRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
Member 141421337-Feb-19 6:24
Member 141421337-Feb-19 6:24 
GeneralRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
Gerry Schmitz7-Feb-19 6:32
mveGerry Schmitz7-Feb-19 6:32 
GeneralRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
Dave Kreskowiak7-Feb-19 2:21
mveDave Kreskowiak7-Feb-19 2:21 
AnswerRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
OriginalGriff6-Feb-19 8:02
mveOriginalGriff6-Feb-19 8:02 
GeneralRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
Member 141421336-Feb-19 8:39
Member 141421336-Feb-19 8:39 
GeneralRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
Pete O'Hanlon6-Feb-19 9:36
mvePete O'Hanlon6-Feb-19 9:36 
GeneralRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
Mycroft Holmes6-Feb-19 13:37
professionalMycroft Holmes6-Feb-19 13:37 
AnswerRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
OriginalGriff6-Feb-19 20:00
mveOriginalGriff6-Feb-19 20:00 
GeneralRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
Member 141421337-Feb-19 6:26
Member 141421337-Feb-19 6:26 
GeneralRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
OriginalGriff7-Feb-19 6:40
mveOriginalGriff7-Feb-19 6:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.