Autore Topic: Fermare un evento quando l'utente clicca sul menu del Form  (Letto 261 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.722
  • Ne mors quidem nos iunget
    • Mostra profilo
Riporto questa discussione apparsa nella M.L. ufficiale:

" I have a form with a textbox that "MUST" be filled in before moving on
to the next control or any other control within the form. Fine, so I
implement a txtManditory_LostFocus method that just checks that there is
some text in there.

My problems are:
1) if the entire form loses focus, the lostfocus event fires.
2) if the user tries to click on the form menu the lost focus event fires.

I think I have got around 1) by using Object.Lock in a Form_Leave()
handler, but 2) has got me stumped.

Any clues?

tia
Bruce
"


" Salut Bruce,

disable all others and set a 'continue' (enabled) behind .....
or let the user only enter to the form after filling that field in a
single form/field

--
Amicalement
Charlie
"


" This is how to do with svn version ...
Codice: gambas [Seleziona]
Public Sub Form_Open()
Balloon.Delay = 1000
End

Public Sub TextBox1_LostFocus()

If IsNull(Application.ActiveControl) Then Return

If Len(Last.Text) < 8 Then

   Balloon.Error("this must be filled before anything else", Last)
   TextBox1.Select()
   Last.SetFocus

Endif
End

I  don't know if Application.ActiveControl is in the last 3.5
packages, but it is what you need.

http://gambasdoc.org/help/comp/gb.qt4/application/activecontrol?v3

Returns the control having the focus.

But return null for a menu or when the form lose the focus

--
Fabien Bodard
"
« Ultima modifica: 24 Gennaio 2014, 17:21:04 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.722
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Fermare un evento quando l'utente clicca sul menu del Form
« Risposta #1 il: 25 Gennaio 2014, 16:25:17 »
...continua...


" Thanks Fabien, that's what I needed...

... but it's strange, no matter how long I stare at that link, I just
can't see that second line   :-)


Uhoh :-( spoke too soon.  Just before I sent this, I had another
thought.  Yep, I had fooled myself into thinking it was that simple.
Attached is a quickly mocked up demo of what's driving me nuts.
(vedi allegato)

The use scenario is this:
1) If the user is just going to do stuff within the form, then they must
enter something into the "Must complete" box, then they can tab or click
anywhere else and do what they want.
2) But they can also do stuff in the File menu, load,save,new or exit.
This now works thanks to your input. What is there is some Dialogs and
some Message commands (and just Me.Close).
3) Or perhaps they want to change some program option. They should be
able to go Tools|Options which opens a form to change them. Guess what happens!
4) Or perhaps they want to view the help files. (This one is "fake" it's
just there to demonstrate something). So they should be able to go Help|
Browse Help.

IOW 2,3,or 4) need to be able to occur without invoking the error
balloon.

Re: 4) this just uses an InputBox to demonstrate the same problem.

Any further ideas?

Bruce
"
« Ultima modifica: 26 Gennaio 2014, 04:02:51 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.722
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Fermare un evento quando l'utente clicca sul menu del Form
« Risposta #2 il: 26 Gennaio 2014, 04:02:05 »
...continua...


" Or
Codice: gambas [Seleziona]
If Application.ActiveControl.Window <> Me.Window


Fabien Bodard "


" Ah!  I was so close.  In fact probably too close to see the obvious.

Thanks Fabien for taking the time.

Bruce
"
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »