P
Peter
I'm looking to create multiple textboxs that change to a light blue on
focus. What is the most efficient way to do this?
-Peter
focus. What is the most efficient way to do this?
-Peter
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Peter said:I'm looking to create multiple textboxs that change to a light blue on
focus. What is the most efficient way to do this?
Phill. W said:Peter said:I'm looking to create multiple textboxs that change to a light blue on
focus. What is the most efficient way to do this?
Create a UserControl and change it to inherit directly from TextBox,
then pop code in the OnGotFocus() routine, as in
[MyTextBox.vb]
Public Class MyTextBox
Inherits System.Windows.Forms.TextBox
Public Overrides Sub OnGotFocus( ...
MyBase.OnGotFocus( ...
Me.BackColor = ...
End Sub
End Class
OK, getting it into the Toolbox to use in other applications is fiddly, but
the code's there and ready to roll ...
HTH,
Phill W.
Cor Ligthert said:Hal,
There are a lot of control arrays in VBNet.
I have a complete sample using it, I have pasted it bellow. It looks very
much your enter leave problem. Just copy it to a new project and add 2
buttons and a textbox on the form. It is hoovering a button, however for a
textbox it goes the same.
This is one approacht of using an array of controls in VBNet. However you
can as well use for this the control.collection.
However the behaviour of control arrays has changed from VB6 what was a
little bit strange approach. (More a table of all controls of a certaintype
than a control array, how you would deal with that when you by instance
inherit from a control to make an almost the same look alike).
About the dataset you will probably in future always hope that you don't
ever have to use the recordset again.
(The sample from Scott is very good, it is the same as this just an other
approach using the array for setting the handlers, which is here for 2
buttons, however could be a bunch)
I hope this gives some ideas?
Cor
\\\needs two buttons and a label on a form
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim btnArea As Button() = New Button() {Button1, Button2}
For Each btn As Button In btnArea
AddHandler btn.MouseLeave, AddressOf Button_MouseLeave
AddHandler btn.MouseEnter, AddressOf Button_MouseEnter
Next
End Sub
Private Sub Button_MouseLeave(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Button).BackColor = Color.Black
Me.Label1.Text = ""
End Sub
Private Sub Button_MouseEnter(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Button).BackColor = Color.Red
Me.Label1.Text = DirectCast(sender, Button).Name
End Sub
End Class
///
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.