von Frieder D. » Do, 17.05.2012 18:55
			
			
			Hallo Rik
Ich habe es auch einmahl mit einem focus listener probiert, aber das Ergebnis ist nicht überzeugend.
versuche ich nun z.B. verschiedene Objekte in einem Dokument anzuklicken, so gelingt das nicht immer. 
Außerdem liegt bei deinem Code so einiges im Argen.
Du solltest dir angewöhnen Variablen auch zu deklarieren.
meine Erfahrung hat gezeigt, je mehr Listener man in einem Makro unterbringt, desto instabiler wird es.
um dein Tool stabiler und besser zu machen, würde ich noch einmahl  ganz von vorne anfangen.
Hier der Code:
Code: Alles auswählen
REM  *****  BASIC  *****
Global oNumSX as object
Global oNumSY as object 
Global oNumX as object
Global oNumY as object
Global oNumStep as object
Global X as double
Global Y as double
Global SX as double
Global SY as double
Global odlg as object
Global l as double
global dstep as double
global bThenth as boolean
Global oPreviousSel as object
Global oSelectionChangeListener 
Global ocontroller
Sub S_Create_Dialog_MiniMove
   
Dim oWindow As Object
Dim oMod As Object
Dim i As Integer
if  dstep = 0 then dstep = 1
If  not isNull (odlg) then 
  if odlg.isVisible() Then
    odlg.setVisible(False)
    odlg.dispose
  end if
end if
'oSelectionChangeListener entfernen
  if Not ( isEmpty (oSelectionChangeListener) or  IsNull(oSelectionChangeListener)) then 
    ocontroller.removeSelectionChangeListener(oSelectionChangeListener)
    oSelectionChangeListener=Null
  end if
'Göße und position des objekts bestimmen(Globale Variablen füllen),
' und überprüfen, ob es ein Grafikobject ist.
if not get_size_and_pos () then
    msgbox ("Please select"+chr(13)+"→ shape"+chr(13)+"→ picture"+chr(13)+"→ frame"+chr(13)+"→ floating frame"+chr(13)+"→ control",64,"MMove")
    exit sub
End if
REM ***** Initialisierung der Eigenschaften des Dialogs
odlgModel = CreateUnoService("com.sun.star.awt.UnoControlDialogModel")
With odlgModel
	.setPropertyValue("PositionX", 320)
	.setPropertyValue("PositionY", 111 )
	.setPropertyValue("FontName", Font)
	.setPropertyValue("Width", 82)
	.setPropertyValue("Height", 76)
	.setPropertyValue("Title", "MiniMove")
	.setPropertyValue("Name", "DLGMove")
	'.setPropertyValue("DesktopAsParent", True )
End With
       
odlg = CreateUnoService("com.sun.star.awt.UnoControlDialog")
       
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
	.setPropertyValue("Label", "X")
	.setPropertyValue("Name", "lblSX")
	.setPropertyValue("PositionX", 2)
	.setPropertyValue("PositionY", 11)
	.setPropertyValue("Height",11)
	.setPropertyValue("Width", 6)
