Alyanto
asked on
Is ther an alternative to activecontrol
I am working with a form and I need to know what the active control is. I am using AddHandler. So far I am using something like this
AddHandler txtBox.GotFocus, AddressOf TextBox_GotFocus
then this
Private Sub TextBox_GotFocus()
_form.ActiveControl.BackCo lor = Highlight
End Sub
I wrote a sample version outside of the main application and things went well. The controls on the form are standard windows syncfusion, and some usercontrols. All of these sit on an image panel divided up on a tabsheet.
I realise this is a bit of a soup in terms of form content, but that is what I have to work with. I supect I might be able to use an alternative approach to ActiveControl but I am not aware of it.
As a foot note the _form is a by reference to the form because this code is in a class, the intent is to create a generic branding class to enable brand format to be applied over the whole application. Also this is a winforms development.
AddHandler txtBox.GotFocus, AddressOf TextBox_GotFocus
then this
Private Sub TextBox_GotFocus()
_form.ActiveControl.BackCo
End Sub
I wrote a sample version outside of the main application and things went well. The controls on the form are standard windows syncfusion, and some usercontrols. All of these sit on an image panel divided up on a tabsheet.
I realise this is a bit of a soup in terms of form content, but that is what I have to work with. I supect I might be able to use an alternative approach to ActiveControl but I am not aware of it.
As a foot note the _form is a by reference to the form because this code is in a class, the intent is to create a generic branding class to enable brand format to be applied over the whole application. Also this is a winforms development.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Timely as ever
ASKER
Imports System.Windows.Forms
Imports System.Drawing
Public Class cGenFormFormatter
Private _form As Form
Private ReadOnly Property Highlight As Color
Get
Return Color.FromArgb(0, 43, 85)
End Get
End Property
Private Property ctrlBackColor As Color
Private Property MouseOver As Color
Private Property aControl As Control
Public Sub New(ByRef Frm As Form)
Dim icn As System.Drawing.Icon = My.Resources.form_default
Frm.Icon = icn
For Each ctrl As Control In Frm.Controls
Debug.Print(ctrl.GetType()
WhatControl(ctrl)
Next
End Sub
Public Sub WhatControl(Ctrl As Control)
Select Case Ctrl.GetType().BaseType.To
Case "System.Windows.Forms.User
UserCtrl(Ctrl)
Case Else
Select Case Ctrl.GetType().ToString
Case "Syncfusion.Windows.Forms.
GradientPanel(Ctrl)
Case "Syncfusion.Windows.Forms.
TabControlAdv(Ctrl)
Case "Syncfusion.Windows.Forms.
syncTextBox(Ctrl)
Case "System.Windows.Forms.Text
txtBox(Ctrl)
Case Else
Debug.Print(Ctrl.GetType()
End Select
End Select
End Sub
Public Sub GradientPanel(ByRef pnl As Syncfusion.Windows.Forms.T
For Each ctrl As Control In pnl.Controls
WhatControl(ctrl)
Next
End Sub
Public Sub TabControlAdv(ByRef tabs As Syncfusion.Windows.Forms.T
Try
For Each tb As Syncfusion.Windows.Forms.T
TabPageAdv(tb)
Next
Catch ex As Exception
Debug.Print(ex.Message)
End Try
End Sub
Public Sub TabPageAdv(ByRef tab As Syncfusion.Windows.Forms.T
For Each ctrl As Control In tab.Controls
WhatControl(ctrl)
Next
End Sub
Private Sub UserCtrl(ByRef UCtrl As UserControl)
For Each ctrl As Control In UCtrl.Controls
WhatControl(ctrl)
Next
End Sub
Private Sub syncTextBox(txtBox As Syncfusion.Windows.Forms.T
ctrlBackColor = txtBox.BackColor
AddHandler txtBox.GotFocus, AddressOf TextBox_GotFocus
AddHandler txtBox.LostFocus, AddressOf TextBox_LostFocus
End Sub
Private Sub TextBox_GotFocus()
_form.ActiveControl.BackCo
End Sub
Private Sub TextBox_LostFocus()
_form.ActiveControl.BackCo
End Sub
Private Sub txtBox(txtBox As System.Windows.Forms.TextB
ctrlBackColor = txtBox.BackColor
AddHandler txtBox.GotFocus, AddressOf TextBox_GotFocus
AddHandler txtBox.LostFocus, AddressOf TextBox_LostFocus
End Sub
End Class