Difference between revisions of "Marshalling updates to a text box"
From RayHarwood
| Line 3: | Line 3: | ||
The code isn't difficult to write, but it is ''complex'', in that it's not intuitive nor easy to simply type out when you need it. | The code isn't difficult to write, but it is ''complex'', in that it's not intuitive nor easy to simply type out when you need it. | ||
| − | '''NOTE: | + | Delegate Sub AddLogtext_Callback(TB As TextBox, Text As String) |
| + | ' | ||
| + | Private MyTB As TextBox = Nothing | ||
| + | ' | ||
| + | Sub AddLogText_Invoke(TB As TextBox, Text As String) | ||
| + | If TB.InvokeRequired Then | ||
| + | Dim AddLogText_Delegate As New AddLogtext_Callback(AddressOf AddLogText_Invoke) | ||
| + | MyTB = TB | ||
| + | Dim ParmArray() As Object = {MyTB, Text} | ||
| + | MyTB.Invoke(AddLogText_Delegate, ParmArray) | ||
| + | Else | ||
| + | tbInfo.Text &= Format(Now, "hh:mm:ss tt") & " " & Text & vbCrLf | ||
| + | tbInfo.Select(tbInfo.TextLength, 1) | ||
| + | tbInfo.ScrollToCaret() | ||
| + | Application.DoEvents() | ||
| + | End If | ||
| + | End Sub | ||
| + | ' | ||
| + | Sub LogInfo(Text As String) | ||
| + | _TextIsDirty = True | ||
| + | AddLogText_Invoke(tbInfo, Text) | ||
| + | End Sub | ||
| + | |||
| + | '''NOTE: The code below isn't right either! Be sure to model after the above code''' | ||
Private Delegate Sub ShowText(Text As String) | Private Delegate Sub ShowText(Text As String) | ||