Click here to Skip to main content
14,604,148 members
   

C#

 
QuestionBest way to transform list and get top result from custom sort order? Pin
linalinea26-Jun-20 9:44
Memberlinalinea26-Jun-20 9:44 
AnswerRe: Best way to transform list and get top result from custom sort order? Pin
OriginalGriff26-Jun-20 11:28
mveOriginalGriff26-Jun-20 11:28 
GeneralRe: Best way to transform list and get top result from custom sort order? Pin
Richard Deeming29-Jun-20 0:21
mveRichard Deeming29-Jun-20 0:21 
AnswerRe: Best way to transform list and get top result from custom sort order? Pin
jsc4229-Jun-20 5:51
professionaljsc4229-Jun-20 5:51 
AnswerRe: Best way to transform list and get top result from custom sort order? Pin
linalinea3-Jul-20 9:59
Memberlinalinea3-Jul-20 9:59 
GeneralRe: Best way to transform list and get top result from custom sort order? Pin
OriginalGriff3-Jul-20 10:49
mveOriginalGriff3-Jul-20 10:49 
QuestionCustomizable keybinds C# Pin
Member 1486815919-Jun-20 14:28
MemberMember 1486815919-Jun-20 14:28 
AnswerRe: Customizable keybinds C# Pin
OriginalGriff19-Jun-20 20:10
mveOriginalGriff19-Jun-20 20:10 
Firstly, don't use F1 for that: the Windows standard use for F1 is "Help", and it's a bad idea to "play" with standard keys - the user can if he wishes, but you shouldn't as it gets confusing.

The simplest way is to have a Dictionary of keys, and Func values:

        private Dictionary<Keys, Func<int>> keyFunctions = new Dictionary<Keys, Func<int>>();
        private int A()
            {
            Console.WriteLine("A");
            return 1;
            }
        private int B()
            {
            Console.WriteLine("B");
            return 2;
            }
        private int C()
            {
            Console.WriteLine("C");
            return 3;
            }
...
            keyFunctions.Add(Keys.A, A);
            keyFunctions.Add(Keys.B, B);
            keyFunctions.Add(Keys.C, C);
...

You can then call the method by accessing the Dictionary with the Key value:
Console.WriteLine(keyFunctions[Keys.C]());
Console.WriteLine(keyFunctions[Keys.B]());
Console.WriteLine(keyFunctions[Keys.A]());

You can use Action instead of Func if your methods do not return a value, but that makes the Add operation more complex:
keyFunctions.Add(Keys.A, () => A());
keyFunctions.Add(Keys.B, () => B());
keyFunctions.Add(Keys.C, () => C());

You can then change the Keys value as you need, and process the Dictionary in your Forms ProcessCmdKey override provided you have set the Form.KeyPreview to true.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!

QuestionC# windows application: how to enable and disable scrollbars in datagridview programatically? Pin
Rajasekaran Bose17-Jun-20 23:53
MemberRajasekaran Bose17-Jun-20 23:53 
AnswerRe: C# windows application: how to enable and disable scrollbars in datagridview programatically? Pin
Richard MacCutchan18-Jun-20 0:41
mveRichard MacCutchan18-Jun-20 0:41 
QuestionAnyone working with the new VS2019 .Net NI-VISA driver? Pin
SunshineDesign16-Jun-20 15:58
MemberSunshineDesign16-Jun-20 15:58 
AnswerRe: Anyone working with the new VS2019 .Net NI-VISA driver? Pin
Richard MacCutchan16-Jun-20 21:01
mveRichard MacCutchan16-Jun-20 21:01 
GeneralRe: Anyone working with the new VS2019 .Net NI-VISA driver? Pin
SunshineDesign17-Jun-20 7:00
MemberSunshineDesign17-Jun-20 7:00 
AnswerRe: Anyone working with the new VS2019 .Net NI-VISA driver? Pin
Pawel Wzietek30-Jun-20 18:50
MemberPawel Wzietek30-Jun-20 18:50 
QuestionMultiple Classes, same name Pin
Wiep Corbier15-Jun-20 22:20
MemberWiep Corbier15-Jun-20 22:20 
AnswerRe: Multiple Classes, same name Pin
Richard Deeming15-Jun-20 22:31
mveRichard Deeming15-Jun-20 22:31 
GeneralRe: Multiple Classes, same name Pin
Wiep Corbier15-Jun-20 22:42
MemberWiep Corbier15-Jun-20 22:42 
GeneralRe: Multiple Classes, same name Pin
Richard Deeming15-Jun-20 22:47
mveRichard Deeming15-Jun-20 22:47 
GeneralRe: Multiple Classes, same name Pin
Wiep Corbier15-Jun-20 22:56
MemberWiep Corbier15-Jun-20 22:56 
GeneralRe: Multiple Classes, same name Pin
Richard Deeming15-Jun-20 23:47
mveRichard Deeming15-Jun-20 23:47 
GeneralRe: Multiple Classes, same name Pin
Member 798912216-Jun-20 0:05
MemberMember 798912216-Jun-20 0:05 
GeneralRe: Multiple Classes, same name Pin
Richard Deeming16-Jun-20 0:31
mveRichard Deeming16-Jun-20 0:31 
GeneralRe: Multiple Classes, same name Pin
Member 798912216-Jun-20 0:44
MemberMember 798912216-Jun-20 0:44 
GeneralRe: Multiple Classes, same name Pin
Wiep Corbier16-Jun-20 0:20
MemberWiep Corbier16-Jun-20 0:20 
GeneralRe: Multiple Classes, same name Pin
Richard Deeming16-Jun-20 0:28
mveRichard Deeming16-Jun-20 0:28 

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.