You cannot pass a reference to the Width property, as you'd need to pass the backing field value ByRef rather than the property, and you don't have access to that. What you could do is pass the button itself, although then you'd be tied to altering the Width property on anything you passed. What I might be tempted to do is instead pass a Func and an Action. Assuming that you solve the cross threading issue separately (i.e. so I'm not completely rewriting your sample) you could look at something like this:
Code:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim t As New Threading.Thread(Sub() Tweener(Function() (Button1.Width), Function(newWidth As Integer) (Button1.Width = newWidth), 100, 400)) t.Start() End Sub Public Sub Tweener(ByVal getTarget As Func(Of Integer), ByVal setTarget As Action(Of Integer), ByVal Amount As Integer, ByVal tPeriod As Integer) Dim stopat As Integer = Environment.TickCount + tPeriod Dim tFrame = 40 Dim chunk As Integer = Amount / (tPeriod / tFrame) While Environment.TickCount < stopat setTarget(getTarget() + chunk) Application.DoEvents() Threading.Thread.Sleep(tFrame) End While End Sub




Reply With Quote