[Mono-winforms-list] RichTextBox

Paul paul at all-the-johnsons.co.uk
Tue Aug 2 11:31:22 EDT 2005


Hi,

Mono is moaning when I try to compile the code below. It is complaining
about RichTextBox not being around. From the looks of the progress on
RichTextBox, the code should work.

TTFN

Paul

using System;
using System.Windows.Forms;
using System.Collections;
using System.Drawing;

class TextEditing : Form
{
  TextBox tb;
  RichTextBox rtb; // <- failed to compile this line
  Random rand = new Random();

  TextEditing()
  {
    ClientSize = new Size(450, 400);
    Text = "Text Editing";

    tb = new TextBox();
    tb.Text = "Some text";
    tb.Location = new Point(10, 10);

    Button bold = new Button();
    bold.Text = "Bold";
    bold.Location = new Point(350, 10);
    bold.Click += new EventHandler(bold_Click);

    Button color = new Button();
    color.Text = "Colour";
    color.Location = new Point(350, 60);
    color.Click += new EventHandler(color_Click);

    Button size = new Button();
    size.Text = "Size";
    size.Location = new Point(350, 110);
    size.Click += new EventHandler(size_Click);

    Button font = new Button();
    font.Text = "Font";
    font.Location = new Point(350, 160);
    font.Click += new EventHandler(font_Click);

    rtb = new RichTextBox();
    rtb.Location = new Point(10, 50);
    rtb.Size = new Size(300, 180);

    Controls.AddRange(new System.Windows.Forms.Control[]
	{
	  tb, rtb, bold, color, size, font
	} );
  }

  private void AddAndSelectText()
  {
    string newText = tb.Text + "\n";
    int insertionPoint = rtb.SelectionStart;
    rtb.AppendText(newText);
    rtb.SelectionStart = insertionPoint;
    rtb.SelectionLength = newText.Length;
  }

  private void ResetSelectionAndFont()
  {
    //set beyond end of textbox places insertion at end of text
    rtb.SelectionStart = Int16.MaxValue;
    rtb.SelectionLength = 0;
    rtb.SelectionFont = new Font("Verdana", 10, FontStyle.Regular);
    rtb.SelectionColor = Color.Black;
  }

  private void bold_Click(object sender, System.EventArgs e)
  {
    AddAndSelectText();
    rtb.SelectionFont = new Font("Verdana", 10, FontStyle.Bold);
    ResetSelectionAndFont();
  }

  private void color_Click(object sender, System.EventArgs e)
  {
    AddAndSelectText();
    rtb.SelectionColor = (rand.NextDouble()) > 0.5 ? Color.Red :
Color.Blue;
    ResetSelectionAndFont();
  }

  private void size_Click(object sender, System.EventArgs e)
  {
    AddAndSelectText();
    int fontSize = 8 + rand.Next(10);
    rtb.SelectionFont = new Font("Verdana", fontSize,
FontStyle.Regular);
    ResetSelectionAndFont();
  }

  private void font_Click(object sender, System.EventArgs e)
  {
    AddAndSelectText();
    FontFamily[] families = FontFamily.Families;
    int iFamily = rand.Next(families.Length);
    rtb.SelectionFont = new Font(families[iFamily], 10,
FontStyle.Regular);
    ResetSelectionAndFont();
  }

  static void Main()
  {
    Application.Run(new TextEditing());
  }
}


-- 
"Some people will do anything for a woman in uniform" - The Doctor -
Unregenerate (Big Finish audio)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.ximian.com/pipermail/mono-winforms-list/attachments/20050802/5089bf48/attachment-0001.bin


More information about the Mono-winforms-list mailing list