Author Topic: DF1Com1 in C# - Simple issue. I think  (Read 2780 times)

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: DF1Com1 in C# - Simple issue. I think
« Reply #15 on: April 21, 2018, 09:57:21 PM »
You seem to be learning how to do programming in C#.
Maybe you should look up some tutorials online.

Currently you have a form with a driver and a BasicButton control on it.
Adding any more controls in the future will not make it any simpler for you.

There are some online code conversion tools which convert VB to C#, like this one:
https://www.carlosag.net/tools/codetranslator/

You could also use SharpDevelop 4.4 program which has code converter built-in.

As for C# in AdvancedHMI, you need to be using the MainForm inside the AdvancedHMIcs project.
You also need to get familiar with Properties window, like the attached picture shows.
Lightning Bolt icon will show all events associated with selected object, whether it's a form or a control.
Double-clicking any of the events will create a code for you and take you to the code window.

If you manually add a code that you find somewhere online then you still need to associate that code with the event by selecting it in the properties window.
« Last Edit: April 21, 2018, 10:02:57 PM by Godra »

authorleon

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: DF1Com1 in C# - Simple issue. I think
« Reply #16 on: April 22, 2018, 06:12:37 AM »
Fantastic !!!!!!!!!!!!!!! THANK YOU VERY MUCH!!!!!!!!!!

I love to learn and you have saved a lot of time!!!!!!!

Thank you again... A beer for you.

authorleon

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: DF1Com1 in C# - Simple issue. I think
« Reply #17 on: April 28, 2018, 04:02:17 PM »
Hello,

Right, I have some progress now. I have global hotkeys working which is fantastic....

I just need a little bit of help tweaking the code please.

 
Code: [Select]
public void hook_KeyPressed(object sender, KeyPressedEventArgs e)
        {
            if (e.Modifier == (Src.Hooks.ModifierKeys.Win | Src.Hooks.ModifierKeys.Alt) && e.Key == Keys.F12)
            {
                Me.SerialDF1forSLCMicroCom1.Write("B3:0/0", "0")
                switch = False
            }
            else if (e.Modifier == (Src.Hooks.ModifierKeys.Win | Src.Hooks.ModifierKeys.Alt) && e.Key == Keys.F11)
            {
                MessageBox.Show("Combinacion F11");
            }
            // show the keys pressed in a label.

        }


Please note, I do not want a toggle function. I would like you that when the button is pressed ("B3:0/0", "1"). And when the button is released ("B3:0/0", "0"). In other words the action only continues when the button is pressed and held down. Once released the bit is put back to zero.

Thank you very much...


authorleon

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: DF1Com1 in C# - Simple issue. I think
« Reply #18 on: April 28, 2018, 04:22:18 PM »
Right. I have the code working for toggle now....

For anyone, it if like this:

 
Code: [Select]
public void hook_KeyPressed(object sender, KeyPressedEventArgs e)
        {
            if (e.Modifier == (Src.Hooks.ModifierKeys.Win | Src.Hooks.ModifierKeys.Alt) && e.Key == Keys.F12)
            {
               
                serialDF1forSLCMicroCom1.Write ("B3:0/0", "1");
            }
            else if (e.Modifier == (Src.Hooks.ModifierKeys.Win | Src.Hooks.ModifierKeys.Alt) && e.Key == Keys.F11)
            {
                serialDF1forSLCMicroCom1.Write("B3:0/0", "0");

            }
            // show the keys pressed in a label.

        }


I jsut need help with keep up and release...

Thank you all very much

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: DF1Com1 in C# - Simple issue. I think
« Reply #19 on: April 30, 2018, 05:54:41 PM »
You seem to be looking to assign those functions to global hotkeys (which you mentioned in your other topic https://www.advancedhmi.com/forum/index.php?topic=2036.0).

There still doesn't seem to be any solution for that.