Wenn der User darauf klickt, soll ein bestimmter "Update" im Sheet ausgeführt werden und der Button anschließend wieder "verschwinden"
Der Button ist an die Sub 'BtnFunc' gebunden.
Die Zeile "form.removeByName( model.Name )" löscht aber offenbar nur den Event (danach reagiert der Button nicht mehr auf klick's.
Die "Darstellung" verbleibt im Sheet...
Daher gehe ich davon aus das ich irgendwie auch die beiden anderen Objekte (btn & shap) löschen muss.
Nur habe ich bisher dazu nichts gefunden.
Wo (in welchem Container) sind die ?
Ich habe den Objekten extra eindeutige Namen gegeben (cell.AbsoluteName & "_BTN" & shape.Name = cell.AbsoluteName & "_SHAPE").
Als model.Name zeigt mit Xray "..._BTN" an, ".._SHAE" finde ich jedoch nicht.
Wie komme ich an die ?
Code: Alles auswählen
Public Sub PlaceBtnOnCell( action As String, form As Object, cell As Object, btnTxt As String, Optional backColor As Long, Optional tag As String )
Dim btn As Object: btn = ThisComponent.createInstance( "com.sun.star.form.component.CommandButton" )
Dim shape As Object: shape = ThisComponent.createInstance( "com.sun.star.drawing.ControlShape" )
Dim script As Object: script = new com.sun.star.script.ScriptEventDescriptor
Dim sheet As Object: sheet = cell.Spreadsheet
btn.Name = cell.AbsoluteName & "_BTN"
btn.Label = btnTxt
btn.FocusOnClick = False
If IsMissing( tag ) Then tag = cell.AbsoluteName & "_TAG"
btn.Tag = tag
shape.Name = cell.AbsoluteName & "_SHAPE"
shape.Control = btn
sheet.Drawpage.add( shape )
shape.Anchor = cell
shape.Size = GetSizeOfCellRange( cell )
shape.Position = cell.Position
shape.SizeProtect = True
shape.MoveProtect = True
If IsMissing( backColor ) Then backColor = cell.CellBackColor
shape.ControlBackground = backColor
shape.CharColor = cell.CharColor
shape.CharFontName = cell.CharFontName
shape.CharHeight = cell.CharHeight
shape.CharWeight = cell.CharWeight
script.ListenerType = "com.sun.star.awt.XActionListener"
script.EventMethod = "actionPerformed"
script.ScriptType = "StarBasic"
script.ScriptCode = action
form.registerScriptEvent( form.count - 1, script )
End Sub
Code: Alles auswählen
Sub BtnFunc( event As Variant )
RemoveButton( event.Source.Model )
End Sub
Sub RemoveButton( model As Object )
'Xray model
Dim form As Object: form = model.Parent
' removes: form.registerScriptEvent( form.count - 1, script )
'Done in PlaceBtnOnCell
'form.removeByName( model.Name )
' How to:
' get/remove shape ?
' get/remove btn ?
End Sub