T
Toe Dipper
In short we have a lengthy process when a form is loaded that adds
activex controls to our windows form. This process in itself works
fine however we would like to push this processing to a thread but are
stumped so far.
Our goal is simply to allow the form to fully display while the
controls are being added. Preferrably with a progressbar to let them
know that the form is still being built.
Here are some snippets.
Private Sub Form_Shown(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Shown
Dim myThread As Threading.Thread
myThread = New Threading.Thread(AddressOf load_udfSections)
myThread.SetApartmentState(Threading.ApartmentState.STA)
myThread.Start()
End Sub
Private Sub load_udfSections()
...
udfSection = New AxTdF_DynamicUDF.AxDynUDF
udfSection.BeginInit()
udfSection.Anchor =
CType(((System.Windows.Forms.AnchorStyles.Top Or
System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right),
System.Windows.Forms.AnchorStyles)
udfSection.Enabled = True
udfSection.Visible = False
udfSection.Location = New
System.Drawing.Point(ToolStripContainer1.ContentPanel.Margin.Left,
currentTop)
udfSection.Name = "AxDynUDF" & CStr(controlIndex + 1)
With ToolStripContainer1.ContentPanel
axWidth = .Width - (.Margin.Left + .Margin.Right)
End With
udfSection.Size = New System.Drawing.Size(axWidth, 1)
ToolStripContainer1.ContentPanel.Invoke(New
addControl(AddressOf addControlToToolstrip), udfSection)
udfSection.EndInit()
udfSection.load_Controls(CShort(reader("ControlGroupID")), True)
.....
End Sub
There is a delegate called addcontroltoToolstrip for the following
function.
Private Sub addControlToToolstrip(ByVal activexControl As
AxTdF_DynamicUDF.AxDynUDF)
ToolStripContainer1.ContentPanel.Controls.Add(activexControl)
End Function
The invoke on the toolstrip seems to work fine but then when we try to
call endinit() it errors telling us that the control has been modified
in a different thread.
Any ideas? Only been using .NET for a week so there is no chance of
offending me. In VB6 we would have just started a timer in the show
event of the form which would let the event exit and then the timer
would process our lengthy code. Ugly but it at least allowed the form
to fully display before adding the remaining controls. Looking for
something a little bit more interactive.
Glenn Welker
activex controls to our windows form. This process in itself works
fine however we would like to push this processing to a thread but are
stumped so far.
Our goal is simply to allow the form to fully display while the
controls are being added. Preferrably with a progressbar to let them
know that the form is still being built.
Here are some snippets.
Private Sub Form_Shown(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Shown
Dim myThread As Threading.Thread
myThread = New Threading.Thread(AddressOf load_udfSections)
myThread.SetApartmentState(Threading.ApartmentState.STA)
myThread.Start()
End Sub
Private Sub load_udfSections()
...
udfSection = New AxTdF_DynamicUDF.AxDynUDF
udfSection.BeginInit()
udfSection.Anchor =
CType(((System.Windows.Forms.AnchorStyles.Top Or
System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right),
System.Windows.Forms.AnchorStyles)
udfSection.Enabled = True
udfSection.Visible = False
udfSection.Location = New
System.Drawing.Point(ToolStripContainer1.ContentPanel.Margin.Left,
currentTop)
udfSection.Name = "AxDynUDF" & CStr(controlIndex + 1)
With ToolStripContainer1.ContentPanel
axWidth = .Width - (.Margin.Left + .Margin.Right)
End With
udfSection.Size = New System.Drawing.Size(axWidth, 1)
ToolStripContainer1.ContentPanel.Invoke(New
addControl(AddressOf addControlToToolstrip), udfSection)
udfSection.EndInit()
udfSection.load_Controls(CShort(reader("ControlGroupID")), True)
.....
End Sub
There is a delegate called addcontroltoToolstrip for the following
function.
Private Sub addControlToToolstrip(ByVal activexControl As
AxTdF_DynamicUDF.AxDynUDF)
ToolStripContainer1.ContentPanel.Controls.Add(activexControl)
End Function
The invoke on the toolstrip seems to work fine but then when we try to
call endinit() it errors telling us that the control has been modified
in a different thread.
Any ideas? Only been using .NET for a week so there is no chance of
offending me. In VB6 we would have just started a timer in the show
event of the form which would let the event exit and then the timer
would process our lengthy code. Ugly but it at least allowed the form
to fully display before adding the remaining controls. Looking for
something a little bit more interactive.
Glenn Welker