Click here to Skip to main content
15,499,289 members
Home / Discussions / C#
   

C#

 
GeneralRe: DGVPrinter how to print Logo and a frame in the text Pin
Member 141432998-Feb-19 4:04
MemberMember 141432998-Feb-19 4:04 
GeneralRe: DGVPrinter how to print Logo and a frame in the text Pin
OriginalGriff8-Feb-19 4:10
mveOriginalGriff8-Feb-19 4:10 
QuestionDisable focus in button with arrow right left up down Pin
Member 114269867-Feb-19 3:29
MemberMember 114269867-Feb-19 3:29 
AnswerRe: Disable focus in button with arrow right left up down Pin
Ralf Meier7-Feb-19 3:41
mveRalf Meier7-Feb-19 3:41 
GeneralRe: Disable focus in button with arrow right left up down Pin
Member 114269867-Feb-19 3:53
MemberMember 114269867-Feb-19 3:53 
GeneralRe: Disable focus in button with arrow right left up down Pin
Richard MacCutchan7-Feb-19 5:40
mveRichard MacCutchan7-Feb-19 5:40 
GeneralRe: Disable focus in button with arrow right left up down Pin
Richard MacCutchan7-Feb-19 7:10
mveRichard MacCutchan7-Feb-19 7:10 
AnswerRe: Disable focus in button with arrow right left up down Pin
Alan N7-Feb-19 6:22
MemberAlan N7-Feb-19 6: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 20:56
mveBillWoodruff9-Feb-19 20:56 
AnswerRe: Disable focus in button with arrow right left up down Pin
Gerry Schmitz7-Feb-19 7:22
mveGerry Schmitz7-Feb-19 7:22 
GeneralRe: Disable focus in button with arrow right left up down Pin
BillWoodruff10-Feb-19 10:07
mveBillWoodruff10-Feb-19 10:07 
QuestionC# GUI for plotting real time MPU(acceleration) scensors Pin
Member 141421336-Feb-19 8:23
MemberMember 141421336-Feb-19 8:23 
AnswerRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
Gerry Schmitz6-Feb-19 9:01
mveGerry Schmitz6-Feb-19 9:01 
GeneralRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
Member 141421336-Feb-19 9:41
MemberMember 141421336-Feb-19 9:41 
GeneralRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
Gerry Schmitz6-Feb-19 17:59
mveGerry Schmitz6-Feb-19 17:59 
GeneralRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
Member 141421337-Feb-19 7:24
MemberMember 141421337-Feb-19 7:24 
GeneralRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
Gerry Schmitz7-Feb-19 7:32
mveGerry Schmitz7-Feb-19 7:32 
GeneralRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
Dave Kreskowiak7-Feb-19 3:21
mveDave Kreskowiak7-Feb-19 3:21 
AnswerRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
OriginalGriff6-Feb-19 9:02
mveOriginalGriff6-Feb-19 9:02 
GeneralRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
Member 141421336-Feb-19 9:39
MemberMember 141421336-Feb-19 9:39 
GeneralRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
Pete O'Hanlon6-Feb-19 10:36
mvaPete O'Hanlon6-Feb-19 10:36 
GeneralRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
Mycroft Holmes6-Feb-19 14:37
professionalMycroft Holmes6-Feb-19 14:37 
AnswerRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
OriginalGriff6-Feb-19 21:00
mveOriginalGriff6-Feb-19 21:00 
GeneralRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
Member 141421337-Feb-19 7:26
MemberMember 141421337-Feb-19 7:26 
GeneralRe: C# GUI for plotting real time MPU(acceleration) scensors Pin
OriginalGriff7-Feb-19 7:40
mveOriginalGriff7-Feb-19 7: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.