Enter as tab

Posted by Lieven De Foor on 19-Nov-2010 03:05

Hello,

Classic ABL widgets support the following to simulate a TAB key when pressing ENTER:

ON RETURN OF FILL-IN-1 IN FRAME DEFAULT-FRAME
DO:
    APPLY "TAB":U TO SELF.
    RETURN NO-APPLY.
END.

When I try to write an equivalent for .NET gui I'm having the some difficulties:

USING Progress.Windows.UserControl.

USING Infragistics.Win.Misc.UltraLabel.

USING Infragistics.Win.UltraWinEditors.UltraTextEditor


/* Simplified class for demonstration purposes */

CLASS FillIn INHERITS UserControl:

    DEFINE PRIVATE VARIABLE MyLabel AS UltraLabel NO-UNDO.

    DEFINE PRIVATE VARIABLE MyTextEditor AS UltraTextEditor NO-UNDO.

    

    CONSTRUCTOR PUBLIC FillIn():
         SUPER().

        THIS-OBJECT:MyTextEditor:KeyPress:Subscribe(KeyPressedHandler).

    END CONSTRUCTOR.


    METHOD PUBLIC VOID KeyPressedHandler(INPUT sender AS System.Object, INPUT e AS System.Windows.Forms.KeyPressEventArgs):
         DEFINE VARIABLE MyTextEditor AS UltraTextEditor NO-UNDO.
         IF e:KeyChar = "~r":U OR e:KeyChar = "~n":U THEN DO:
             MyTextEditor = CAST(sender, UltraTextEditor).
             /*MyTextEditor:KeyPress:Publish(MyTextEditor, NEW System.Windows.Forms.KeyPressEventArgs("~t":U)).*/ /* 1 */
             /*MyTextEditor:OnKeyPress(NEW System.Windows.Forms.KeyPressEventArgs("~t":U)).*/ /* 2 */
         END.

    END METHOD.

END CLASS.

Number /* 1 */ doesn't work: you can only publish events from the class that defines the event. Even a subclass can't publish a public event of its super class. See also http://communities.progress.com/pcom/message/81301#81301

There is a OnKeyPress method on System.Windows.Forms.Control that is inherited but it is protected so /* 2 */ doesn't work either.

Therefore I created a subclass of UltraTextEditor: UltraTextEditorEx and made the OnKeyPress public

USING Infragistics.Win.UltraWinEditors.UltraTextEditor.

CLASS UltraTextEditorEx INHERITS UltraTextEditor:   
    CONSTRUCTOR PUBLIC UltraTextEditorEx():
        SUPER().
    END CONSTRUCTOR.

    METHOD PUBLIC OVERRIDE VOID OnKeyPress(e AS System.Windows.Forms.KeyPressEventArgs):
        SUPER:OnKeyPress(e).

    END METHOD.

END CLASS.

Then I've changed the code above to the following:

USING Progress.Windows.UserControl.

USING Infragistics.Win.Misc.UltraLabel.


/* Simplified class for demonstration purposes */

CLASS FillIn INHERITS UserControl:

    DEFINE PRIVATE VARIABLE MyLabel AS UltraLabel NO-UNDO.

    DEFINE PRIVATE VARIABLE MyTextEditor AS UltraTextEditorEx NO-UNDO.

    

    CONSTRUCTOR PUBLIC FillIn():
         SUPER().

        THIS-OBJECT:MyTextEditor:KeyPress:Subscribe(KeyPressedHandler).

    END CONSTRUCTOR.


    METHOD PUBLIC VOID KeyPressedHandler(INPUT sender AS System.Object, INPUT e AS System.Windows.Forms.KeyPressEventArgs):
         DEFINE VARIABLE MyTextEditor AS UltraTextEditorEx NO-UNDO.
         IF e:KeyChar = "~r":U OR e:KeyChar = "~n":U THEN DO:
             MyTextEditor = CAST(sender, UltraTextEditorEx).
             /*MyTextEditor:KeyPress:Publish(MyTextEditor, NEW System.Windows.Forms.KeyPressEventArgs("~t":U)).*/ /* 1 */
             MyTextEditor:OnKeyPress(NEW System.Windows.Forms.KeyPressEventArgs("~t":U)). /* 2 */
         END.

    END METHOD.

END CLASS.

Now /* 2 */ works (the event gets triggered), but apparently nothing happens.

Any ideas?

Thx

All Replies

Posted by bheavican on 19-Nov-2010 07:55

The methods you are calling are the result of an event and are not actually triggering the event.  If you want to mimic a tab key when enter is pressed this is what we use.

METHOD PRIVATE VOID TextBox1_KeyPress (INPUT sender AS System.Object, INPUT e AS INPUT e AS System.Windows.Forms.KeyPressEventArgs):

  IF e:KeyChar = CHR(13) THEN

  DO:

    DEFINE VARIABLE cTest     AS CHARACTER   NO-UNDO INIT "".

    cTest = "~{TAB~}".

    System.Windows.Forms.SendKeys:Send(cTest).

  END.

END METHOD.

Posted by Lieven De Foor on 19-Nov-2010 08:19

That seems to do the trick, thanks!

This thread is closed