当前位置: 首页>>代码示例>>C#>>正文


C# StyledText.HasSameStyle方法代码示例

本文整理汇总了C#中NetGore.Graphics.GUI.StyledText.HasSameStyle方法的典型用法代码示例。如果您正苦于以下问题:C# StyledText.HasSameStyle方法的具体用法?C# StyledText.HasSameStyle怎么用?C# StyledText.HasSameStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NetGore.Graphics.GUI.StyledText的用法示例。


在下文中一共展示了StyledText.HasSameStyle方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConcastTestA

        public void ConcastTestA()
        {
            var s1 = new StyledText("abcd", Color.Black);
            var s2 = new StyledText("123", Color.Black);
            var s3 = new StyledText("xyz", Color.Black);
            var concat = StyledText.Concat(new StyledText[] { s1, s2, s3 });

            Assert.AreEqual(1, concat.Count());
            Assert.AreEqual(s1.Text + s2.Text + s3.Text, concat.First().Text);
            Assert.IsTrue(s1.HasSameStyle(concat.First()));
        }
开发者ID:Furt,项目名称:netgore,代码行数:11,代码来源:StyledTextTests.cs

示例2: ConcastTestB

        public void ConcastTestB()
        {
            var s1 = new StyledText("abcd", Color.Black);
            var s2 = new StyledText("123", Color.Black);
            var s3 = new StyledText("xyz", Color.White);
            var concat = StyledText.Concat(new StyledText[] { s1, s2, s3 }).ToArray();

            Assert.AreEqual(2, concat.Count());
            Assert.AreEqual(s1.Text + s2.Text, concat[0].Text);
            Assert.AreEqual(s3.Text, concat[1].Text);
            Assert.IsTrue(s1.HasSameStyle(concat[0]));
            Assert.IsTrue(s3.HasSameStyle(concat[1]));
        }
开发者ID:Furt,项目名称:netgore,代码行数:13,代码来源:StyledTextTests.cs

示例3: HasSameStyleFalseTest

        public void HasSameStyleFalseTest()
        {
            var a = new StyledText("abc", Color.Red);
            var b = new StyledText("123", Color.Green);

            Assert.IsFalse(a.HasSameStyle(b));
            Assert.IsFalse(b.HasSameStyle(a));
        }
开发者ID:Furt,项目名称:netgore,代码行数:8,代码来源:StyledTextTests.cs

示例4: HasSameStyleTrueTest

        public void HasSameStyleTrueTest()
        {
            var a = new StyledText("abc", Color.Red);
            var b = new StyledText("123", a);

            Assert.IsTrue(a.HasSameStyle(b));
            Assert.IsTrue(b.HasSameStyle(a));
        }
开发者ID:Furt,项目名称:netgore,代码行数:8,代码来源:StyledTextTests.cs

示例5: Insert

        /// <summary>
        /// Inserts the <see cref="text"/> into the line at the specified position.
        /// </summary>
        /// <param name="position">The 0-based index to insert the <see cref="text"/>. The text
        /// will be inserted before the character in the line whos index is equal to the position. For example,
        /// inserting at position 3 will insert between the 3rd and 4th character of the string. As such,
        /// position 0 will insert at the start of the string, and the length of the string will insert
        /// at the end. If the position is invalid, this method will always return false.</param>
        /// <param name="text">The character to insert.</param>
        /// <returns>True if the <paramref name="text"/> was inserted successfully; otherwise false.</returns>
        public bool Insert(StyledText text, int position)
        {
            if (position < 0 || position > _lineText.Length)
                return false;

            if (position == 0)
            {
                // Insert at the start
                var first = _texts.Count > 0 ? _texts[0] : null;
                if (first != null)
                {
                    // Try to combine the texts
                    if (text.HasSameStyle(first))
                        _texts[0] = text + first.Text;
                    else
                        _texts.Insert(0, text);
                }
                else
                    _texts.Add(text);

                _lineText = text.Text + _lineText;
            }
            else if (position == _lineText.Length)
            {
                // Insert at the end
                var last = _texts.Count > 0 ? _texts[_texts.Count - 1] : null;
                if (last != null)
                {
                    // Try to combine the texts
                    if (text.HasSameStyle(last))
                        _texts[_texts.Count - 1] = last + text.Text;
                    else
                        _texts.Add(text);
                }
                else
                    _texts.Add(text);

                _lineText += text.Text;
            }
            else
            {
                // Somewhere in the middle

                // Get the StyledText containing the character to insert before
                StyledText subText;
                int subTextIndex;
                int listIndex;
                try
                {
                    FindLineCharacter(position, out subText, out subTextIndex, out listIndex);
                }
                catch (ArgumentOutOfRangeException)
                {
                    return false;
                }

                // Try to combine the texts
                if (text.HasSameStyle(subText))
                {
                    var combined = string.Empty;
                    if (subTextIndex > 0)
                        combined += subText.Text.Substring(0, subTextIndex);
                    combined += text.Text;
                    combined += subText.Text.Substring(subTextIndex);
                    _texts[listIndex] = new StyledText(combined, text);
                }
                else
                {
                    if (subTextIndex == 0)
                    {
                        // Don't need to split up the existing StyledText (inserts whole thing before)
                        _texts.Insert(listIndex, text);
                    }
                    else
                    {
                        // Have to split apart the existing StyledText and insert the new one in between
                        // the split up parts
                        var firstPart = subText.Substring(0, subTextIndex);
                        var secondPart = subText.Substring(subTextIndex);
                        _texts[listIndex] = secondPart;
                        _texts.Insert(listIndex, text);
                        _texts.Insert(listIndex, firstPart);
                    }
                }

                _lineText = _lineText.Substring(0, position) + text.Text + _lineText.Substring(position);
            }

            EnsureCacheMatchesActualText();

//.........这里部分代码省略.........
开发者ID:mateuscezar,项目名称:netgore,代码行数:101,代码来源:TextBoxLine.cs


注:本文中的NetGore.Graphics.GUI.StyledText.HasSameStyle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。