Beyond_Beyaan.BBTextBox.SetText C# (CSharp) Метод

SetText() публичный Метод

public SetText ( string text ) : void
text string
Результат void
        public void SetText(string text)
        {
            lock (_lockObject)
            {
                Text = text;
                if (string.IsNullOrEmpty(text))
                {
                    text = " "; //Blank so it don't crash with 0 width
                }
                _textSprite.Text = text;
                if (_allowScrollbar)
                {
                    _textScrollBar.TopIndex = 0;
                    if (_wrapText)
                    {
                        if (_textSprite.Height > Height)
                        {
                            _scrollbarVisible = true;
                            _textScrollBar.SetAmountOfItems((int) _textSprite.Height);
                        }
                        else
                        {
                            if (_textSprite.Width < _maxWidth)
                            {
                                Width = (int) _textSprite.Width;
                            }
                            else
                            {
                                Width = _maxWidth;
                            }
                            _scrollbarVisible = false;
                        }
                    }
                    else
                    {
                        if (_textSprite.Width > _maxWidth)
                        {
                            _scrollbarVisible = true;
                            _textScrollBar.SetAmountOfItems((int) _textSprite.Width);
                            _textScrollBar.MoveTo(_x, (int) (_y + _textSprite.Height));
                        }
                        else
                        {
                            _scrollbarVisible = false;
                        }
                    }
                }
                else
                {
                    //Expand the size to the actual text sprite's size
                    if (_wrapText)
                    {
                        Height = (int) _textSprite.Height;
                        if (_textSprite.Width < _maxWidth)
                        {
                            Width = (int) _textSprite.Width;
                        }
                        else
                        {
                            Width = _maxWidth;
                        }
                        _target.Height = Height;
                    }
                    else
                    {
                        Width = (int) _textSprite.Width;
                        _target.Width = Width;
                    }
                }
                RefreshText();
            }
        }

Usage Example

Пример #1
0
        public bool Initialize(string name, string text, int screenWidth, int screenHeight, Random r, out string reason)
        {
            _text = new BBTextBox();
            if (!_text.Initialize(0, 0, WIDTH - 30, 0, true, false, name, r, out reason))
            {
                return false;
            }
            _text.SetText(text);
            if (_text.Width < WIDTH - 30)
            {
                _actualWidth = _text.Width + 30;
            }
            else
            {
                _actualWidth = WIDTH;
            }

            _totalHeight = _text.Height + 15;

            _background = new BBStretchableImage();
            if (!_background.Initialize(0, 0, _actualWidth, _totalHeight, StretchableImageType.ThinBorderBG, r, out reason))
            {
                return false;
            }

            _showing = false;
            _delayBeforeShowing = 0; //1 second will turn on showing

            _screenWidth = screenWidth;
            _screenHeight = screenHeight;

            reason = null;
            return true;
        }