-
December 2nd, 2009, 06:02 AM
#1
Marked text? Only when color and font..
Hey this is my code
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
private void openToolStripButton_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "*.txt,*.rtf|*.txt;*.rtf";
if (dialog.ShowDialog() == DialogResult.OK)
{
string fileName = dialog.FileName;
if (fileName.Length > 0)
{
richTextBox1.LoadFile(fileName, GetStreamType(fileName));
}
}
}
private RichTextBoxStreamType GetStreamType(string fileName)
{
return fileName.EndsWith("rtf") ?
RichTextBoxStreamType.RichText : RichTextBoxStreamType.PlainText;
}
private void saveToolStripButton_Click(object sender, EventArgs e)
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "*.txt,*.rtf|*.txt;*.rtf";
if (dialog.ShowDialog() == DialogResult.OK)
{
string fileName = dialog.FileName;
richTextBox1.SaveFile(fileName, GetStreamType(dialog.FileName));
}
}
private void newToolStripButton_Click(object sender, EventArgs e)
{
richTextBox1.Clear();
}
private void printToolStripButton_Click(object sender, EventArgs e)
{
printDialog1.ShowDialog();
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
colorDialog1.ShowDialog();
richTextBox1.ForeColor = colorDialog1.Color;
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
fontDialog1.ShowDialog();
richTextBox1.Font = fontDialog1.Font;
}
}
}
I want to make the "Marked" text to change only when i use these buttons. (Color and fonts)
Thank you for helping me.
Mike
-
December 2nd, 2009, 06:59 AM
#2
Re: Marked text? Only when color and font..
The RichTextBox has following properties that will help you out.
SelectionFont
SelectionColor
SelectionBackColor
-
December 2nd, 2009, 07:13 AM
#3
Re: Marked text? Only when color and font..
Okay nice, but how do i code it then?
Example:
private void toolStripButton2_Click(object sender, EventArgs e)
{
fontDialog1.ShowDialog();
richTextBox1.SelectionFont = fontDialog1.Font;
}
this is giving me errors? Invalid Code..
-
December 2nd, 2009, 08:01 AM
#4
Re: Marked text? Only when color and font..
problem fixed, i copy and pasted it in another project. Thank you ixi for helping me
-
December 2nd, 2009, 09:21 AM
#5
Re: Marked text? Only when color and font..
No Problem
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|