What even to use for InputBox?

R

RB

For controls on a form, we used to use the <Focus> event to open the SIP and
and input box for a user to enter/revise text. Now this gets stuck in a
loop since the input box puts focus back on the control it was called from.

Private Function EditCtlDialog(ByVal strCtlName As String, ByVal strCurVal
As String, ByVal intChar As Int16, ByVal strType As String) As String

EditCtlDialog = ""

If blnOpening Then Exit Function

Dim strNewVal As String = "", strMsg As String

If intChar <> 0 Then

strMsg = "Edit text in " + strCtlName + "(" + intChar.ToString + "
characters max)"

Else

strMsg = "Edit " + strCtlName + "(" + strType + ")"

End If

strNewVal = InputBox(strMsg, strCtlName, strCurVal, 20, 20)

Select Case strType

Case "String"

strNewVal = Mid(strNewVal, 1, intChar)

Case "Date"

If Not IsDate(strNewVal) Then

MsgBox("Could not recognize date format", MsgBoxStyle.Exclamation, "Date?")

strNewVal = strCurVal

End If

Case "Number"

If Not IsNumeric(strNewVal) Then

MsgBox("Could not recognize number format " + strNewVal,
MsgBoxStyle.Exclamation, "Number?")

strNewVal = strCurVal

End If

End Select

EditCtlDialog = strNewVal

End Function

----------------------------------
Private Sub txtShipName_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles txtShipName.GotFocus

InputPanel1.Enabled = True

strNewVal = EditCtlDialog("Ship Name", txtShipName.Text, 40, "String")

InputPanel1.Enabled = False

If strNewVal <> "" Then txtShipName.Text = Trim(strNewVal)

strLastFocus = "txtShipName"

End Sub

------------------------------------------------------

What event can be used for this instead of "Focus"?

Thanks,

RB
 
C

chris-s

Before trying to use a different event, in the existing 'focus'
method, try checking the 'sender' property to see if that can be used
to detect what object has called it. If that doesn't help, try
something like this...


private m_gotFocusFlag bool = false;

private txtShipName_GotFocus(sender Object, e System.EventArgs)
{
InputPanel1.Enabled = True

strNewVal = EditCtlDialog("Ship Name", txtShipName.Text, 40, "String")

InputPanel1.Enabled = False

If strNewVal <> "" Then txtShipName.Text = Trim(strNewVal)

strLastFocus = "txtShipName"

End Sub
 
C

chris-s

Try checking the 'sender' property to see if that can be used to
determine which object has raised the event. If not trying something
like this, not pretty but it may work, sorry it's a mis-mash of code
but sure you can work it out!

private m_flag bool = false;

Private Sub txtShipName_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles txtShipName.GotFocus

if m_flag return;

m_flag = true;
try
{

InputPanel1.Enabled = True

strNewVal = EditCtlDialog("Ship Name", txtShipName.Text, 40,
"String")

InputPanel1.Enabled = False

If strNewVal <> "" Then txtShipName.Text = Trim(strNewVal)

strLastFocus = "txtShipName"
}
finally
{
m_flag = false;
}
End Sub



Chris
 
R

RB

Chris:

Thank you for your responses. After several more hours of testing including
a flag solution similar to yours, it appears that this is a catch 22 when
InputPanel and InputBox are combined to edit the value in a text control.

We're just going with moving the controls that were below the input panel to
above the input panel when they receive focus. A control's location is
restored in the lost focus and InputPanel1_EnabledChanged events.

This was something that was better managed in EVB!

Thanks again,

RB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top