Beispiel #1
0
        /// <summary>
        ///     Change the richtextbox font for the current selection.
        /// </summary>
        /// <param name="fontFamily">The new font name.</param>
        public void ChangeFont(string fontFamily)
        {
            int rtbstart = rtb.SelectionStart;
            int len      = rtb.SelectionLength;

            // Step through the selected text one char at a time
            rtbTemp.Rtf = rtb.SelectedRtf;
            for (int i = 0; i < len; ++i)
            {
                rtbTemp.Select(i, 1);
                rtbTemp.SelectionFont = new Font(fontFamily, rtbTemp.SelectionFont.Size, rtbTemp.SelectionFont.Style);
            }

            // Replace & reselect
            rtbTemp.SelectAll();
            rtb.SelectedRtf = rtbTemp.SelectedRtf;
            rtb.Select(rtbstart, len);
            return;
        }
Beispiel #2
0
        private void InsertLink_TextMethod(string linkText)
        {
            int iPos;

            string stringToSplit = textBox.Text;

            do
            {
                iPos = stringToSplit.IndexOf(linkText);
                if (iPos < 0)
                {
                    break;
                }
                else
                {
                    //textBox.Select(iPos, linkText.Length);
                    textBox.Select(textBox.Text.IndexOf(stringToSplit) + iPos, linkText.Length);
                    textBox.SetSelectionLink(true);
                    //textBox.Select(iPos + linkText.Length, 0);textBox.Text.IndexOf(stringToSplit) + iPos
                    textBox.Select(textBox.Text.IndexOf(stringToSplit) + iPos + linkText.Length, 0);
                    stringToSplit = textBox.Text.Remove(0, textBox.SelectionStart);
                }
            } while (textBox.SelectionStart < (textBox.TextLength - 2));
        }