"Ewald" <***@freenet.de> writes:
Hallo Ewald,
Post by EwaldboxNotizen.SelectionFont = new Font("Arial",
boxNotizen.SelectionFont.Size, boxNotizen.SelectionFont.Style);
Dies klappt auch wunderbar, wenn der gewählte Text nur aus einem Schrifttyp
besteht. D.h. wenn z.B. mehrere Schriftgrösse im gewählten Text sind, kommt
es zum Fehler und das Programm bricht ab.
ACK.
Post by EwaldDies liegt wohl daran, daß in diesem Fall 'boxNotizen.SelectionFont.Size'
nicht mehr zugeordnet werden kann.
Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt
Post by EwaldWie kann ich nun erreichen, daß jeder beliebige Text nach meinen Vorgaben
formatiert werden kann?
boxNotizen.SelectionFont = new Font("Arial", this.Font.Size, this.Font.Style);
oder
// Code Anfang
using System;
using System.Windows.Forms;
using System.Drawing;
namespace MyFormProject
{
class MainForm : System.Windows.Forms.Form
{
private System.Windows.Forms.RichTextBox richTextBox;
private System.Windows.Forms.Button button;
public MainForm()
{
InitializeComponent();
FormatTextToRichTextBox();
}//end Konstruktor
// THIS METHOD IS MAINTAINED BY THE FORM DESIGNER
// DO NOT EDIT IT MANUALLY! YOUR CHANGES ARE LIKELY TO BE LOST
void InitializeComponent()
{
this.button = new System.Windows.Forms.Button();
this.richTextBox = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// button
//
this.button.Location = new System.Drawing.Point(9, 136);
this.button.Name = "button";
this.button.Size = new System.Drawing.Size(127, 32);
this.button.TabIndex = 0;
this.button.Text = "button";
this.button.Click += new System.EventHandler(this.ButtonClick);
//
// richTextBox
//
this.richTextBox.Location = new System.Drawing.Point(10, 8);
this.richTextBox.Name = "richTextBox";
this.richTextBox.Size = new System.Drawing.Size(128, 112);
this.richTextBox.TabIndex = 1;
this.richTextBox.Text = "Erste Zeile\nZweite Spalte\nDritte Zeile";
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(152, 180);
this.Controls.Add(this.button);
this.Controls.Add(this.richTextBox);
this.Name = "MainForm";
this.Text = "This is my form";
this.ResumeLayout(false);
}//end Methode
[STAThread]
public static void Main(string[] args)
{
Application.Run(new MainForm());
}//end Methode
void ButtonClick(object sender, System.EventArgs e)
{
this.richTextBox.SelectAll();
this.richTextBox.SelectionFont = new Font("Arial", 8, FontStyle.Italic | FontStyle.Underline);
}//end Methode
private void FormatTextToRichTextBox()
{
this.richTextBox.Find("Erste", RichTextBoxFinds.MatchCase);
this.richTextBox.SelectionFont = new Font("Verdana", 12, FontStyle.Bold);
this.richTextBox.Find("Spalte", RichTextBoxFinds.MatchCase);
this.richTextBox.SelectionFont = new Font("Mistral", 8, FontStyle.Bold);
this.richTextBox.Find("Dritte", RichTextBoxFinds.MatchCase);
this.richTextBox.SelectionFont = new Font("Impact", 16, FontStyle.Strikeout);
}//end Methode
}//end Class
}//end Namespace
//Code Ende
--
emails an ***@worldonline.de, die größer sind als 4 KBytes,
werden in /dev/null entsorgt!