VB.Net Problem Passing A Control To A Routine and retrieving the ctrls index

S

squigster

Hello Everyone,
I am having a problem when I pass a control to a routine and I want to
set properties for the control I cannot determine a way to retrieve the

passed in controls index so that I can set the properties for the
specific index. The routine blows up after the first time through. The
If idx = statement is screwed up. Any help would be appreciated.
Thanks, Jim
My code is as follows:

' I create the control here
' Add Recipe Step Number Panels 1 thru 12
pnlSteps1thru12.Controls.Add(recipeStepNumberLabel(panelIdx))
recipeStepNumberLabel(panelIdx).Left = 3
recipeStepNumberLabel(panelIdx).Top = 34 + (26 * (panelIdx - 1))
recipeStepNumberLabel(panelIdx).Width = 26
recipeStepNumberLabel(panelIdx).Height = 22


' I call the routine here!!
Call SetPanelFontAndColor(recipeStepNumberLabel)


' ROUTINE
Public Sub SetPanelFontAndColor(ByVal passedInControl() As Control)


Dim idx As Integer


Try
' Loop Through The Controls And Look For The Passed In
Index, Then Set The Control Properties
For idx = 1 To MAX_PLC_RECIPE_STEPS
If idx =
passedInControl(idx).Controls.IndexOf(passedInControl(idx)) Then
passedInControl(idx).Font = SystemDefaultFont '
Set The Font
passedInControl(idx).BringToFront()
' Bring Control To Front
passedInControl(idx).BackColor = Color.Wheat '
Set The BackColor
End If
Next idx


Exit Sub
Catch ex As Exception
If MsgExceptionFlag = 1 Then
MessageBox.Show("Center Form" + ex.Message) ' Display
During Testing
Else
SystemExceptionHandler(ex) ' Write
To File In Live Mode
End If
End Try


End Sub
 
G

Greg Young

I am not understanding what you are trying to do here but it would seem from
the code you posted that you could just do...

Public Sub SetPanelFontAndColor(ByVal passedInControl() As Control, Index
ToChange as Integer)
passedInControl(IndexToChange).Font = SystemDefaultFont
'
Set The Font
passedInControl(IndexToChange).BringToFront()
' Bring Control To Front
passedInControl(IndexToChange).BackColor = Color.Wheat
'
Set The BackColor
Next idx

Note that you would need to add error checking for the index etc.

Or am I missing something?

Cheers,

Greg Young
MVP - C#
 

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