AW: [Mono-winforms-list] RichTextBox

Matthias Felgner matthiasf at voelcker.com
Tue Aug 2 11:35:27 EDT 2005


Hi, 

how is it supposed to work? There is no implementation of System.Windows.Forms.RichTextBox class yet in svn...PeterB is working on it though...

you can check at:

http://svn.myrealbox.com/

Greets

--Matt

-----Ursprüngliche Nachricht-----
Von: mono-winforms-list-bounces at lists.ximian.com [mailto:mono-winforms-list-bounces at lists.ximian.com] Im Auftrag von Paul
Gesendet: Dienstag, 2. August 2005 17:31
An: winforms
Betreff: [Mono-winforms-list] RichTextBox

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)


More information about the Mono-winforms-list mailing list