Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Prüfen ob ein Steuerelement den Focus hat

269 views
Skip to first unread message

Alexander Wabro

unread,
Aug 16, 2003, 4:22:32 AM8/16/03
to
Hallo,
wie kann man prüfen ob ein bestimmtes Steuerelement den Focus hat.

Ich stelle mir das ungefähr so vor: if hasfocus(txt_EditFG) ...

Gibt es so etwas ähnliches ?

Gruß
Alexander


Markus Uihlein

unread,
Aug 15, 2003, 4:30:40 AM8/15/03
to
Hallo Alexander!

"Alexander Wabro" <awa...@gmx.de> wrote:

> wie kann man prüfen ob ein bestimmtes Steuerelement den Focus hat.

Screen.ActiveControl + [F1]

HTH
Markus


Alexander Wabro

unread,
Aug 16, 2003, 4:44:55 AM8/16/03
to
Danke für die Antwort,
aber ich habe in der MSDN nachgeschlagen, aber ich kann damit immernoch
nicht so recht ertwas anfangen. Hast Du vielleicht ein kl. Beispiel ?

Gruß
Alexander


"Markus Uihlein" <mori...@gmx.net> schrieb im Newsbeitrag
news:OALUEewY...@tk2msftngp13.phx.gbl...

Christian Stauffer

unread,
Aug 15, 2003, 5:36:40 AM8/15/03
to
Alexander Wabro sprach:

> "Markus Uihlein" <mori...@gmx.net> schrieb ...


>
>> "Alexander Wabro" <awa...@gmx.de> wrote:
>>
>>> wie kann man prüfen ob ein bestimmtes Steuerelement den Focus hat.
>> Screen.ActiveControl + [F1]
>

> Danke für die Antwort,
> aber ich habe in der MSDN nachgeschlagen, aber ich kann damit immernoch
> nicht so recht ertwas anfangen. Hast Du vielleicht ein kl. Beispiel ?

Screen.ActiveControl ist eine Referenz auf das Steuerelement, das den Focus
hat.

Das kannst Du z.B. für eine Funktion benutzen:

'Nicht getesteter Code, kann Schreibfehler beinhalten
private function HasFocus (byval sControl as string) as boolean

if lcase(screen.activecontrol.name) = lcase(scontrol) then
HasFocus = true
end if

end function
'Nicht getesteter Code, kann Schreibfehler beinhalten

Nun kannst Du mit HasFocus("txt_EditFG") oder HasFocus(txt_EditFG.Name)
abfragen, ob das Control den Focus hat.

Gruss Christian

PS: Bitte lies mal www.learn.to/quote

Markus Uihlein

unread,
Aug 15, 2003, 5:40:06 AM8/15/03
to
Hallo Alexander!

"Alexander Wabro" <awa...@gmx.de> wrote:

> aber ich habe in der MSDN nachgeschlagen

..bei mir sagt die zu "ActiveControl":

<schnipp>
Returns the control that has thefocus. When a form is referenced, as in
ChildForm.ActiveControl, ActiveControl specifies the control that would have
the focus if the referenced form were active. Not available atdesign time;
read-only atrun time.
<schnapp>

> Hast Du vielleicht ein kl. Beispiel ?

"if hasfocus(txt_EditFG) ..." ->

If Screen.ActiveControl Is txt_EditFG...

HTH
Markus


Harald M. Genauck

unread,
Aug 15, 2003, 5:48:44 AM8/15/03
to
Hallo Christian,

> Screen.ActiveControl ist eine Referenz auf das Steuerelement, das den
Focus
> hat.

Nicht ganz.

Screen.ActiveControl ist eine Referenz auf das Steuerelement der eigenen
Anwendung, das das zuletzt aktivierte Steuerelement ist. Wenn eine andere
Anwendung aktiv ist, gibt es trotzdem ein Screen.ActiveControl, aber es hat
nicht den Fokus.

Viele Grüße

Harald M. Genauck

ABOUT Visual Basic - das Webmagazin
http://www.aboutvb.de

Herfried K. Wagner [MVP]

unread,
Aug 15, 2003, 6:57:58 AM8/15/03
to
Hallo Alexander!

"Alexander Wabro" <awa...@gmx.de> schrieb:


> wie kann man prüfen ob ein bestimmtes Steuerelement den Focus hat.
>
> Ich stelle mir das ungefähr so vor: if hasfocus(txt_EditFG) ...
>
> Gibt es so etwas ähnliches ?

Quick and Dirty, ungetestet und ohne ActiveControl:

\\\
Private Declare Function GetFocus Lib "user32.dll" () As Long
.
.
.
On Error Resume Next
Dim c As Control
Dim h As Long
h = GetFocus
For Each c In Me.Controls
If c.hWnd = h Then
Exit For
End If
Next c
Call MsgBox(c.Name)
///

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet

Purpose: Help Protect Your Computer Today (Immediately)
Action: Read about the Blaster worm and update your software
immediately. Check the Security site for more information and steps you
should take to help protect your systems.
URL: http://www.microsoft.com/security/incident/blast.asp


Thomas Haaf

unread,
Aug 15, 2003, 8:42:13 AM8/15/03
to
hi alexander,

statt deinem if-modell mit

if hasfocus(txt_EditFG)
mach was ...
end if

usw. könntest du doch die prozedur

Private Sub Text1_GotFocus()
msgbox("hat den focus"), vbOK,("Focus")
End Sub

nutzen, falls es nicht zu viele steuerelemente sind, die du abfragen musst.

gruss thomas


Private Sub txt_EditFG_GotFocus()
Alexander Wabro <awa...@gmx.de> schrieb in im Newsbeitrag:
bhi5bd$238$03$1...@news.t-online.com...

Christian Stauffer

unread,
Aug 15, 2003, 2:15:47 PM8/15/03
to
Thomas Haaf sprach:

> statt deinem if-modell mit
>
> if hasfocus(txt_EditFG)
> mach was ...
> end if
>
> usw. könntest du doch die prozedur
>
> Private Sub Text1_GotFocus()
> msgbox("hat den focus"), vbOK,("Focus")
> End Sub
>
> nutzen, falls es nicht zu viele steuerelemente sind, die du abfragen musst.

Genau. Und anstatt

sTest = ""
for lindex = 1 to 10
lblTotal(lindex).width = lblTotal(lindex).width + lDeltaWidth
next lindex

könnte man auch einfach

lblTotal(1).width = lblTotal(1).width + lDeltaWidth
lblTotal(2).width = lblTotal(2).width + lDeltaWidth
...
lblTotal(10).width = lblTotal(10).width + lDeltaWidth

benutzen.

SCNR

Gruss Christian

0 new messages