CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2009
    Posts
    61

    Talking 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

  2. #2
    Join Date
    Nov 2009
    Location
    .net 3.5 csharp 2008 developer
    Posts
    36

    Re: Marked text? Only when color and font..

    The RichTextBox has following properties that will help you out.

    SelectionFont
    SelectionColor
    SelectionBackColor


  3. #3
    Join Date
    Nov 2009
    Posts
    61

    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..

  4. #4
    Join Date
    Nov 2009
    Posts
    61

    Re: Marked text? Only when color and font..

    problem fixed, i copy and pasted it in another project. Thank you ixi for helping me

  5. #5
    Join Date
    Nov 2009
    Location
    .net 3.5 csharp 2008 developer
    Posts
    36

    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
  •  





Click Here to Expand Forum to Full Width

Featured