473,662 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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(r ecipeStepNumber Label(panelIdx) )
recipeStepNumbe rLabel(panelIdx ).Left = 3
recipeStepNumbe rLabel(panelIdx ).Top = 34 + (26 * (panelIdx - 1))
recipeStepNumbe rLabel(panelIdx ).Width = 26
recipeStepNumbe rLabel(panelIdx ).Height = 22
' I call the routine here!!
Call SetPanelFontAnd Color(recipeSte pNumberLabel)
' ROUTINE
Public Sub SetPanelFontAnd Color(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(passedI nControl(idx)) Then
passedInControl (idx).Font = SystemDefaultFo nt '
Set The Font
passedInControl (idx).BringToFr ont()
' Bring Control To Front
passedInControl (idx).BackColor = Color.Wheat '
Set The BackColor
End If
Next idx
Exit Sub
Catch ex As Exception
If MsgExceptionFla g = 1 Then
MessageBox.Show ("Center Form" + ex.Message) ' Display
During Testing
Else
SystemException Handler(ex) ' Write
To File In Live Mode
End If
End Try
End Sub

May 26 '06 #1
2 1466
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 SetPanelFontAnd Color(ByVal passedInControl () As Control, Index
ToChange as Integer)
passedInControl (IndexToChange) .Font = SystemDefaultFo nt
'
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#
"squigster" <js*********@co refurnace.com> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.com.. .
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(r ecipeStepNumber Label(panelIdx) )
recipeStepNumbe rLabel(panelIdx ).Left = 3
recipeStepNumbe rLabel(panelIdx ).Top = 34 + (26 * (panelIdx - 1))
recipeStepNumbe rLabel(panelIdx ).Width = 26
recipeStepNumbe rLabel(panelIdx ).Height = 22
' I call the routine here!!
Call SetPanelFontAnd Color(recipeSte pNumberLabel)
' ROUTINE
Public Sub SetPanelFontAnd Color(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(passedI nControl(idx)) Then
passedInControl (idx).Font = SystemDefaultFo nt '
Set The Font
passedInControl (idx).BringToFr ont()
' Bring Control To Front
passedInControl (idx).BackColor = Color.Wheat '
Set The BackColor
End If
Next idx
Exit Sub
Catch ex As Exception
If MsgExceptionFla g = 1 Then
MessageBox.Show ("Center Form" + ex.Message) ' Display
During Testing
Else
SystemException Handler(ex) ' Write
To File In Live Mode
End If
End Try
End Sub

May 27 '06 #2
Thanks, I got it to work.

Jim

May 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
5937
by: Paul | last post by:
I want to use sessions to cover myself in case the user switches off cookies so I am passing the session ID manually through a hidden input field. This is what I have so far. index.php page contains: <?php $_SESSION = ""; $_SESSION = "";
1
7780
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains: ---------------------------------------------------------------------------- <?php ini_set("session.use_cookies", "off"); ini_set("session.use_trans_sid", "on"); session_start(); $_SESSION = ""; $_SESSION = ""; echo "<form method='POST' action='login.php'>
39
7639
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down indicate: a) That I don't know enough b) Passing arguments by ref is bad
2
1564
by: Tamarack | last post by:
I have a simple function which loops through all the controls on a form searching for a specific one: Public Function FindControl(ByVal ctrls As Control.ControlCollection, ByVal ctrlName As String) As Control For Each ctrl As Control In ctrls If ctrl.Name = ctrlName.Trim Then Return ctrl End If
31
7202
by: jcrouse | last post by:
Is there a quick and easy way to change the color of a label controls border from the default black to white? Thank you, John
0
1331
by: Rene Aichinger | last post by:
Hi, I've created a server control (it inherits from WebControl) wich has a property of genertic collection type. The type of the generic collection is NavigationItem, a little class I've created... The declaration of the collection property is that:
4
1293
by: Peter Newman | last post by:
im trying to write a global function to set controls up throughout a project. ive managed to create a procedure to set the the basics on each form but want to expand it to be able to set properties ie colours and text fonts for each type of control on a form ie Public sub setControls( formName as form) dim CtrlControl as Control for each CtrlControl in formName.gettype
1
1501
by: krishnasamy | last post by:
Hi, I am retrieving the image from DLL through vc++ dll. Actually Image is retrieving in Callback function of main function. When I writing that image file inside of the Callback function then no problem in retrieving. At the same I want to send the Imagedata to the another function and write the same which cause the error. Here I given that code,
7
1375
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
i have a master page and aseries of controls labeled fn1, fn2, fn3 , ... i want ot loop and use find control but i'm finding them. i'm using the following w/o luck ContentPlaceHolder cph = (ContentPlaceHolder)Page.Master.FindControl("ContentPlaceHolder1"); for (int i = 0; i < 7; i++) {
0
8856
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8545
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7365
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4179
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1992
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.