This property while processing Hot Keys

Moderator: Rathinagiri

Post Reply
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

This property while processing Hot Keys

Post by mol »

I need to determine the name of control from which hotkey F3 was pressed.
But - calling THIS method generates error.
I've modified textbox1 sample to test it

Code: Select all

/*
 * MINIGUI - Harbour Win32 GUI library Demo
 *
 * Copyright 2002 Roberto Lopez <mail.box.hmg@gmail.com>
 * http://sites.google.com/site/hmgweb/
*/

#include "hmg.ch"

Function Main

	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 640 HEIGHT 480 ;
		TITLE 'HMG Demo' ;
		MAIN 

		@ 10,10 TEXTBOX Text_1 ;
			VALUE 123 ;
			TOOLTIP 'Numeric TextBox' ;
			NUMERIC ;
			MAXLENGTH 5 ;
			RIGHTALIGN ;
			ON LOSTFOCUS if ( This.Value < 100 , This.SetFocus , Nil)


		@ 40,10 TEXTBOX Text_2 ;
			VALUE 'Hi All' ;
			TOOLTIP 'Character TextBox' ;
			DISABLEDBACKCOLOR { 0,255,0 } ;
			DISABLEDFONTCOLOR { 255,255,255 } 

		DEFINE BUTTON C
			ROW	250
			COL	100
			WIDTH	160
			CAPTION	'Set Text_2 ReadOnly .T.'
			ACTION	Form_1.Text_2.ReadOnly := .T.
		END BUTTON

		DEFINE BUTTON D
			ROW	250
			COL	290
			WIDTH	160
			CAPTION	'Set Text_2 ReadOnly .F.'
			ACTION	Form_1.Text_2.ReadOnly := .F.
		END BUTTON


	END WINDOW

	Form_1.Center

	ON KEY F3 of FORM_1 action msgbox(this.name)

	Form_1.Activate

Return Nil
what's wrong with this.name?
User avatar
gfilatov
Posts: 1057
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: This property while processing Hot Keys

Post by gfilatov »

mol wrote:I need to determine the name of control from which hotkey F3 was pressed.
But - calling THIS method generates error.
I've modified textbox1 sample to test it
...
what's wrong with this.name?
Marek,

Please try an updated sample below :arrow:

Code: Select all

/*
* MINIGUI - Harbour Win32 GUI library Demo
*
* Copyright 2002 Roberto Lopez <mail.box.hmg@gmail.com>
* http://sites.google.com/site/hmgweb/
*/

#include "hmg.ch"

Function Main

   DEFINE WINDOW Form_1 ;
      AT 0,0 ;
      WIDTH 640 HEIGHT 480 ;
      TITLE 'HMG Demo' ;
      MAIN 

      @ 10,10 TEXTBOX Text_1 ;
         VALUE 123 ;
         TOOLTIP 'Numeric TextBox' ;
         NUMERIC ;
         MAXLENGTH 5 ;
         RIGHTALIGN ;
         ON LOSTFOCUS if ( This.Value < 100 , This.SetFocus , Nil)


      @ 40,10 TEXTBOX Text_2 ;
         VALUE 'Hi All' ;
         TOOLTIP 'Character TextBox' ;
         DISABLEDBACKCOLOR { 0,255,0 } ;
         DISABLEDFONTCOLOR { 255,255,255 } 

      DEFINE BUTTON C
         ROW   250
         COL   100
         WIDTH   160
         CAPTION   'Set Text_2 ReadOnly .T.'
         ACTION   Form_1.Text_2.ReadOnly := .T.
      END BUTTON

      DEFINE BUTTON D
         ROW   250
         COL   290
         WIDTH   160
         CAPTION   'Set Text_2 ReadOnly .F.'
         ACTION   Form_1.Text_2.ReadOnly := .F.
      END BUTTON


   END WINDOW

   Form_1.Center

   ON KEY F3 OF Form_1 ACTION msgbox( ThisWindow.FocusedControl )

   Form_1.Activate

Return Nil

I hope that helps.
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: This property while processing Hot Keys

Post by mol »

Thanks Grigori!
I found it, too.

Best regards!
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: This property while processing Hot Keys

Post by Roberto Lopez »

mol wrote:Thanks Grigori!
I found it, too.

Best regards!
'FocusedControl' is the right way indeed.

Thanks for the sample Grigory.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: This property while processing Hot Keys

Post by mol »

Roberto Lopez wrote:
'FocusedControl' is the right way indeed.

Thanks for the sample Grigory.

So, why "THIS" does not work?
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: This property while processing Hot Keys

Post by Roberto Lopez »

mol wrote:
Roberto Lopez wrote:
'FocusedControl' is the right way indeed.

Thanks for the sample Grigory.

So, why "THIS" does not work?
Because ON KEY is not a control, so there is no 'this' for it.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: This property while processing Hot Keys

Post by mol »

thanks for the clarification...
I didn't thought about 'ON KEY' as a control...
I'm still learning :)
Post Reply