How to increase height when it's textwrap.
private void creattextbox_Click(object sender, RoutedEventArgs e)
{
var txt = new TextBox();
txt.Height = 90;
txt.Width = 470;
txt.TextWrapping = TextWrapping.Wrap;
GR_Img.Children.Add(txt);
}
It is not clear which height you referred. If it is height of the TextBox that you want to increase when text wrapping, then avoid hardcoding Height property. Remove this line :
txt.Height = 90;
But if you meant to increase height of each text line, in other words increasing space between lines of TextBox's Text, then simply set LineHeight property to desired value :
txt.LineHeight= 50;
Related
I have an Image for drawing my background that I add to the stage. For some reason, there is a small space on the bottom - it's not laid out correctly
See attached image. I draw the background yellow to make it more visible. Why doesn't expand the background all the way to the bottom?
#Override
public void show() {
cam = new OrthographicCamera(Helper.RESOLUTION_WIDTH, Helper.RESOLUTION_HEIGHT);
cam.position.set(Helper.RESOLUTION_WIDTH / 2, Helper.RESOLUTION_HEIGHT / 2, 0);
stage = new Stage(Helper.RESOLUTION_WIDTH, Helper.RESOLUTION_HEIGHT, true);
stage.setCamera(cam); // !IMPORTANT
Image img = new Image(Assets.background);
img.setFillParent(true);
img.setSize(Helper.RESOLUTION_WIDTH, Helper.RESOLUTION_HEIGHT);
stage.addActor(img);
Table table = new Table(skin);
table.debug();
table.setBounds(0, 0, Helper.RESOLUTION_WIDTH, Helper.RESOLUTION_HEIGHT);
table.setFillParent(true);
/* add all the menu items to table */
stage.addActor(table);
}
RESOLUTION_WIDTH = 800
RESOLUTION_HEIGHT = 1280;
I figured out why it would draw that border:
I completely overlooked, that I implemented the resize method and did something weird with the zoom.
cam.viewportHeight = height; //set the viewport
cam.viewportWidth = width;
if (Helper.RESOLUTION_WIDTH / cam.viewportWidth < Helper.RESOLUTION_HEIGHT / cam.viewportHeight)
{
//set the right zoom direct
cam.zoom = Helper.RESOLUTION_HEIGHT / cam.viewportHeight;
} else {
//set the right zoom direct
cam.zoom = Helper.RESOLUTION_WIDTH / cam.viewportWidth;
}
cam.update();
Leaving the resize function to its default implementation fixed the problem.
Thanks, Pranav008 for all the help though!
I have dynamically created a bunch of textfields, the number of which depends on xml input. The textfields need to be button-enabled, so I thought the easiest solution is to put them in a movieclip and buttonMode that movieclip.
The hierarchy looks like this: main (extends MovieClip) -> klankoefening (a MovieClip) -> Textfieldparent (a MovieClip) -> Textfield
I have a variable maxw which contains the biggest textfield's width and I want all my Textfieldparents to have this width.
I'm trying to do it like this:
//generate textfields
keuzes = new XMLList(lijstOpties.categorie.(#cat == catname));
var nrs:int = keuzes.keuze.length(); //aantal keuzemogelijkheden
var maxw:int = 0; //grootste breedte tf, nodig voor bepalen breedte knoppen
for (var nr:int = 0; nr < nrs; nr++) {
var tf:TextField = createTextfield(werkfmt);
tf.text = keuzes.keuze[nr].toString();
tf.autoSize = "center";
tf.background = true;
tf.backgroundColor = 0xffcc33;
tf.border = true;
tf.borderColor = 0x000000;
tf.name = "keuzetf";
tf.selectable = false;
tf.x = 0;
tf.y = 0;
if (tf.width > maxw) {maxw = tf.width;}
var tfcontainer:MovieClip = new MovieClip();
tfcontainer.buttonMode = true;
tfcontainer.name = keuzes.keuze[nr].toString();
tfcontainer.addChild(tf);
klankoefening.addChildAt(tfcontainer,nr);
}
for (var an:int = 0; an < 3; an++) {
var mcs:MovieClip = klankoefening.getChildAt(an) as MovieClip;
mcs.width = maxw;
trace ("mcs " + mcs.width);
var mtf:TextField = mcs.getChildAt(0) as TextField;
trace ("mtf " + mtf.text);
}
the trace results are
mcs 32.05
mcs 33
mcs 21.25
Which I find odd, because I stated in my second loop that the width for all Textfieldparents should be set to maxw. What is happening?
Consider drawing an underlaying Rectangle of desired width and height. You can use mcs.graphics to do that. The trick is, width of a DisplayObjectContainer is a calculated property, and changing it will likely result in changing scale. Say, a MC has two shapes as chilren, one at (1000,0) and another at (0,0), and both have width of 10 - the resultant width of that MC will be 1010. So, instead of changing width, simulate its change by drawing a rectangle on the MC.
mcs.graphics.clear();
mcs.graphics.lineStyle(0,0,0);
mcs.graphics.beginFill(0x808080,0); // bogus filled rect, to capture events
mcs.graphics.drawRect(0,0,maxw,maxh); // height is needed too
mcs.graphics.endFill();
After thinking a bit more about your problem, I think your issue is that the buttons you're adding the text to have a width entirely defined by the TextField, and because you're set the text to autoSize, it's snapping back to it's original width.
What you will need to do to make the width more indicative of what you need, and allow for easy clicking on the buttons is to create a transparent rectangle in the tfContainer mc, set the width of the tfContainer, and then add the text to the button.
I want to add border around TextBlock programatically in Windows Store Application.
How can I do this?
Thanks.
Create new project and add this code in OnNavigatedTo event.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var tb = new TextBlock()
{
Text = "...TextBlock with border...",
FontSize = 20
};
//To get actual height and width of TextBlock
tb.Arrange(new Rect(0, 0, Window.Current.Bounds.Width, Window.Current.Bounds.Height));
tb.Measure(new Size(Window.Current.Bounds.Width, Window.Current.Bounds.Height));
var border = new Border()
{
BorderThickness = new Thickness(3),
BorderBrush = new SolidColorBrush(Windows.UI.Colors.Red),
Height = tb.ActualHeight + 10,
Width = tb.ActualWidth + 10
};
var rootGrid = (Grid)(((Page)this).Content);
rootGrid.Children.Add(border);
border.Child = tb;
}
I want to set width and height of the stage during resize of that swf..
I do it in resize event handling..but doesn't work..any other way to achieve this?
stage.addEventListener (Event.RESIZE, resizeListener);
function resizeListener (e:Event):void {
stage.stageWidth=500;
stage.stageHeight=300;
}
Thanks
by the sounds of it you just need
stage.align = "";
stage.scaleMode = StageScaleMode.NO_SCALE;
this will keep the content the same size no matter how much you stretch the window
Updated:
you need is to compare the ratios of the width and height scales of the content and the target. To make the loaded image fit within the area, scaling so that everything is inside you can do something like this:
var scale:Number = Math.min( _holder.width / _loader.content.width,
_holder.height / _loader.content.height );
_loader.content.scaleX = _loader.content.scaleY = scale;
This will make sure that you can see everything. If you change Math.min to Math.max, you will get a different result if the dimensions don't match.
public function loaderComplete(event:Event):void
{
var content:MovieClip = MovieClip(event.currentTarget.content );
//the dimensions of the external SWF
var _width:int = content.width;
var _height:int = content.height;
// you have several options here , assuming you have a container Sprite
// you can directly set to the dimensions of your container, if any
if( container.width < _width )
_width = container.width // and do the same for height
// or you could scale your content to fit , here's a simple version
// but you can check the height too or keep checking both value
// until it fits
if( container.width < _width )
{
var scale:Number = container.width / _width;
content.scaleX = content.scaleY = scale;
}
}
This answer gives better understanding of previous code given by swati singh.See this link
How to resize an external SWF to fit into a container?
Thanks to all
In a card game I use a TextField in the middle to display the playing table number, but also to detect if a playing card has been played - using myTextField.hitTestObject(myCard) - which means the TextField's position and dimensions may not change:
My current AS3 code is:
var format:TextFormat = new TextFormat();
format.color = 0xFFFFFF;
format.size = 30;
format.bold = true;
myTextField.defaultTextFormat = format;
myTextField.border = true;
myTextField.borderColor = 0xFFFFFF;
myTextField.x = W/2-Card.W/2;
myTextField.y = Card.H;
myTextField.width = Card.W;
myTextField.height = Card.H/4;
addChild(myTextField);
However the TextField's content (the String "#2029" in the above screenshot) is not in the center of it.
I can not set _middle.autoSize = TextFieldAutoSize.CENTER because this changes the width of the border and breaks hitTestObject().
Is there another way to align the text in the middle please?
Set the align property of TextFormat.
format.align = TextFormatAlign.CENTER;