VS 2005 & AC 2006
I have a problem: I have a palette in my project that contains controls such as multiple textboxes, combobox, buttons, etc. These controls are there to supply the user with calculated data as the user draws figures graphically on the drawing.
However, the only time I can get the controls to refresh on the palette is when the refreshcontrols subroutine is run by an event fired by a control on my palette. The following is the routine in the palette control code that is used to refresh the controls: (You can see everything I have tried in the commented fields)
Public Sub RefreshControls()
'Dim docLock As DocumentLock = AcadApp.DocumentManager.MdiActiveDocument.LockDocument _
' (Autodesk.AutoCAD.ApplicationServices.DocumentLockMode.Write, "NB", "NB", True)
'NativeMethods.SetFocus(Me.Handle)
'ResetUCSButton.Enabled = True
'AddNewBeamButton.Enabled = True
'DistLoadButton.Enabled = True
'PointLoadButton.Enabled = True
LengthBox.Text = AppStart.CurrentBeam.Length.ToString
BeamNameText.Text = AppStart.CurrentBeam.Name
DeflectionBox.Text = AppStart.CurrentBeam.DeflectionFactorLL & "/" & AppStart.CurrentBeam.DeflectionFactor
'MomentBox.Text = AppStart.CurrentBeam.CalcMoment.ToString
'ShearBox.Text = AppStart.CurrentBeam.CalcShear.ToString
'DeflBox.Text = AppStart.CurrentBeam.DistributedLoads.Count
'LengthBox.Invalidate()
'LengthBox.Refresh()
'BeamNameText.Refresh()
'DeflectionBox.Refresh()
'MomentBox.Refresh()
'ShearBox.Refresh()
'DeflBox.Refresh()
'ComboBox1.Refresh()
'ComboBox1.Items.Clear()
'Dim beams(AppStart.CurrentBeam.PassingBeams.Count) As String
'Dim count As Integer = 1
'For Each beam As BeamType In AppStart.CurrentBeam.PassingBeams
' beams.SetValue(beam, count)
' count += 1
'Next
ComboBox1.DataSource = Nothing
ComboBox1.DataSource = AppStart.CurrentBeam.PassingBeams
If ComboBox1.Items.Count > 0 Then
ComboBox1.SelectedIndex = 0
End If
Me.Refresh()
MyBase.Refresh()
'AppStart.mPaletteSet.Visible = False
'AppStart.mPaletteSet.Visible = True
'ComboBox1.DisplayMember = "FullName"
'docLock.Dispose()
'Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.UpdateScreen()
'Autodesk.AutoCAD.ApplicationServices.Application.UpdateScreen()
End Sub
The following is an examble of a handled button click event. When this is fired from a real "click" on a button on my palette, everything works fine as long as I run the NewBeamCommand subroutine directly. However, if I sendstringtoexecute then i have the same problem of the controls never refreshing. It seems that whenever I pass control to the Autocad Editor my palette stops repainting.
Private Sub AddNewBeamButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddNewBeamButton.Click
AddNewBeamButton.Enabled = False
DistLoadButton.Enabled = False
PointLoadButton.Enabled = False
ResetUCSButton.Enabled = False
NativeMethods.SetFocus(AcadApp.DocumentManager.MdiActiveDocument.Window.Handle)
Dim docLock As DocumentLock = AcadApp.DocumentManager.MdiActiveDocument.LockDocument _
(Autodesk.AutoCAD.ApplicationServices.DocumentLockMode.Write, "NB", "NB", True)
Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
'Commands.Command("NB")
NewBeamCommand() '<- This sub marked with command attribute NB
'Application.DocumentManager.MdiActiveDocument.SendStringToExecute("_NB ", True, False, True)
RefreshControls() 'WHY WONT THIS WORK ARGGGHHHH!!!
Dim db As Database = HostApplicationServices.WorkingDatabase()
If Not XDataHelper.HasActiveTag(db) Then
XDataHelper.TagAcadDoc(db)
End If
ResetUCSButton.Enabled = True
AddNewBeamButton.Enabled = True
DistLoadButton.Enabled = True
PointLoadButton.Enabled = True
AcadUi.SetUCS(Matrix3d.AlignCoordinateSystem(Ge.kOrigin, Ge.kXAxis, Ge.kYAxis, Ge.kZAxis, Ge.kOrigin, Ge.kXAxis, Ge.kYAxis, Ge.kZAxis))
docLock.Dispose()
End Sub
It is important to note that during debugging, I have identified that the controls properties are updated with the correct data every time. However, the controls are never repainted.
This is very frustrating because the data the controls hold is the whole reason for this program. Unless I figure this out, I will have to force the user to click a button every time they want to use a feature of my program, instead of being able to use commands and the command buffer!
I truly appreciate any help you can give me. I have been lurking here for a while and you guys seem to know your stuff. If you need more info or code, I will be happy to supply as much as I can.
Thanks!