Macros/Base/ba003

    From The Document Foundation Wiki
    < Macros‎ | Base
    This page contains changes which are not marked for translation.


    Description

    Add control (TextBox) in runtime a form.

    Import, you need execute this code from a form, always.

    Basic code

    Sub create_text_box()
    Dim pos As New com.sun.star.awt.Point
    Dim size As New com.sun.star.awt.Size
    
    	doc = ThisComponent
    	draw_page = doc.DrawPage
    	form = draw_page.Forms.getByName("MainForm")
    	
    	new_text_box = doc.createInstance("com.sun.star.drawing.ControlShape")
    	
    	pos.X = 1000
    	pos.Y = 5000
    	new_text_box.setPosition(pos)
    	
    	size.Width = 10000
    	size.Height = 800
    	new_text_box.setSize(size)
    		
    	text_box_model = doc.createInstance("com.sun.star.form.component.TextField")
    	text_box_model.Name = "txt_new_text_box"
    	new_text_box.Control = text_box_model
    	
    	form.insertByIndex(0, text_box_model)
    	
    	draw_page.add(new_text_box)
    	
    End Sub

    Return to Macros/Base