With statement

Status
Niet open voor verdere reacties.

bn2vs

Terugkerende gebruiker
Lid geworden
18 aug 2007
Berichten
1.705
Is het mogelijk om iets in deze aard te doen?

With control1, control2, control3
.propertie = value
End with
 
als je het zelf probeert dan weet je het gelijk? :p

zie http://msdn2.microsoft.com/en-us/library/wc500chb(VS.80).aspx
- Accessing Other Objects. Once you have entered a With block, you cannot reassign object until you have passed the End With statement.(...) You can use methods and properties of other objects, but you must qualify them with their object names.
ik kon niets vinden, en met zelf wat geknutsel met VB ook niet.

wel: http://msdn2.microsoft.com/en-us/library/8y82wx12(VS.80).aspx
Code:
For Each ctl As System.Windows.Forms.Control In Me.Controls
    With ctl
        .BackColor = System.Drawing.Color.Yellow
        .ForeColor = System.Drawing.Color.Black
        If .CanFocus Then
            .Text = "Colors changed"
            If Not .Focus() Then
                ' Insert code to process failed focus.
            End If
        End If
    End With
Next ctl
 
dat is idd een oplossing, maar niet echt ideaal als je bv 3 controls hebt waarbei je properties wil veranderen en in totaal 10 controls van dat type hebt in je collectie... dan moet je nog eerst de naam gaan liggen controleren enzo, en kan je het evengoed met meer with-statements doen, wat dan zelf sneller gaat als ik me niet vergis...
 
ik zie mijn code en denk... zomg?

Code:
For Each ctl As System.Windows.Forms.textbox In Me.Controls
    With ctl
        .text = "yo"
    End With
Next ctl
zoiets mischien? (iets in die richting, probeer de 'for each ctl as ....... aan te passen (de ....))
 
zoiets?

For Each ctl As System.Windows.Forms.textbox In Me.Controls
select case ctl.name
case ctrl1.name, ctrl2.name, ctrl3.name
With ctl
.text = "yo"
End With
end select
Next ctl
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan