83 lines
2.7 KiB
C#
83 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Volian.Controls.Library
|
|
{
|
|
public partial class DisplayTabRibbon : UserControl
|
|
{
|
|
|
|
private RichTextBox _RichTextBox;
|
|
public RichTextBox RichTextBox
|
|
{
|
|
get { return _RichTextBox; }
|
|
set
|
|
{
|
|
_RichTextBox = value;
|
|
if (value != null)
|
|
{
|
|
_ContextMenuBar.SetContextMenuEx(_RichTextBox, btnCMRtfEdit);
|
|
_RichTextBox.SelectionChanged += new EventHandler(_RichTextBox_SelectionChanged);
|
|
_RichTextBox.Leave += new EventHandler(_RichTextBox_Leave);
|
|
}
|
|
}
|
|
}
|
|
void _RichTextBox_Leave(object sender, EventArgs e)
|
|
{
|
|
_RichTextBox.SelectionChanged -= new EventHandler(_RichTextBox_SelectionChanged);
|
|
_RichTextBox.Leave -= new EventHandler(_RichTextBox_Leave);
|
|
}
|
|
void _RichTextBox_SelectionChanged(object sender, EventArgs e)
|
|
{
|
|
btnCMBold.Checked = btnBold.Checked = _RichTextBox.SelectionFont.Bold;
|
|
btnCMItalics.Checked = btnItalics.Checked = _RichTextBox.SelectionFont.Italic;
|
|
btnCMUnderline.Checked = btnUnderline.Checked = _RichTextBox.SelectionFont.Underline;
|
|
btnCut.Enabled = btnCopy.Enabled = btnCMCut.Enabled = btnCMCopy.Enabled = _RichTextBox.SelectionLength > 0;
|
|
}
|
|
public DisplayTabRibbon()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
private void btnPaste_Click(object sender, EventArgs e)
|
|
{
|
|
IDataObject myDO = Clipboard.GetDataObject();
|
|
if (myDO.GetDataPresent("Rich Text Format"))
|
|
_RichTextBox.SelectedRtf = myDO.GetData("Rich Text Format").ToString();
|
|
else if (myDO.GetDataPresent("Text"))
|
|
_RichTextBox.SelectedText = myDO.GetData("Text").ToString();
|
|
}
|
|
private void btnCut_Click(object sender, EventArgs e)
|
|
{
|
|
Clipboard.Clear();
|
|
DataObject myDO = new DataObject("Rich Text Format", _RichTextBox.SelectedRtf);
|
|
Clipboard.SetDataObject(myDO);
|
|
_RichTextBox.SelectedText = "";
|
|
}
|
|
private void btnCopy_Click(object sender, EventArgs e)
|
|
{
|
|
Clipboard.Clear();
|
|
DataObject myDO = new DataObject("Rich Text Format", _RichTextBox.SelectedRtf);
|
|
Clipboard.SetDataObject(myDO);
|
|
}
|
|
private void btnBold_Click(object sender, EventArgs e)
|
|
{
|
|
FontStyle fs = _RichTextBox.SelectionFont.Style ^ FontStyle.Bold;
|
|
_RichTextBox.SelectionFont = new Font(_RichTextBox.SelectionFont, fs);
|
|
}
|
|
private void btnItalics_Click(object sender, EventArgs e)
|
|
{
|
|
FontStyle fs = _RichTextBox.SelectionFont.Style ^ FontStyle.Italic;
|
|
_RichTextBox.SelectionFont = new Font(_RichTextBox.SelectionFont, fs);
|
|
}
|
|
private void btnUnderline_Click(object sender, EventArgs e)
|
|
{
|
|
FontStyle fs = _RichTextBox.SelectionFont.Style ^ FontStyle.Underline;
|
|
_RichTextBox.SelectionFont = new Font(_RichTextBox.SelectionFont, fs);
|
|
}
|
|
}
|
|
}
|