Newsgroup: it.comp.lang.visual-basic
Titolo: more troubles with Using label instead of text box

Hi, Flavio,
Thank you for the help.
Suppose I have 10 labels, 1 text box, and 3 command buttons on a form.
As you suggested, I use Text1_LostFocus. I also set all 3 command buttons'
TabStop to True(if command buttons' TabStop is set to False, Text1_LostFocus
event won't get triggered). It works if I use tab to move the text box. But if
I mouse-click on one command button without going through all the labels, say
the focus is on Label1 or Label2 and I clicked one of the command buttons, it
will go through the Text1_LostFocus event each time the command button is
clicked until the text box has been through all labels and then the next click
on the command button will trigger Command1_Click event.
Same situation happens on the Label_Click event. I put code in Command3_
LostFocus(the last command button that TabStop will go to) to set focus on the
text box and move text box back to where Label1 is. It works if I use Tab but
if I click on the 2nd, or 3rd, or 4th or ... label while the focus is on
Command3, it will trigger the Command2_LostFocus event to go to Label1 and a
second click on a label will trigger the Label_Click event.
What should I do with this? It seems that I can make it work either Tabbing or
Mouse-clicking but not both at the same time. Can you or anyone help? Thanks!
Carol
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/
       Search, Read, Discuss, or Start Your Own    

Hi, Carol
try with the ActiveControl property of the form. The active control at the
LostFocus raising time is the next control in the tab order. If you set the Tag
property of the buttons and the labels you can select the correct action to
perform before exiting from textbox (moving the textbox or suspend any input and
pass the control to the Click event of the button). If you organised the labels in
a control array you can also move the text box over the label you have clicked,
calculating coordinates based on the Index of the lable clicked.
Excuse again, my English is the same of the yesterday's one. Let me know...
Bye
Flavio
car...@my-dejanews.com
 ha scritto:

--
--------------------------------
/DECOMPILE. Before it's too late
--------------------------------
f.ronco@*NonMiServeNiente*
flashnet.it
http:\\
www.geocities.com
\Paris\3461\
-------------------------------------------------------------
"Dio ha uno screensaver. Speriamo che non tocchi il mouse..."

Hi,
here is a sample, save it in a textfile, name it "Form1.frm" and load it in a new
project.
Or take a look at the routines and the property tables.
You can clicking on the labels and the Textbox lets you edit the label content. If you
press tab or shift+tab the textbox navigate the labels. The Return key works like the
Tab key. If you click on the Command1 button the textbox returns to home.
I'm pleased to work about this feature because I will implement in my current project.
I simply have anticipated the task...
Flavio
f.ronco@*NonMiServeNiente*
flashnet.it
http:\\
www.geocities.com
\Paris\3461\
-------------------------------------------------------------
"Dio ha uno screensaver. Speriamo che non tocchi il mouse..."
--------------------------------------------------------------
VERSION 5.00
Begin VB.Form Form1
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows Default
   Tag             =   "Command1"
   Begin VB.TextBox Text2
      Appearance      =   0  'Flat
      BackColor       =   &H8000000F&
      Height          =   285
      Index           =   0
      Left            =   540
      Locked          =   -1  'True
      TabIndex        =   0
      Tag             =   "Dummy"
      Text            =   "Dummy For LeftTab"
      Top             =   180
      Width           =   1545
   End
   Begin VB.TextBox Text2
      Appearance      =   0  'Flat
      BackColor       =   &H8000000F&
      Height          =   285
      Index           =   1
      Left            =   495
      Locked          =   -1  'True
      TabIndex        =   2
      Tag             =   "Dummy"
      Text            =   "Dummy For Right Tab"
      Top             =   825
      Width           =   1575
   End
   Begin VB.CommandButton Command1
      Caption         =   "Command1"
      Height          =   330
      Left            =   3135
      TabIndex        =   5
      Tag             =   "Button"
      Top             =   2070
      Width           =   1275
   End
   Begin VB.TextBox Text1
      Height          =   285
      Left            =   690
      MaxLength       =   128
      TabIndex        =   1
      Tag             =   "Textbox"
      Text            =   "Text1"
      Top             =   495
      Width           =   1200
   End
   Begin VB.Label Label
      BorderStyle     =   1  'Fixed Single
      Caption         =   "Label2"
      Height          =   270
      Index           =   2
      Left            =   3195
      TabIndex        =   6
      Tag             =   "Label2"
      Top             =   1305
      Width           =   1200
   End
   Begin VB.Label Label
      BorderStyle     =   1  'Fixed Single
      Caption         =   "Label1"
      Height          =   270
      Index           =   1
      Left            =   3195
      TabIndex        =   4
      Tag             =   "Label1"
      Top             =   1020
      Width           =   1200
   End
   Begin VB.Label Label
      BorderStyle     =   1  'Fixed Single
      Caption         =   "Label0"
      Height          =   270
      Index           =   0
      Left            =   3195
      TabIndex        =   3
      Tag             =   "Label0"
      Top             =   735
      Width           =   1200
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim iIndex As Integer
Private Sub Command1_Click()
    Text1.Top = 495
    Text1.Left = 690
    iIndex = -1
End Sub
Private Sub Label1_Click()
End Sub
Private Sub Form_Load()
    iIndex = -1 'the Textbox is initially out of the grid
End Sub
Private Sub Label_Click(Index As Integer)
    Text2(0).TabStop = True 'Sets The Dummy Control actives so the Text1 tabs to it
    Text2(1).TabStop = True
    If iIndex <> -1 Then
        Label(iIndex) = Text1
    End If
    Text1.Top = Label(Index).Top
    Text1.Left = Label(Index).Left
    Text1 = Label(Index)
    iIndex = Index
    Text1.SetFocus
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = Asc(vbCr) Then
        KeyAscii = 0 '(Prevent the beep)
        Text2(1).SetFocus
    End If
End Sub
Private Sub Text1_LostFocus()
    If Me.ActiveControl.Tag = "Dummy" Then
        'iIndex = -1 means that control is out of the grid
        Label(iIndex).Caption = Text1
        iIndex = iIndex + CInt(Me.ActiveControl.TabIndex < Text1.TabIndex) -
CInt(Me.ActiveControl.TabIndex > Text1.TabIndex)
        If iIndex > 2 Then iIndex = 0
        If iIndex < 0 Then iIndex = 2
        Text1.Top = Label(iIndex).Top
        Text1.Left = Label(iIndex).Left
        Text1.SetFocus
        Text1 = Label(iIndex).Caption
    Else
        iIndex = -1
        Text2(0).TabStop = True 'Sets The Dummy Control not selectable
        Text2(1).TabStop = True
    End If
End Sub