Creating textbox dynamically.
Posted: 16 Jan 2014, 00:16
I am trying to create textbox dynamically and also keep updating its values. Is there any way to add textbox to root ? Thanks.
Welcome to our official discussion site. You’ll find topics on features, bugs, development, and general support here
https://www.noesisengine.com/forums/
using System;
using Noesis;
// Attached next to the NoesisGUIPanel component
public class Test: MonoBehavior
{
void Start()
{
// create TextBox
var tb = new TextBox();
// you can specify an initial text
tb.SetText("Type here...");
// and some layout properties
tb.SetHorizontalAlignment(HorizontalAlignment.Center);
tb.SetVerticalAlignment(VerticalAlignment.Center);
tb.SetWidth(200.0f);
// get root (supposing it is a Grid element)
var gui = GetComponent<NoesisGUIPanel>();
var root = gui.GetRoot<Grid>();
// add TextBox to the root
root.GetChildren().Add(tb);
}
}
#include <NsGui/TextBox.h>
#include <NsGui/Grid.h>
#include <NsGui/UIElementCollection.h>
using Noesis;
using Noesis::Core;
using Noesis::Gui;
void AddTextBox(FrameworkElement* root)
{
// create TextBox
Ptr<TextBox> tb = *new TextBox();
// you can specify an initial text
tb->SetText("Type here...");
// and some layout properties
tb->SetHorizontalAlignment(HorizontalAlignment_Center);
tb->SetVerticalAlignment(VerticalAlignment_Center);
tb->SetWidth(200.0f);
// get root (supposing it is a Grid element)
Grid* grid = NsDynamicCast<Grid*>(root);
// add TextBox to the root
grid->GetChildren()->Add(tb.GetPtr());
}