|
-
Nov 30th, 2010, 06:39 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Last Activate control
MSDN brings nothing up, so here was my attempt at a work around.
Code:
Private Sub txtTime1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTime1.Leave, txtTime2.Leave, txtTime3.Leave, _
txtTime4.Leave, txtTime5.Leave, txtTime6.Leave, txtTime7.Leave
Code:
Dim LastActiveTimeControl As String = Me.ActiveControl.Name
Dim n As Integer = CInt(LastActiveTimeControl.Substring(LastActiveTimeControl.Length - 1))
n += -1
Dim newTime As String = String.Format("txtTime{0}", n)
Because event leave calls another sub i need the last active control. I have the textbox name txtTime{0} but obviously string is not a control.
So Two questions:
1) can a string value be attached to an existing control if i know it's name?
Dim attControl as Control = newTime
2) All this could be avoided in event leave if i could get the left controls name. I have tried sender.tostring etc but nothing returns the textboxs name
-
Nov 30th, 2010, 07:19 AM
#2
Re: Last Activate control
Think about what you're doing. You're getting the Name from the control and then storing it, then you're trying to use that to get the control again later. Why not just store the control in the first place?
-
Nov 30th, 2010, 07:30 AM
#3
Thread Starter
Fanatic Member
Re: Last Activate control
Thats when question 2 comes in. This would obviously been the prefered method for me. But i cant figure out
Code:
Private Sub txtTime1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTime1.Leave, txtTime2.Leave, txtTime3.Leave, _
txtTime4.Leave, txtTime5.Leave, txtTime6.Leave, txtTime7.Leave
my.settings.LastActiveControl = ' here
end sub
-
Nov 30th, 2010, 07:34 AM
#4
Re: Last Activate control
Why are you using My.Settings for a start? You should just be using a member variable.
As for what goes there, it's the 'sender'. The 'sender' is ALWAYS the object that raised the event. If you want to assign it to a variable of type Control or TextBox then you have to cast it as type Control or type TextBox.
-
Nov 30th, 2010, 07:44 AM
#5
Thread Starter
Fanatic Member
Re: Last Activate control
That was just a quick insertion my.settings.
Maybe i should of included my first attempt.....
Code:
Private Sub txtTime1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTime1.Leave, txtTime2.Leave, txtTime3.Leave, _
txtTime4.Leave, txtTime5.Leave, txtTime6.Leave, txtTime7.Leave
Dim ControlSender As Control = CType(sender, TextBox)
Debug.WriteLine(ControlSender.ToString)
End Sub
output : WindowsApplication1.SelectedText, Text: textinfield
-
Nov 30th, 2010, 07:58 AM
#6
Re: Last Activate control
There's no use assigning it to local variable because the variable ceases to exist at the end of the method. As I already said last post:
You should just be using a member variable.
-
Nov 30th, 2010, 08:24 AM
#7
Thread Starter
Fanatic Member
Re: Last Activate control
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|