ATOUTFOX
COMMUNAUTÉ FRANCOPHONE DES PROFESSIONNELS FOXPRO
Visual FoxPro : le développement durable

Forum AtoutFox : Re: étendre la propriété SelectOnEntry   

Sujet

rss Flux RSS des derniers messages

Vous devez vous identifier pour pouvoir poser une question ou répondre.

lun. 08 octobre 2012, 15h16

Francis Faure
France France

atoutfox.public.association

Re: étendre la propriété SelectOnEntry

Bonjour

Grâce aux réponse de Grégory et de Jean Claude Rivière : (Merci à Eux)

j'ai maintenant un petite classe toute simple qui répond bien à la demande :
c'est à dire un TextBox : lors du click dessus il y a la sélection comme le "TAB" et cela n’empêche pas la selection pas click, ni même le double ou triple click
c'est cool

voici le code synthétisé pour reproduire :

sur un textbox :
* méthodes :

* INIT()
This.AddProperty('Clicked', .F.) && ou ajouter cette propriété au VCX

* GOTFOCUS()
this.Clicked = .f.
DODEFAULT()

*CLICK()
IF (not this.Clicked) AND (This.SelectOnEntry OR "K"$This.Format)
  this.SelStart = 0
  IF TYPE("this.value")=="C"
    this.SelLength = len(ALLTRIM(this.Text))
  else
    this.SelLength = len(this.Text)
  endif
  this.Clicked= .t.
endif

* propriété SlectonEntry=.T. (ou format "K" à la foxpro...)


c'est bien !

mais pour aller ENCORE PLUS LOIN :

dans la même idée : sur le même principe : mais dans le cas des champs numérique : il serait agréable un fonctionnement à la saisie "Excel"
c'est à dire que la valeur numérique en modification passe à gauche, sans le InputMask d'actif, sans la contrainte du délimiteur "." ou "," et cerise sur le gâteau : optimiser l'affichage par exemple 1 234.00 s'affichant 1234 sélectionné en modif :d

j'ai trouvé une solution qui fonctionne bien, excepté le coté qu'il est possible de saisie des caractères...

voilà le source pour reproduire, cela doit être perfectible ?

sur un textbox

* INIT()
This.AddProperty('Clicked', .F.) && si on vient de cliquer sur la zone
This.AddProperty('IsNumeric', .F.) && si c'est une zone numérique
This.AddProperty('nDecimal', 0) && nombre de décimale
This.AddProperty('SInputMask', "") && mémorisation du mask
This.AddProperty('SControlSource', "") && mémorisation du control source
This.AddProperty('cNumValue', "") && String pour saisie d'un numérique

* GOTFOCUS()
LOCAL liI as Integer

this.Clicked = .f.

IF TYPE("this.Value")=="N"
  * si c'est un numérique :
  * on veut pouvoir saisir aligné à gauche sans imputmask et format chaine pour éviter le séparateur décimal
  this.IsNumeric=.T.
  this.Refresh() && forcer le rechargement de This.text au cas ou la même valeur ai été modifiée dans un autre champ
* this.cNumValue = ALLTRIM(CAST(this.Value as M))
  this.cNumValue = ALLTRIM(this.Text)
  this.cNumValue = STRTRAN(this.cNumValue," ","")
  this.cNumValue = STRTRAN(this.cNumValue,",",".")
  * recherche du nom de décimales, et mémoriser pour restituer en sortie
  IF "."$this.cNumValue
    this.nDecimal=LEN(this.cNumValue)-RAT(".",this.cNumValue)
    * enlever les 0 de fin exemple "121.00" a saisir sous forme "121"
    FOR m.liI=1 TO this.nDecimal+1
      IF RIGHT(this.cNumValue,1)$"0."
        this.cNumValue=left(this.cNumValue, LEN(this.cNumValue)-1)
      ELSE
        exit
      endif
    NEXT
  ELSE
    this.nDecimal=0
  endif
  this.Alignment=0 && gauche
  this.SInputMask=this.InputMask
  this.SControlSource=this.ControlSource
  this.ControlSource="this.cNumValue"
  this.InputMask=""
endif

DODEFAULT()


* CLICK()
IF (not this.Clicked) AND (This.SelectOnEntry OR "K"$This.Format)
  this.SelStart = 0
  IF TYPE("this.value")=="C"
    this.SelLength = len(ALLTRIM(this.Text))
  else
    this.SelLength = len(this.Text)
  endif
  this.Clicked= .t.
endif


* VALID()
IF this.IsNumeric
  this.Alignment= 1 && droite
  this.ControlSource=this.SControlSource
  this.InputMask=this.SInputMask
  this.cNumValue = STRTRAN(this.cNumValue," ","") && IE si saisie "1 200"
  this.cNumValue = STRTRAN(this.cNumValue,",",".")  && ie si saisie "12,20"
  this.value=Cast(this.cNumValue as N(20,this.nDecimal))
ENDIF
* test de this.value
IF this.Value>9999
  this.Value=9999
  this.GotFocus()
  RETURN .F.
endif
DODEFAULT()


* propriété SlectonEntry=.T.
* propriété InputMak = "999 999.99"


la solution est proche...



Permalink : http://www.atoutfox.org/nntp.asp?ID=0000009961
20 286 messages dans le forum • Liste complète des messages

www.atoutfox.org - Site de la Communauté Francophone des Professionnels FoxPro - v3.4.0 - © 2004-2026.
Cette page est générée par un composant COM+ développé en Visual FoxPro 9.0-SP2-HF3