End With
odlgModel.insertByName("lblSX", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
	.setPropertyValue("Label", "Y")
	.setPropertyValue("Name", "lblSY")
	.setPropertyValue("PositionX", 76)
	.setPropertyValue("PositionY", 11)
	.setPropertyValue("Height",11)
	.setPropertyValue("Width", 6)
End With
odlgModel.insertByName("lblSY", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
	.setPropertyValue("Label", "X")
	.setPropertyValue("Name", "lblX")
	.setPropertyValue("PositionX", 2)
	.setPropertyValue("PositionY", 57)
	.setPropertyValue("Height",11)
	.setPropertyValue("Width", 6)
End With
odlgModel.insertByName("lblX", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
	.setPropertyValue("Label", "Y")
	.setPropertyValue("Name", "lblY")
	.setPropertyValue("PositionX", 76)
	.setPropertyValue("PositionY", 57)
	.setPropertyValue("Height",11)
	.setPropertyValue("Width", 6)
End With
odlgModel.insertByName("lblY", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
	.setPropertyValue("Label", "Size")
	.setPropertyValue("Name", "lblSize")
	.setPropertyValue("PositionX", 8)
	.setPropertyValue("PositionY", 4)
	.setPropertyValue("Height",8)
	.setPropertyValue("Width",20)
	.setPropertyValue("FontHeight",7)
End With       
odlgModel.insertByName("lblSize", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
	.setPropertyValue("Label", "[mm]")
	.setPropertyValue("Name", "lblSmm")
	.setPropertyValue("PositionX", 54)
	.setPropertyValue("PositionY", 4)
	.setPropertyValue("Height",8)
	.setPropertyValue("Width", 50)
	.setPropertyValue("FontHeight",6)
End With       
odlgModel.insertByName("lblSmm", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
	.setPropertyValue("Label", "Step")
	.setPropertyValue("Name", "lblStep")
	.setPropertyValue("PositionX", 31)
	.setPropertyValue("PositionY", 24)
	.setPropertyValue("Height",8)
	.setPropertyValue("Width", 23)
	.setPropertyValue("FontHeight",7)
End With       
odlgModel.insertByName("lblStep", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
	.setPropertyValue("Label", "Position")
	.setPropertyValue("Name", "lblPosition")
	.setPropertyValue("PositionX", 8)
	.setPropertyValue("PositionY", 50)
	.setPropertyValue("Height",8)
	.setPropertyValue("Width", 23)
	.setPropertyValue("FontHeight",7)
End With       
odlgModel.insertByName("lblPosition", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
	.setPropertyValue("Label", "[mm]")
	.setPropertyValue("Name", "lblPmm")
	.setPropertyValue("PositionX", 54)
	.setPropertyValue("PositionY", 50)
	.setPropertyValue("Height",8)
	.setPropertyValue("Width", 50)
	.setPropertyValue("FontHeight",6)
End With       
odlgModel.insertByName("lblPmm", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
	.setPropertyValue("Label", "made by rikhustede.de")
	.setPropertyValue("Name", "lblmadeby")
	.setPropertyValue("PositionX", 34)
	.setPropertyValue("PositionY", 70)
	.setPropertyValue("Height",8)
	.setPropertyValue("Width", 50)
	.setPropertyValue("FontHeight",6)
End With       
odlgModel.insertByName("lblmadeby", oMod)
REM ********** Optionsbuttons erzeugen
dim s_buttons(3,4) as variant
s_buttons(0,1)="↑"
s_buttons(0,2)="→"
s_buttons(0,3)="↓"
s_buttons(0,4)="←"
s_buttons(1,1)=31
s_buttons(1,2)=54
s_buttons(1,3)=31
s_buttons(1,4)=8
  
s_buttons(2,1)=4
s_buttons(2,2)=27
s_buttons(2,3)=50
s_buttons(2,4)=27
s_buttons(3,1)="Y - 100"
s_buttons(3,2)="X + 100"
s_buttons(3,3)="Y + 100"
s_buttons(3,4)="X - 100"
       
for i=1 to 4
 oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlButtonModel")
 With oMod
	 .setPropertyValue("Label", s_buttons(0,i))
	 .setPropertyValue("Name", "cmd"+i)
	 .setPropertyValue("PositionX", s_buttons(1,i))
	 .setPropertyValue("PositionY", s_buttons(2,i))
	 .setPropertyValue("Height", 20)
	 .setPropertyValue("Width", 20)
	 .setPropertyValue("Tag", s_buttons(3,i))
	 .setPropertyValue("FontHeight",18)
	 .setPropertyValue("FocusOnClick",false)
	 .setPropertyValue("Tabstop",false)
 End With
 odlgModel.insertByName("cmd"+i, oMod)
next i
       
      
REM **********numerisches Feld erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlNumericFieldModel")
With oMod
	.setPropertyValue("Name", "NumSX")
	.setPropertyValue("PositionX", 8)
	.setPropertyValue("PositionY", 10)
	.setPropertyValue("Height", 10)
	.setPropertyValue("Width", 20)
	.setPropertyValue("Value", SX)
End With      
odlgModel.insertByName("NumSX", oMod)
REM **********numerisches Feld erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlNumericFieldModel")
With oMod
	.setPropertyValue("Name", "NumSY")
	.setPropertyValue("PositionX", 54)
	.setPropertyValue("PositionY", 10)
	.setPropertyValue("Height", 10)
	.setPropertyValue("Width", 20)
	.setPropertyValue("Value", SY)
End With      
odlgModel.insertByName("NumSY", oMod)
REM **********numerisches Feld erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlNumericFieldModel")
With oMod
	.setPropertyValue("Name", "NumX")
	.setPropertyValue("PositionX", 8)
	.setPropertyValue("PositionY", 56)
	.setPropertyValue("Height", 10)
	.setPropertyValue("Width", 20)
	.setPropertyValue("Value", X)
End With      
odlgModel.insertByName("NumX", oMod)
REM **********numerisches Feld erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlNumericFieldModel")
With oMod
	.setPropertyValue("Name", "NumY")
	.setPropertyValue("PositionX", 54)
	.setPropertyValue("PositionY", 56)
	.setPropertyValue("Height", 10)
	.setPropertyValue("Width", 20)
	.setPropertyValue("Value", Y)
End With      
odlgModel.insertByName("NumY", oMod)
REM **********numerisches Drehfeld erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlNumericFieldModel")
With oMod
	.setPropertyValue("Name", "NumStep")
	.setPropertyValue("PositionX", 31)
	.setPropertyValue("PositionY", 30)
	.setPropertyValue("Height", 12)
	.setPropertyValue("Width", 20)
	.setPropertyValue("Value", dstep)
	.setPropertyValue("Spin", true)
	.setPropertyValue("ValueMax",20)
	.setPropertyValue("ValueMin",1)
End With  
odlgModel.insertByName("NumStep", oMod)
REM **********Checkbox erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlCheckBoxModel")
With oMod
	.setPropertyValue("Name", "ChkStep")
	.setPropertyValue("PositionX", 31)
	.setPropertyValue("PositionY", 42)
	.setPropertyValue("Height", 14)
	.setPropertyValue("Width", 20)
	.setPropertyValue("Label", "1/10")
	.setPropertyValue("FontHeight",7)
End With
if bthenth = false then
 oMod.setPropertyValue("State", 0)
else
 oMod.setPropertyValue("State", 1)
endif
odlgModel.insertByName("ChkStep", oMod)
odlg.setModel(odlgModel)
      
oNumSX= odlg.getcontrol("NumSX")
oNumSY = odlg.getcontrol("NumSY")  
oNumX = odlg.getcontrol("NumX")
oNumY = odlg.getcontrol("NumY")
oNumStep = odlg.getcontrol("NumStep")
oChkStep = odlg.getcontrol("ChkStep")
oNumSX.DecimalDigits = 1
oNumSY.DecimalDigits = 1
oNumX.DecimalDigits = 1
oNumY.DecimalDigits = 1
Set_digits
      
REM ********** Listener für den Register erzeugen Button
ocmd_move_Listener = createUnoListener("cmd_move_", "com.sun.star.awt.XActionListener")
for i=1 to 4
	oControl = odlg.getControl("cmd"+i)
	oControl.addActionListener(ocmd_move_Listener)
next i
o_numS_focus_Listener = createUnoListener("numS_focus_", "com.sun.star.awt.XFocusListener")
oNumSX.addFocusListener(o_numS_focus_Listener)
oNumSY.addFocusListener(o_numS_focus_Listener)
o_num_focus_Listener = createUnoListener("num_focus_", "com.sun.star.awt.XFocusListener")
oNumX.addFocusListener(o_num_focus_Listener)
oNumY.addFocusListener(o_num_focus_Listener)
o_numS_key_Listener = createUnoListener("numS_key_", "com.sun.star.awt.XKeyListener")
oNumSX.addKeyListener(o_numS_key_Listener)
oNumSY.addKeyListener(o_numS_key_Listener)
o_num_key_Listener = createUnoListener("num_key_", "com.sun.star.awt.XKeyListener")
oNumX.addKeyListener(o_num_key_Listener)
oNumY.addKeyListener(o_num_key_Listener)
o_ChkStep_item_Listener = createUnoListener("chk_item_", "com.sun.star.awt.XItemListener")
oChkStep.addItemListener(o_ChkStep_item_Listener)
o_NumStep_text_Listener = createUnoListener("numstep_text_", "com.sun.star.awt.XTextListener")
oNumStep.addTextListener(o_NumStep_text_Listener)
      
REM ********** Mittels des Modells den Dialog anzeigen
oWindow = CreateUnoService("com.sun.star.awt.Toolkit")
odlg.createPeer(oWindow, null)
Dim oWindowsListener as Object
oWindowsListener = CreateUnoListener( "Win_", "com.sun.star.awt.XTopWindowListener" )
odlg.addTopWindowListener(oWindowsListener)
odlg.setVisible(True)
odoc = stardesktop.currentcomponent
ocontroller = odoc.currentcontroller
oSelectionChangeListener = createUnoListener("sel_", "com.sun.star.view.XSelectionChangeListener")
ocontroller.addSelectionChangeListener(oSelectionChangeListener)
End Sub
Sub S_Create_Dialog_MicroMove
   
Dim oWindow As Object
Dim oMod As Object
Dim i As Integer
if  dstep = 0 then dstep = 1
If  not isNull (odlg) then  
  if odlg.isVisible() Then
    odlg.setVisible(False)
    odlg.dispose
  end if
end if
'oSelectionChangeListener entfernen
  if Not ( isEmpty (oSelectionChangeListener) or  IsNull(oSelectionChangeListener)) then 
    ocontroller.removeSelectionChangeListener(oSelectionChangeListener)
    oSelectionChangeListener=Null
  end if
'Göße und position des objekts bestimmen(Globale Variablen füllen),
' und überprüfen, ob es ein Grafikobject ist.
if not get_size_and_pos () then
    msgbox ("Please select"+chr(13)+"→ shape"+chr(13)+"→ picture"+chr(13)+"→ frame"+chr(13)+"→ floating frame"+chr(13)+"→ control",64,"MMove")
    exit sub
End if
REM ***** Initialisierung der Eigenschaften des Dialogs
odlgModel = CreateUnoService("com.sun.star.awt.UnoControlDialogModel")
With odlgModel
.setPropertyValue("PositionX", 320)
.setPropertyValue("PositionY", 111 )
.setPropertyValue("FontName", Font)
.setPropertyValue("Width", 58)
.setPropertyValue("Height", 57)
.setPropertyValue("Title", "MicroMove")
.setPropertyValue("Name", "DLGMove")
.setPropertyValue("FontHeight",7)
'.setPropertyValue("DesktopAsParent", True )
End With
       
odlg = CreateUnoService("com.sun.star.awt.UnoControlDialog")
       
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
.setPropertyValue("Label", "X")
.setPropertyValue("Name", "lblSX")
.setPropertyValue("PositionX", 1)
.setPropertyValue("PositionY", 7)
.setPropertyValue("Height",11)
.setPropertyValue("Width", 6)
.setPropertyValue("FontHeight",6)
End With
odlgModel.insertByName("lblSX", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
.setPropertyValue("Label", "Y")
.setPropertyValue("Name", "lblSY")
.setPropertyValue("PositionX", 54)
.setPropertyValue("PositionY", 7)
.setPropertyValue("Height",11)
.setPropertyValue("Width", 6)
.setPropertyValue("FontHeight",6)
End With
odlgModel.insertByName("lblSY", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
.setPropertyValue("Label", "X")
.setPropertyValue("Name", "lblX")
.setPropertyValue("PositionX", 1)
.setPropertyValue("PositionY", 40)
.setPropertyValue("Height",11)
.setPropertyValue("Width", 6)
.setPropertyValue("FontHeight",6)
End With
odlgModel.insertByName("lblX", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
.setPropertyValue("Label", "Y")
.setPropertyValue("Name", "lblY")
.setPropertyValue("PositionX", 54)
.setPropertyValue("PositionY", 40)
.setPropertyValue("Height",11)
.setPropertyValue("Width", 6)
.setPropertyValue("FontHeight",6)
End With
odlgModel.insertByName("lblY", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
.setPropertyValue("Label", "Size")
.setPropertyValue("Name", "lblSize")
.setPropertyValue("PositionX", 6)
.setPropertyValue("PositionY", 0)
.setPropertyValue("Height",8)
.setPropertyValue("Width", 20)
.setPropertyValue("FontHeight",6)
End With       
odlgModel.insertByName("lblSize", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
.setPropertyValue("Label", "[mm]")
.setPropertyValue("Name", "lblSmm")
.setPropertyValue("PositionX", 42)
.setPropertyValue("PositionY", 0)
.setPropertyValue("Height",8)
.setPropertyValue("Width", 50)
.setPropertyValue("FontHeight",6)
End With       
odlgModel.insertByName("lblSmm", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
.setPropertyValue("Label", "Step")
.setPropertyValue("Name", "lblStep")
.setPropertyValue("PositionX", 19)
.setPropertyValue("PositionY", 15)
.setPropertyValue("Height",8)
.setPropertyValue("Width", 23)
.setPropertyValue("FontHeight",6)
End With       
odlgModel.insertByName("lblStep", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
.setPropertyValue("Label", "Position")
.setPropertyValue("Name", "lblPosition")
.setPropertyValue("PositionX", 6)
.setPropertyValue("PositionY", 33)
.setPropertyValue("Height",8)
.setPropertyValue("Width", 15)
.setPropertyValue("FontHeight",6)
End With       
odlgModel.insertByName("lblPosition", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
.setPropertyValue("Label", "[mm]")
.setPropertyValue("Name", "lblPmm")
.setPropertyValue("PositionX", 42)
.setPropertyValue("PositionY", 33)
.setPropertyValue("Height",8)
.setPropertyValue("Width", 50)
.setPropertyValue("FontHeight",6)
End With       
odlgModel.insertByName("lblPmm", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
.setPropertyValue("Label", "made by rikhustede.de")
.setPropertyValue("Name", "lblmadeby")
.setPropertyValue("PositionX", 12)
.setPropertyValue("PositionY", 50)
.setPropertyValue("Height",8)
.setPropertyValue("Width", 50)
.setPropertyValue("FontHeight",6)
End With       
odlgModel.insertByName("lblmadeby", oMod)
REM ********** Optionsbuttons erzeugen
dim s_buttons(3,4) as variant
s_buttons(0,1)="↑"
s_buttons(0,2)="→"
s_buttons(0,3)="↓"
s_buttons(0,4)="←"
s_buttons(1,1)=23
s_buttons(1,2)=40
s_buttons(1,3)=23
s_buttons(1,4)=6
  
s_buttons(2,1)=5
s_buttons(2,2)=22
s_buttons(2,3)=38
s_buttons(2,4)=22
s_buttons(3,1)="Y - 100"
s_buttons(3,2)="X + 100"
s_buttons(3,3)="Y + 100"
s_buttons(3,4)="X - 100"
       
for i=1 to 4
 oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlButtonModel")
 With oMod
 .setPropertyValue("Label", s_buttons(0,i))
 .setPropertyValue("Name", "cmd"+i)
 .setPropertyValue("PositionX", s_buttons(1,i))
 .setPropertyValue("PositionY", s_buttons(2,i))
 .setPropertyValue("Height", 12)
 .setPropertyValue("Width", 12)
 .setPropertyValue("Tag", s_buttons(3,i))
 .setPropertyValue("FontHeight",14)
 .setPropertyValue("FocusOnClick",false)
 .setPropertyValue("Tabstop",false)
 End With
 odlgModel.insertByName("cmd"+i, oMod)
next i
       
      
REM **********numerisches Feld erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlNumericFieldModel")
With oMod
.setPropertyValue("Name", "NumSX")
.setPropertyValue("PositionX", 6)
.setPropertyValue("PositionY", 6)
.setPropertyValue("Height", 10)
.setPropertyValue("Width", 15)
.setPropertyValue("Value", SX)
End With      
odlgModel.insertByName("NumSX", oMod)
REM **********numerisches Feld erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlNumericFieldModel")
With oMod
.setPropertyValue("Name", "NumSY")
.setPropertyValue("PositionX", 38)
.setPropertyValue("PositionY", 6)
.setPropertyValue("Height", 10)
.setPropertyValue("Width", 15)
.setPropertyValue("Value", SY)
End With      
odlgModel.insertByName("NumSY", oMod)
REM **********numerisches Feld erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlNumericFieldModel")
With oMod
.setPropertyValue("Name", "NumX")
.setPropertyValue("PositionX", 6)
.setPropertyValue("PositionY", 39)
.setPropertyValue("Height", 10)
.setPropertyValue("Width", 15)
.setPropertyValue("Value", X)
End With      
odlgModel.insertByName("NumX", oMod)
REM **********numerisches Feld erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlNumericFieldModel")
With oMod
.setPropertyValue("Name", "NumY")
.setPropertyValue("PositionX", 38)
.setPropertyValue("PositionY", 39)
.setPropertyValue("Height", 10)
.setPropertyValue("Width", 15)
.setPropertyValue("Value", Y)
End With      
odlgModel.insertByName("NumY", oMod)
REM **********numerisches Drehfeld erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlNumericFieldModel")
With oMod
.setPropertyValue("Name", "NumStep")
.setPropertyValue("PositionX", 19)
.setPropertyValue("PositionY", 21)
.setPropertyValue("Height", 10)
.setPropertyValue("Width", 21)
.setPropertyValue("Value", dStep)
.setPropertyValue("Spin", true)
.setPropertyValue("ValueMax",9)
.setPropertyValue("ValueMin",1)
End With  
odlgModel.insertByName("NumStep", oMod)
REM **********Checkbox erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlCheckBoxModel")
With oMod
.setPropertyValue("Name", "ChkStep")
.setPropertyValue("PositionX", 22)
.setPropertyValue("PositionY", 31)
.setPropertyValue("Height", 12)
.setPropertyValue("Width", 20)
.setPropertyValue("Label", "1/10")
.setPropertyValue("FontHeight",6)
End With
if bthenth = false then
 oMod.setPropertyValue("State", 0)
else
 oMod.setPropertyValue("State", 1)
endif
odlgModel.insertByName("ChkStep", oMod)
odlg.setModel(odlgModel)
          
oNumSX= odlg.getcontrol("NumSX")
oNumSY = odlg.getcontrol("NumSY")  
oNumX = odlg.getcontrol("NumX")
oNumY = odlg.getcontrol("NumY")
oNumStep=odlg.getcontrol("NumStep")
oChkStep = odlg.getcontrol("ChkStep")
oNumSX.DecimalDigits = 1
oNumSY.DecimalDigits = 1
oNumX.DecimalDigits = 1
oNumY.DecimalDigits = 1
Set_digits
       
REM ********** Listener für den Register erzeugen Button
ocmd_move_Listener = createUnoListener("cmd_move_", "com.sun.star.awt.XActionListener")
for i=1 to 4
oControl = odlg.getControl("cmd"+i)
oControl.addActionListener(ocmd_move_Listener)
next i
o_numS_focus_Listener = createUnoListener("numS_focus_", "com.sun.star.awt.XFocusListener")
oNumSX.addFocusListener(o_numS_focus_Listener)
oNumSY.addFocusListener(o_numS_focus_Listener)
o_num_focus_Listener = createUnoListener("num_focus_", "com.sun.star.awt.XFocusListener")
oNumX.addFocusListener(o_num_focus_Listener)
oNumY.addFocusListener(o_num_focus_Listener)
o_numS_key_Listener = createUnoListener("numS_key_", "com.sun.star.awt.XKeyListener")
oNumSX.addKeyListener(o_numS_key_Listener)
oNumSY.addKeyListener(o_numS_key_Listener)
o_num_key_Listener = createUnoListener("num_key_", "com.sun.star.awt.XKeyListener")
oNumX.addKeyListener(o_num_key_Listener)
oNumY.addKeyListener(o_num_key_Listener)
o_ChkStep_item_Listener = createUnoListener("chk_item_", "com.sun.star.awt.XItemListener")
oChkStep.addItemListener(o_ChkStep_item_Listener)
o_NumStep_text_Listener = createUnoListener("numstep_text_", "com.sun.star.awt.XTextListener")
oNumStep.addTextListener(o_NumStep_text_Listener)
       
REM ********** Mittels des Modells den Dialog anzeigen
oWindow = CreateUnoService("com.sun.star.awt.Toolkit")
odlg.createPeer(oWindow, null)
Dim oWindowsListener as Object
oWindowsListener = CreateUnoListener( "Win_", "com.sun.star.awt.XTopWindowListener" )
odlg.addTopWindowListener(oWindowsListener)
odlg.setVisible(True)'execute=true
oSelectionChangeListener = createUnoListener("sel_", "com.sun.star.view.XSelectionChangeListener")
ocontroller.addSelectionChangeListener(oSelectionChangeListener)
End Sub
sub moveshape(oEv)
dim sTag as string
'dim a()
dstep = odlg.getcontrol("NumStep").value
l= 100 * dstep
osel = Thiscomponent.currentselection
 a = split(oEv.Source.Model.Tag," ")
 if a(0) = "X" then
  if a(1) = "-" then
   dx = -l
  else
   dx = l
  endif
   dy = 0
 else
   dx = 0
   if a(1) = "-" then
    dy = -l
   else
    dy = l
   endif
 endif
if osel.supportsService("com.sun.star.drawing.ShapeCollection") then
 opos = osel(0).Position
 X = opos.X+dx
 y = opos.Y+dy
 opos.X = X
 opos.Y = Y
 osel(0).Position = opos
 oNumX.Text=runden(X/100)
 oNumY.Text=runden(Y/100)
else
 X = osel.HoriOrientPosition+dx
 Y = osel.VertOrientPosition+dy
 osel.HoriOrientPosition = X
 osel.VertOrientPosition = Y
 oNumX.Text=runden(X/100)
 oNumY.Text=runden(Y/100)
endif
thiscomponent.modified = true
end sub
Sub Set_step
oChkStep = odlg.getcontrol("ChkStep")
if oChkStep.state = 0 then
 bThenth = false
 set_digits
else
 bThenth = true
 set_digits
endif
sStep = replace(odlg.getcontrol("NumStep").Text,",",".")
dstep = sStep
odlg.getcontrol("NumStep").value = dstep
end sub
sub Set_digits
if bThenth = false then
  with oNumStep
    .DecimalDigits = 0
    .SpinSize = 1
    .model.ValueMax = 20
    .model.ValueMin = 1
  end with
else
  with oNumStep
    .DecimalDigits = 1
    .SpinSize = 0.1
    .model.ValueMax = 9.9
    .model.ValueMin = 0.1
  end with
endif
end Sub
Sub Set_Position
On Error Goto ErrorHandler
dim doX as Integer
dim doY as Integer
osel = Thiscomponent.currentselection
if osel.supportsService("com.sun.star.drawing.ShapeCollection") then
opos = osel(0).Position
doX = oNumX.Text
doX = doX*100
doY = oNumY.Text
doY = doY*100
opos.X = doX
opos.Y = doY
osel(0).Position = opos
else
doX = oNumX.Text
doX = doX*100
doY = oNumY.Text
doY = doY*100
osel.HoriOrientPosition = doX
osel.VertOrientPosition = doY
endif
ErrorHandler:
thiscomponent.modified = true
end sub
Sub Set_Size
On Error Goto ErrorHandler
dim SoX as Integer
dim SoY as Integer
osel = Thiscomponent.currentselection
if osel.supportsService("com.sun.star.drawing.ShapeCollection") then
oSize = osel(0).Size
SoX = oNumSX.Text
SoX = SoX*100
SoY = oNumSY.Text
SoY = SoY*100
oSize.Width = SoX
oSize.Height = SoY
osel(0).Size = oSize
else
oSize = osel.Size
SoX = oNumSX.Text
SoX = SoX*100
SoY = oNumSY.Text
SoY = SoY*100
oSize.Width = SoX
oSize.Height = SoY
osel.Size = oSize
endif
ErrorHandler:
thiscomponent.modified = true
end sub
Function runden(dblZahl as double, optional iStellen as integer) as double
' Funktion rundet eine Zahl (dblZahl) auf die angegebene Anzahl von Stellen (iStellen)
' Angabe der Stellenanzahl optional (Standard=0)
   dim dblTmp as double, lngTmp as Long
   iStellen = 1
   dblTmp = dblZahl * 10^iStellen
   lngTmp = CLng(dblTmp)
   dblTmp = CDbl(lngTmp) / 10^iStellen
   runden = dblTmp
end Function
REM ***** Die Aktion des Listeners für die Buttons
Sub cmd_move_actionPerformed(oEv)
moveshape(oEv)
end sub
    
Sub cmd_move_disposing(oEv)
End Sub
REM ***** Listeners für die NumericFields
Sub numS_focus_focusLost(oEv)
Set_Size
end sub
Sub numS_focus_focusGained(oEv)
end sub
    
Sub numS_focus_disposing(oEv)
End Sub
sub numS_key_keyPressed(oEv)
End Sub
sub numS_key_keyReleased(oEv)
If (oEv.KeyCode = 1280) Then Set_Size
End Sub
    
Sub numS_key_disposing(oEv)
End Sub
'-------------------------------------------------
Sub num_focus_focusLost(oEv)
Set_Position
end sub
Sub num_focus_focusGained(oEv)
end sub
    
Sub num_focus_disposing(oEv)
End Sub
 
sub num_key_keyPressed(oEv)
End Sub
sub num_key_keyReleased(oEv)
If (oEv.KeyCode = 1280) Then Set_Position
End Sub
    
Sub num_key_disposing(oEv)
End Sub
Sub chk_item_itemStateChanged (oEv)
Set_step
end sub
Sub chk_item_disposing(oEv)
end sub
sub numstep_text_textChanged
Set_step
end sub
sub numstep_text_disposing(oEv)
end sub
'Diese Routinen werden von dem XTopWindowListener benötigt
Sub Win_windowClosing( oEvent ) 'Dialog schließen
  odlg.setVisible(False)
  odlg.dispose
  if Not ( isEmpty (oSelectionChangeListener) or  IsNull(oSelectionChangeListener)) then 
    ocontroller.removeSelectionChangeListener(oSelectionChangeListener)
    oSelectionChangeListener=Null
  end if
End Sub 
Sub Win_disposing( ) 
End Sub 
Sub Win_windowOpened	( oEvent )
End sub 
Sub Win_windowClosed	( oEvent )
End sub  
Sub Win_windowMinimized	( oEvent )
End sub
Sub Win_windowNormalized	( oEvent )
End sub 
Sub Win_windowActivated	( oEvent )
End sub 
Sub Win_windowDeactivated ( oEvent )
End sub
'--------------------------------------
Function get_size_and_pos () as boolean
Dim osel as object
Dim opos as object
Dim oSize as object
osel = stardesktop.currentcomponent.currentselection
oPreviousSel=osel
if ismissing(osel) or not osel.supportsService("com.sun.star.drawing.ShapeCollection") then
  if not osel.supportsService("com.sun.star.text.BaseFrame") then
    get_size_and_pos=False
    exit function
  endif
endif
on Error goto errorhandler
if osel.supportsService("com.sun.star.drawing.ShapeCollection") then
	opos = osel(0).Position
	oSize = osel(0).Size
	SX=oSize.Width
	SY=oSize.Height
	X=opos.X
	Y=opos.Y
	
	X= runden(X/100)
	Y= runden(Y/100)
	SX= runden(SX/100)
	SY= runden(SY/100)
	opos.X = X*100
	opos.Y = Y*100
	oSize.Width = SX*100
	oSize.Height = SY*100
	'set position on 1mm grid
	osel(0).Position = opos
	
else
	X = osel.HoriOrientPosition
	Y = osel.VertOrientPosition
	oSize = osel.Size
	SX=oSize.Width
	SY=oSize.Height
	X= runden(X/100)
	Y= runden(Y/100)
	SX= runden(SX/100)
	SY= runden(SY/100)
	osel.HoriOrientPosition = X*100
	osel.VertOrientPosition = Y*100
	oSize.Width = SX*100
	oSize.Height = SY*100
endif
get_size_and_pos=True
Exit Function
errorhandler:
get_size_and_pos=False
end function
function Set_Numeric_Filds () as Boolean
if get_size_and_pos () Then
  oNumSX.Text= SX
  oNumSY.Text= SY
  oNumX.Text= X
  oNumY.Text= Y
  Set_Numeric_Filds = True
else
  Set_Numeric_Filds = False
end if
end function
sub sel_selectionChanged(ev)
osel = ev.source.Selection
if ismissing(osel) or not osel.supportsService("com.sun.star.drawing.ShapeCollection") then exit sub
Set_Numeric_Filds ()
end sub
Sub sel_disposing( ) 
End Sub
    
Gruß Frieder
 
			
			
							Hallo Rik
Ich habe es auch einmahl mit einem focus listener probiert, aber das Ergebnis ist nicht überzeugend.
versuche ich nun z.B. verschiedene Objekte in einem Dokument anzuklicken, so gelingt das nicht immer. 
Außerdem liegt bei deinem Code so einiges im Argen.
Du solltest dir angewöhnen Variablen auch zu deklarieren.
meine Erfahrung hat gezeigt, je mehr Listener man in einem Makro unterbringt, desto instabiler wird es.
um dein Tool stabiler und besser zu machen, würde ich noch einmahl  ganz von vorne anfangen.
Hier der Code:
[code]
REM  *****  BASIC  *****
Global oNumSX as object
Global oNumSY as object 
Global oNumX as object
Global oNumY as object
Global oNumStep as object
Global X as double
Global Y as double
Global SX as double
Global SY as double
Global odlg as object
Global l as double
global dstep as double
global bThenth as boolean
Global oPreviousSel as object
Global oSelectionChangeListener 
Global ocontroller
Sub S_Create_Dialog_MiniMove
   
Dim oWindow As Object
Dim oMod As Object
Dim i As Integer
if  dstep = 0 then dstep = 1
If  not isNull (odlg) then 
  if odlg.isVisible() Then
    odlg.setVisible(False)
    odlg.dispose
  end if
end if
'oSelectionChangeListener entfernen
  if Not ( isEmpty (oSelectionChangeListener) or  IsNull(oSelectionChangeListener)) then 
    ocontroller.removeSelectionChangeListener(oSelectionChangeListener)
    oSelectionChangeListener=Null
  end if
'Göße und position des objekts bestimmen(Globale Variablen füllen),
' und überprüfen, ob es ein Grafikobject ist.
if not get_size_and_pos () then
    msgbox ("Please select"+chr(13)+"→ shape"+chr(13)+"→ picture"+chr(13)+"→ frame"+chr(13)+"→ floating frame"+chr(13)+"→ control",64,"MMove")
    exit sub
End if
REM ***** Initialisierung der Eigenschaften des Dialogs
odlgModel = CreateUnoService("com.sun.star.awt.UnoControlDialogModel")
With odlgModel
	.setPropertyValue("PositionX", 320)
	.setPropertyValue("PositionY", 111 )
	.setPropertyValue("FontName", Font)
	.setPropertyValue("Width", 82)
	.setPropertyValue("Height", 76)
	.setPropertyValue("Title", "MiniMove")
	.setPropertyValue("Name", "DLGMove")
	'.setPropertyValue("DesktopAsParent", True )
End With
       
odlg = CreateUnoService("com.sun.star.awt.UnoControlDialog")
       
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
	.setPropertyValue("Label", "X")
	.setPropertyValue("Name", "lblSX")
	.setPropertyValue("PositionX", 2)
	.setPropertyValue("PositionY", 11)
	.setPropertyValue("Height",11)
	.setPropertyValue("Width", 6)
End With
odlgModel.insertByName("lblSX", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
	.setPropertyValue("Label", "Y")
	.setPropertyValue("Name", "lblSY")
	.setPropertyValue("PositionX", 76)
	.setPropertyValue("PositionY", 11)
	.setPropertyValue("Height",11)
	.setPropertyValue("Width", 6)
End With
odlgModel.insertByName("lblSY", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
	.setPropertyValue("Label", "X")
	.setPropertyValue("Name", "lblX")
	.setPropertyValue("PositionX", 2)
	.setPropertyValue("PositionY", 57)
	.setPropertyValue("Height",11)
	.setPropertyValue("Width", 6)
End With
odlgModel.insertByName("lblX", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
	.setPropertyValue("Label", "Y")
	.setPropertyValue("Name", "lblY")
	.setPropertyValue("PositionX", 76)
	.setPropertyValue("PositionY", 57)
	.setPropertyValue("Height",11)
	.setPropertyValue("Width", 6)
End With
odlgModel.insertByName("lblY", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
	.setPropertyValue("Label", "Size")
	.setPropertyValue("Name", "lblSize")
	.setPropertyValue("PositionX", 8)
	.setPropertyValue("PositionY", 4)
	.setPropertyValue("Height",8)
	.setPropertyValue("Width",20)
	.setPropertyValue("FontHeight",7)
End With       
odlgModel.insertByName("lblSize", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
	.setPropertyValue("Label", "[mm]")
	.setPropertyValue("Name", "lblSmm")
	.setPropertyValue("PositionX", 54)
	.setPropertyValue("PositionY", 4)
	.setPropertyValue("Height",8)
	.setPropertyValue("Width", 50)
	.setPropertyValue("FontHeight",6)
End With       
odlgModel.insertByName("lblSmm", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
	.setPropertyValue("Label", "Step")
	.setPropertyValue("Name", "lblStep")
	.setPropertyValue("PositionX", 31)
	.setPropertyValue("PositionY", 24)
	.setPropertyValue("Height",8)
	.setPropertyValue("Width", 23)
	.setPropertyValue("FontHeight",7)
End With       
odlgModel.insertByName("lblStep", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
	.setPropertyValue("Label", "Position")
	.setPropertyValue("Name", "lblPosition")
	.setPropertyValue("PositionX", 8)
	.setPropertyValue("PositionY", 50)
	.setPropertyValue("Height",8)
	.setPropertyValue("Width", 23)
	.setPropertyValue("FontHeight",7)
End With       
odlgModel.insertByName("lblPosition", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
	.setPropertyValue("Label", "[mm]")
	.setPropertyValue("Name", "lblPmm")
	.setPropertyValue("PositionX", 54)
	.setPropertyValue("PositionY", 50)
	.setPropertyValue("Height",8)
	.setPropertyValue("Width", 50)
	.setPropertyValue("FontHeight",6)
End With       
odlgModel.insertByName("lblPmm", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
	.setPropertyValue("Label", "made by rikhustede.de")
	.setPropertyValue("Name", "lblmadeby")
	.setPropertyValue("PositionX", 34)
	.setPropertyValue("PositionY", 70)
	.setPropertyValue("Height",8)
	.setPropertyValue("Width", 50)
	.setPropertyValue("FontHeight",6)
End With       
odlgModel.insertByName("lblmadeby", oMod)
REM ********** Optionsbuttons erzeugen
dim s_buttons(3,4) as variant
s_buttons(0,1)="↑"
s_buttons(0,2)="→"
s_buttons(0,3)="↓"
s_buttons(0,4)="←"
s_buttons(1,1)=31
s_buttons(1,2)=54
s_buttons(1,3)=31
s_buttons(1,4)=8
  
s_buttons(2,1)=4
s_buttons(2,2)=27
s_buttons(2,3)=50
s_buttons(2,4)=27
s_buttons(3,1)="Y - 100"
s_buttons(3,2)="X + 100"
s_buttons(3,3)="Y + 100"
s_buttons(3,4)="X - 100"
       
for i=1 to 4
 oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlButtonModel")
 With oMod
	 .setPropertyValue("Label", s_buttons(0,i))
	 .setPropertyValue("Name", "cmd"+i)
	 .setPropertyValue("PositionX", s_buttons(1,i))
	 .setPropertyValue("PositionY", s_buttons(2,i))
	 .setPropertyValue("Height", 20)
	 .setPropertyValue("Width", 20)
	 .setPropertyValue("Tag", s_buttons(3,i))
	 .setPropertyValue("FontHeight",18)
	 .setPropertyValue("FocusOnClick",false)
	 .setPropertyValue("Tabstop",false)
 End With
 odlgModel.insertByName("cmd"+i, oMod)
next i
       
      
REM **********numerisches Feld erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlNumericFieldModel")
With oMod
	.setPropertyValue("Name", "NumSX")
	.setPropertyValue("PositionX", 8)
	.setPropertyValue("PositionY", 10)
	.setPropertyValue("Height", 10)
	.setPropertyValue("Width", 20)
	.setPropertyValue("Value", SX)
End With      
odlgModel.insertByName("NumSX", oMod)
REM **********numerisches Feld erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlNumericFieldModel")
With oMod
	.setPropertyValue("Name", "NumSY")
	.setPropertyValue("PositionX", 54)
	.setPropertyValue("PositionY", 10)
	.setPropertyValue("Height", 10)
	.setPropertyValue("Width", 20)
	.setPropertyValue("Value", SY)
End With      
odlgModel.insertByName("NumSY", oMod)
REM **********numerisches Feld erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlNumericFieldModel")
With oMod
	.setPropertyValue("Name", "NumX")
	.setPropertyValue("PositionX", 8)
	.setPropertyValue("PositionY", 56)
	.setPropertyValue("Height", 10)
	.setPropertyValue("Width", 20)
	.setPropertyValue("Value", X)
End With      
odlgModel.insertByName("NumX", oMod)
REM **********numerisches Feld erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlNumericFieldModel")
With oMod
	.setPropertyValue("Name", "NumY")
	.setPropertyValue("PositionX", 54)
	.setPropertyValue("PositionY", 56)
	.setPropertyValue("Height", 10)
	.setPropertyValue("Width", 20)
	.setPropertyValue("Value", Y)
End With      
odlgModel.insertByName("NumY", oMod)
REM **********numerisches Drehfeld erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlNumericFieldModel")
With oMod
	.setPropertyValue("Name", "NumStep")
	.setPropertyValue("PositionX", 31)
	.setPropertyValue("PositionY", 30)
	.setPropertyValue("Height", 12)
	.setPropertyValue("Width", 20)
	.setPropertyValue("Value", dstep)
	.setPropertyValue("Spin", true)
	.setPropertyValue("ValueMax",20)
	.setPropertyValue("ValueMin",1)
End With  
odlgModel.insertByName("NumStep", oMod)
REM **********Checkbox erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlCheckBoxModel")
With oMod
	.setPropertyValue("Name", "ChkStep")
	.setPropertyValue("PositionX", 31)
	.setPropertyValue("PositionY", 42)
	.setPropertyValue("Height", 14)
	.setPropertyValue("Width", 20)
	.setPropertyValue("Label", "1/10")
	.setPropertyValue("FontHeight",7)
End With
if bthenth = false then
 oMod.setPropertyValue("State", 0)
else
 oMod.setPropertyValue("State", 1)
endif
odlgModel.insertByName("ChkStep", oMod)
odlg.setModel(odlgModel)
      
oNumSX= odlg.getcontrol("NumSX")
oNumSY = odlg.getcontrol("NumSY")  
oNumX = odlg.getcontrol("NumX")
oNumY = odlg.getcontrol("NumY")
oNumStep = odlg.getcontrol("NumStep")
oChkStep = odlg.getcontrol("ChkStep")
oNumSX.DecimalDigits = 1
oNumSY.DecimalDigits = 1
oNumX.DecimalDigits = 1
oNumY.DecimalDigits = 1
Set_digits
      
REM ********** Listener für den Register erzeugen Button
ocmd_move_Listener = createUnoListener("cmd_move_", "com.sun.star.awt.XActionListener")
for i=1 to 4
	oControl = odlg.getControl("cmd"+i)
	oControl.addActionListener(ocmd_move_Listener)
next i
o_numS_focus_Listener = createUnoListener("numS_focus_", "com.sun.star.awt.XFocusListener")
oNumSX.addFocusListener(o_numS_focus_Listener)
oNumSY.addFocusListener(o_numS_focus_Listener)
o_num_focus_Listener = createUnoListener("num_focus_", "com.sun.star.awt.XFocusListener")
oNumX.addFocusListener(o_num_focus_Listener)
oNumY.addFocusListener(o_num_focus_Listener)
o_numS_key_Listener = createUnoListener("numS_key_", "com.sun.star.awt.XKeyListener")
oNumSX.addKeyListener(o_numS_key_Listener)
oNumSY.addKeyListener(o_numS_key_Listener)
o_num_key_Listener = createUnoListener("num_key_", "com.sun.star.awt.XKeyListener")
oNumX.addKeyListener(o_num_key_Listener)
oNumY.addKeyListener(o_num_key_Listener)
o_ChkStep_item_Listener = createUnoListener("chk_item_", "com.sun.star.awt.XItemListener")
oChkStep.addItemListener(o_ChkStep_item_Listener)
o_NumStep_text_Listener = createUnoListener("numstep_text_", "com.sun.star.awt.XTextListener")
oNumStep.addTextListener(o_NumStep_text_Listener)
      
REM ********** Mittels des Modells den Dialog anzeigen
oWindow = CreateUnoService("com.sun.star.awt.Toolkit")
odlg.createPeer(oWindow, null)
Dim oWindowsListener as Object
oWindowsListener = CreateUnoListener( "Win_", "com.sun.star.awt.XTopWindowListener" )
odlg.addTopWindowListener(oWindowsListener)
odlg.setVisible(True)
odoc = stardesktop.currentcomponent
ocontroller = odoc.currentcontroller
oSelectionChangeListener = createUnoListener("sel_", "com.sun.star.view.XSelectionChangeListener")
ocontroller.addSelectionChangeListener(oSelectionChangeListener)
End Sub
Sub S_Create_Dialog_MicroMove
   
Dim oWindow As Object
Dim oMod As Object
Dim i As Integer
if  dstep = 0 then dstep = 1
If  not isNull (odlg) then  
  if odlg.isVisible() Then
    odlg.setVisible(False)
    odlg.dispose
  end if
end if
'oSelectionChangeListener entfernen
  if Not ( isEmpty (oSelectionChangeListener) or  IsNull(oSelectionChangeListener)) then 
    ocontroller.removeSelectionChangeListener(oSelectionChangeListener)
    oSelectionChangeListener=Null
  end if
'Göße und position des objekts bestimmen(Globale Variablen füllen),
' und überprüfen, ob es ein Grafikobject ist.
if not get_size_and_pos () then
    msgbox ("Please select"+chr(13)+"→ shape"+chr(13)+"→ picture"+chr(13)+"→ frame"+chr(13)+"→ floating frame"+chr(13)+"→ control",64,"MMove")
    exit sub
End if
REM ***** Initialisierung der Eigenschaften des Dialogs
odlgModel = CreateUnoService("com.sun.star.awt.UnoControlDialogModel")
With odlgModel
.setPropertyValue("PositionX", 320)
.setPropertyValue("PositionY", 111 )
.setPropertyValue("FontName", Font)
.setPropertyValue("Width", 58)
.setPropertyValue("Height", 57)
.setPropertyValue("Title", "MicroMove")
.setPropertyValue("Name", "DLGMove")
.setPropertyValue("FontHeight",7)
'.setPropertyValue("DesktopAsParent", True )
End With
       
odlg = CreateUnoService("com.sun.star.awt.UnoControlDialog")
       
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
.setPropertyValue("Label", "X")
.setPropertyValue("Name", "lblSX")
.setPropertyValue("PositionX", 1)
.setPropertyValue("PositionY", 7)
.setPropertyValue("Height",11)
.setPropertyValue("Width", 6)
.setPropertyValue("FontHeight",6)
End With
odlgModel.insertByName("lblSX", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
.setPropertyValue("Label", "Y")
.setPropertyValue("Name", "lblSY")
.setPropertyValue("PositionX", 54)
.setPropertyValue("PositionY", 7)
.setPropertyValue("Height",11)
.setPropertyValue("Width", 6)
.setPropertyValue("FontHeight",6)
End With
odlgModel.insertByName("lblSY", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
.setPropertyValue("Label", "X")
.setPropertyValue("Name", "lblX")
.setPropertyValue("PositionX", 1)
.setPropertyValue("PositionY", 40)
.setPropertyValue("Height",11)
.setPropertyValue("Width", 6)
.setPropertyValue("FontHeight",6)
End With
odlgModel.insertByName("lblX", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
.setPropertyValue("Label", "Y")
.setPropertyValue("Name", "lblY")
.setPropertyValue("PositionX", 54)
.setPropertyValue("PositionY", 40)
.setPropertyValue("Height",11)
.setPropertyValue("Width", 6)
.setPropertyValue("FontHeight",6)
End With
odlgModel.insertByName("lblY", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
.setPropertyValue("Label", "Size")
.setPropertyValue("Name", "lblSize")
.setPropertyValue("PositionX", 6)
.setPropertyValue("PositionY", 0)
.setPropertyValue("Height",8)
.setPropertyValue("Width", 20)
.setPropertyValue("FontHeight",6)
End With       
odlgModel.insertByName("lblSize", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
.setPropertyValue("Label", "[mm]")
.setPropertyValue("Name", "lblSmm")
.setPropertyValue("PositionX", 42)
.setPropertyValue("PositionY", 0)
.setPropertyValue("Height",8)
.setPropertyValue("Width", 50)
.setPropertyValue("FontHeight",6)
End With       
odlgModel.insertByName("lblSmm", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
.setPropertyValue("Label", "Step")
.setPropertyValue("Name", "lblStep")
.setPropertyValue("PositionX", 19)
.setPropertyValue("PositionY", 15)
.setPropertyValue("Height",8)
.setPropertyValue("Width", 23)
.setPropertyValue("FontHeight",6)
End With       
odlgModel.insertByName("lblStep", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
.setPropertyValue("Label", "Position")
.setPropertyValue("Name", "lblPosition")
.setPropertyValue("PositionX", 6)
.setPropertyValue("PositionY", 33)
.setPropertyValue("Height",8)
.setPropertyValue("Width", 15)
.setPropertyValue("FontHeight",6)
End With       
odlgModel.insertByName("lblPosition", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
.setPropertyValue("Label", "[mm]")
.setPropertyValue("Name", "lblPmm")
.setPropertyValue("PositionX", 42)
.setPropertyValue("PositionY", 33)
.setPropertyValue("Height",8)
.setPropertyValue("Width", 50)
.setPropertyValue("FontHeight",6)
End With       
odlgModel.insertByName("lblPmm", oMod)
REM ********** Textlabel erzeugen
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
With oMod
.setPropertyValue("Label", "made by rikhustede.de")
.setPropertyValue("Name", "lblmadeby")
.setPropertyValue("PositionX", 12)
.setPropertyValue("PositionY", 50)
.setPropertyValue("Height",8)
.setPropertyValue("Width", 50)
.setPropertyValue("FontHeight",6)
End With       
odlgModel.insertByName("lblmadeby", oMod)
REM ********** Optionsbuttons erzeugen
dim s_buttons(3,4) as variant
s_buttons(0,1)="↑"
s_buttons(0,2)="→"
s_buttons(0,3)="↓"
s_buttons(0,4)="←"
s_buttons(1,1)=23
s_buttons(1,2)=40
s_buttons(1,3)=23
s_buttons(1,4)=6
  
s_buttons(2,1)=5
s_buttons(2,2)=22
s_buttons(2,3)=38
s_buttons(2,4)=22
s_buttons(3,1)="Y - 100"
s_buttons(3,2)="X + 100"
s_buttons(3,3)="Y + 100"
s_buttons(3,4)="X - 100"
       
for i=1 to 4
 oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlButtonModel")
 With oMod
 .setPropertyValue("Label", s_buttons(0,i))
 .setPropertyValue("Name", "cmd"+i)
 .setPropertyValue("PositionX", s_buttons(1,i))
 .setPropertyValue("PositionY", s_buttons(2,i))
 .setPropertyValue("Height", 12)
 .setPropertyValue("Width", 12)
 .setPropertyValue("Tag", s_buttons(3,i))
 .setPropertyValue("FontHeight",14)
 .setPropertyValue("FocusOnClick",false)
 .setPropertyValue("Tabstop",false)
 End With
 odlgModel.insertByName("cmd"+i, oMod)
next i
       
      
REM **********numerisches Feld erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlNumericFieldModel")
With oMod
.setPropertyValue("Name", "NumSX")
.setPropertyValue("PositionX", 6)
.setPropertyValue("PositionY", 6)
.setPropertyValue("Height", 10)
.setPropertyValue("Width", 15)
.setPropertyValue("Value", SX)
End With      
odlgModel.insertByName("NumSX", oMod)
REM **********numerisches Feld erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlNumericFieldModel")
With oMod
.setPropertyValue("Name", "NumSY")
.setPropertyValue("PositionX", 38)
.setPropertyValue("PositionY", 6)
.setPropertyValue("Height", 10)
.setPropertyValue("Width", 15)
.setPropertyValue("Value", SY)
End With      
odlgModel.insertByName("NumSY", oMod)
REM **********numerisches Feld erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlNumericFieldModel")
With oMod
.setPropertyValue("Name", "NumX")
.setPropertyValue("PositionX", 6)
.setPropertyValue("PositionY", 39)
.setPropertyValue("Height", 10)
.setPropertyValue("Width", 15)
.setPropertyValue("Value", X)
End With      
odlgModel.insertByName("NumX", oMod)
REM **********numerisches Feld erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlNumericFieldModel")
With oMod
.setPropertyValue("Name", "NumY")
.setPropertyValue("PositionX", 38)
.setPropertyValue("PositionY", 39)
.setPropertyValue("Height", 10)
.setPropertyValue("Width", 15)
.setPropertyValue("Value", Y)
End With      
odlgModel.insertByName("NumY", oMod)
REM **********numerisches Drehfeld erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlNumericFieldModel")
With oMod
.setPropertyValue("Name", "NumStep")
.setPropertyValue("PositionX", 19)
.setPropertyValue("PositionY", 21)
.setPropertyValue("Height", 10)
.setPropertyValue("Width", 21)
.setPropertyValue("Value", dStep)
.setPropertyValue("Spin", true)
.setPropertyValue("ValueMax",9)
.setPropertyValue("ValueMin",1)
End With  
odlgModel.insertByName("NumStep", oMod)
REM **********Checkbox erzeugen       
oMod = odlgModel.createInstance("com.sun.star.awt.UnoControlCheckBoxModel")
With oMod
.setPropertyValue("Name", "ChkStep")
.setPropertyValue("PositionX", 22)
.setPropertyValue("PositionY", 31)
.setPropertyValue("Height", 12)
.setPropertyValue("Width", 20)
.setPropertyValue("Label", "1/10")
.setPropertyValue("FontHeight",6)
End With
if bthenth = false then
 oMod.setPropertyValue("State", 0)
else
 oMod.setPropertyValue("State", 1)
endif
odlgModel.insertByName("ChkStep", oMod)
odlg.setModel(odlgModel)
          
oNumSX= odlg.getcontrol("NumSX")
oNumSY = odlg.getcontrol("NumSY")  
oNumX = odlg.getcontrol("NumX")
oNumY = odlg.getcontrol("NumY")
oNumStep=odlg.getcontrol("NumStep")
oChkStep = odlg.getcontrol("ChkStep")
oNumSX.DecimalDigits = 1
oNumSY.DecimalDigits = 1
oNumX.DecimalDigits = 1
oNumY.DecimalDigits = 1
Set_digits
       
REM ********** Listener für den Register erzeugen Button
ocmd_move_Listener = createUnoListener("cmd_move_", "com.sun.star.awt.XActionListener")
for i=1 to 4
oControl = odlg.getControl("cmd"+i)
oControl.addActionListener(ocmd_move_Listener)
next i
o_numS_focus_Listener = createUnoListener("numS_focus_", "com.sun.star.awt.XFocusListener")
oNumSX.addFocusListener(o_numS_focus_Listener)
oNumSY.addFocusListener(o_numS_focus_Listener)
o_num_focus_Listener = createUnoListener("num_focus_", "com.sun.star.awt.XFocusListener")
oNumX.addFocusListener(o_num_focus_Listener)
oNumY.addFocusListener(o_num_focus_Listener)
o_numS_key_Listener = createUnoListener("numS_key_", "com.sun.star.awt.XKeyListener")
oNumSX.addKeyListener(o_numS_key_Listener)
oNumSY.addKeyListener(o_numS_key_Listener)
o_num_key_Listener = createUnoListener("num_key_", "com.sun.star.awt.XKeyListener")
oNumX.addKeyListener(o_num_key_Listener)
oNumY.addKeyListener(o_num_key_Listener)
o_ChkStep_item_Listener = createUnoListener("chk_item_", "com.sun.star.awt.XItemListener")
oChkStep.addItemListener(o_ChkStep_item_Listener)
o_NumStep_text_Listener = createUnoListener("numstep_text_", "com.sun.star.awt.XTextListener")
oNumStep.addTextListener(o_NumStep_text_Listener)
       
REM ********** Mittels des Modells den Dialog anzeigen
oWindow = CreateUnoService("com.sun.star.awt.Toolkit")
odlg.createPeer(oWindow, null)
Dim oWindowsListener as Object
oWindowsListener = CreateUnoListener( "Win_", "com.sun.star.awt.XTopWindowListener" )
odlg.addTopWindowListener(oWindowsListener)
odlg.setVisible(True)'execute=true
oSelectionChangeListener = createUnoListener("sel_", "com.sun.star.view.XSelectionChangeListener")
ocontroller.addSelectionChangeListener(oSelectionChangeListener)
End Sub
sub moveshape(oEv)
dim sTag as string
'dim a()
dstep = odlg.getcontrol("NumStep").value
l= 100 * dstep
osel = Thiscomponent.currentselection
 a = split(oEv.Source.Model.Tag," ")
 if a(0) = "X" then
  if a(1) = "-" then
   dx = -l
  else
   dx = l
  endif
   dy = 0
 else
   dx = 0
   if a(1) = "-" then
    dy = -l
   else
    dy = l
   endif
 endif
if osel.supportsService("com.sun.star.drawing.ShapeCollection") then
 opos = osel(0).Position
 X = opos.X+dx
 y = opos.Y+dy
 opos.X = X
 opos.Y = Y
 osel(0).Position = opos
 oNumX.Text=runden(X/100)
 oNumY.Text=runden(Y/100)
else
 X = osel.HoriOrientPosition+dx
 Y = osel.VertOrientPosition+dy
 osel.HoriOrientPosition = X
 osel.VertOrientPosition = Y
 oNumX.Text=runden(X/100)
 oNumY.Text=runden(Y/100)
endif
thiscomponent.modified = true
end sub
Sub Set_step
oChkStep = odlg.getcontrol("ChkStep")
if oChkStep.state = 0 then
 bThenth = false
 set_digits
else
 bThenth = true
 set_digits
endif
sStep = replace(odlg.getcontrol("NumStep").Text,",",".")
dstep = sStep
odlg.getcontrol("NumStep").value = dstep
end sub
sub Set_digits
if bThenth = false then
  with oNumStep
    .DecimalDigits = 0
    .SpinSize = 1
    .model.ValueMax = 20
    .model.ValueMin = 1
  end with
else
  with oNumStep
    .DecimalDigits = 1
    .SpinSize = 0.1
    .model.ValueMax = 9.9
    .model.ValueMin = 0.1
  end with
endif
end Sub
Sub Set_Position
On Error Goto ErrorHandler
dim doX as Integer
dim doY as Integer
osel = Thiscomponent.currentselection
if osel.supportsService("com.sun.star.drawing.ShapeCollection") then
opos = osel(0).Position
doX = oNumX.Text
doX = doX*100
doY = oNumY.Text
doY = doY*100
opos.X = doX
opos.Y = doY
osel(0).Position = opos
else
doX = oNumX.Text
doX = doX*100
doY = oNumY.Text
doY = doY*100
osel.HoriOrientPosition = doX
osel.VertOrientPosition = doY
endif
ErrorHandler:
thiscomponent.modified = true
end sub
Sub Set_Size
On Error Goto ErrorHandler
dim SoX as Integer
dim SoY as Integer
osel = Thiscomponent.currentselection
if osel.supportsService("com.sun.star.drawing.ShapeCollection") then
oSize = osel(0).Size
SoX = oNumSX.Text
SoX = SoX*100
SoY = oNumSY.Text
SoY = SoY*100
oSize.Width = SoX
oSize.Height = SoY
osel(0).Size = oSize
else
oSize = osel.Size
SoX = oNumSX.Text
SoX = SoX*100
SoY = oNumSY.Text
SoY = SoY*100
oSize.Width = SoX
oSize.Height = SoY
osel.Size = oSize
endif
ErrorHandler:
thiscomponent.modified = true
end sub
Function runden(dblZahl as double, optional iStellen as integer) as double
' Funktion rundet eine Zahl (dblZahl) auf die angegebene Anzahl von Stellen (iStellen)
' Angabe der Stellenanzahl optional (Standard=0)
   dim dblTmp as double, lngTmp as Long
   iStellen = 1
   dblTmp = dblZahl * 10^iStellen
   lngTmp = CLng(dblTmp)
   dblTmp = CDbl(lngTmp) / 10^iStellen
   runden = dblTmp
end Function
REM ***** Die Aktion des Listeners für die Buttons
Sub cmd_move_actionPerformed(oEv)
moveshape(oEv)
end sub
    
Sub cmd_move_disposing(oEv)
End Sub
REM ***** Listeners für die NumericFields
Sub numS_focus_focusLost(oEv)
Set_Size
end sub
Sub numS_focus_focusGained(oEv)
end sub
    
Sub numS_focus_disposing(oEv)
End Sub
sub numS_key_keyPressed(oEv)
End Sub
sub numS_key_keyReleased(oEv)
If (oEv.KeyCode = 1280) Then Set_Size
End Sub
    
Sub numS_key_disposing(oEv)
End Sub
'-------------------------------------------------
Sub num_focus_focusLost(oEv)
Set_Position
end sub
Sub num_focus_focusGained(oEv)
end sub
    
Sub num_focus_disposing(oEv)
End Sub
 
sub num_key_keyPressed(oEv)
End Sub
sub num_key_keyReleased(oEv)
If (oEv.KeyCode = 1280) Then Set_Position
End Sub
    
Sub num_key_disposing(oEv)
End Sub
Sub chk_item_itemStateChanged (oEv)
Set_step
end sub
Sub chk_item_disposing(oEv)
end sub
sub numstep_text_textChanged
Set_step
end sub
sub numstep_text_disposing(oEv)
end sub
'Diese Routinen werden von dem XTopWindowListener benötigt
Sub Win_windowClosing( oEvent ) 'Dialog schließen
  odlg.setVisible(False)
  odlg.dispose
  if Not ( isEmpty (oSelectionChangeListener) or  IsNull(oSelectionChangeListener)) then 
    ocontroller.removeSelectionChangeListener(oSelectionChangeListener)
    oSelectionChangeListener=Null
  end if
End Sub 
Sub Win_disposing( ) 
End Sub 
Sub Win_windowOpened	( oEvent )
End sub 
Sub Win_windowClosed	( oEvent )
End sub  
Sub Win_windowMinimized	( oEvent )
End sub
Sub Win_windowNormalized	( oEvent )
End sub 
Sub Win_windowActivated	( oEvent )
End sub 
Sub Win_windowDeactivated ( oEvent )
End sub
'--------------------------------------
Function get_size_and_pos () as boolean
Dim osel as object
Dim opos as object
Dim oSize as object
osel = stardesktop.currentcomponent.currentselection
oPreviousSel=osel
if ismissing(osel) or not osel.supportsService("com.sun.star.drawing.ShapeCollection") then
  if not osel.supportsService("com.sun.star.text.BaseFrame") then
    get_size_and_pos=False
    exit function
  endif
endif
on Error goto errorhandler
if osel.supportsService("com.sun.star.drawing.ShapeCollection") then
	opos = osel(0).Position
	oSize = osel(0).Size
	SX=oSize.Width
	SY=oSize.Height
	X=opos.X
	Y=opos.Y
	
	X= runden(X/100)
	Y= runden(Y/100)
	SX= runden(SX/100)
	SY= runden(SY/100)
	opos.X = X*100
	opos.Y = Y*100
	oSize.Width = SX*100
	oSize.Height = SY*100
	'set position on 1mm grid
	osel(0).Position = opos
	
else
	X = osel.HoriOrientPosition
	Y = osel.VertOrientPosition
	oSize = osel.Size
	SX=oSize.Width
	SY=oSize.Height
	X= runden(X/100)
	Y= runden(Y/100)
	SX= runden(SX/100)
	SY= runden(SY/100)
	osel.HoriOrientPosition = X*100
	osel.VertOrientPosition = Y*100
	oSize.Width = SX*100
	oSize.Height = SY*100
endif
get_size_and_pos=True
Exit Function
errorhandler:
get_size_and_pos=False
end function
function Set_Numeric_Filds () as Boolean
if get_size_and_pos () Then
  oNumSX.Text= SX
  oNumSY.Text= SY
  oNumX.Text= X
  oNumY.Text= Y
  Set_Numeric_Filds = True
else
  Set_Numeric_Filds = False
end if
end function
sub sel_selectionChanged(ev)
osel = ev.source.Selection
if ismissing(osel) or not osel.supportsService("com.sun.star.drawing.ShapeCollection") then exit sub
Set_Numeric_Filds ()
end sub
Sub sel_disposing( ) 
End Sub
    [/code]
Gruß Frieder