728x90
반응형
728x170
▶ MainForm.cs
using System;
using System.Drawing;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
#region 이벤트를 설정한다.
Load += Form_Load;
this.copyButton.Click += copyButton_Click;
this.pasterButton.Click += pasteButton_Click;
#endregion
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
//////////////////////////////////////////////////////////////////////////////// Function
#region 폼 로드시 처리하기 - Form_Load(sender, e)
/// <summary>
/// 폼 로드시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_Load(object sender, EventArgs e)
{
string text = "The quick brown fox jumps over the lazy dog.";
this.sourceRichTextBox.Text = text;
this.sourceRichTextBox.Select(text.IndexOf("quick"), "quick".Length);
this.sourceRichTextBox.SelectionFont = new Font(this.sourceRichTextBox.SelectionFont, FontStyle.Italic);
this.sourceRichTextBox.Select(text.IndexOf("brown"), "brown".Length);
this.sourceRichTextBox.SelectionFont = new Font(this.sourceRichTextBox.SelectionFont, FontStyle.Bold);
this.sourceRichTextBox.SelectionColor = Color.Brown;
this.sourceRichTextBox.Select(text.IndexOf("fox"), "fox".Length);
this.sourceRichTextBox.SelectionFont = new Font(this.sourceRichTextBox.SelectionFont, FontStyle.Bold);
this.sourceRichTextBox.SelectionColor = Color.Red;
this.sourceRichTextBox.Select(text.IndexOf("jumps over"), "jumps over".Length);
this.sourceRichTextBox.SelectionFont = new Font(this.sourceRichTextBox.SelectionFont, FontStyle.Underline);
this.sourceRichTextBox.Select(text.IndexOf("lazy"), "lazy".Length);
this.sourceRichTextBox.SelectionFont = new Font(this.sourceRichTextBox.SelectionFont, FontStyle.Bold);
this.sourceRichTextBox.Select(text.IndexOf("dog"), "dog".Length);
this.sourceRichTextBox.SelectionFont = new Font(this.sourceRichTextBox.SelectionFont, FontStyle.Bold);
this.sourceRichTextBox.SelectionColor = Color.Blue;
this.sourceRichTextBox.Select(0, 0);
}
#endregion
#region 복사하기 버튼 클릭시 처리하기 - copyButton_Click(sender, e)
/// <summary>
/// 복사하기 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void copyButton_Click(object sender, EventArgs e)
{
DataObject dataObject = new DataObject();
dataObject.SetData(DataFormats.Rtf , this.sourceRichTextBox.Rtf );
dataObject.SetData(DataFormats.Text, this.sourceRichTextBox.Text);
string htmlText;
htmlText = "<HTML>\r\n";
htmlText += " <HEAD>The Quick Brown Fox</HEAD>\r\n";
htmlText += " <BODY>\r\n";
htmlText += sourceRichTextBox.Text + "\r\n";
htmlText += " </BODY>\r\n";
htmlText += "</HTML>";
dataObject.SetData(DataFormats.Html, htmlText);
Clipboard.SetDataObject(dataObject);
}
#endregion
#region 붙여넣기 버튼 클릭시 처리하기 - pasteButton_Click(sender, e)
/// <summary>
/// 붙여넣기 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void pasteButton_Click(object sender, EventArgs e)
{
IDataObject dataObject = Clipboard.GetDataObject();
if(dataObject.GetDataPresent(DataFormats.Rtf))
{
this.rtfRichTextBox.Rtf = dataObject.GetData(DataFormats.Rtf).ToString();
this.rtfCodeTextBox.Text = dataObject.GetData(DataFormats.Rtf).ToString();
}
else
{
this.rtfRichTextBox.Clear();
this.rtfCodeTextBox.Clear();
}
if(dataObject.GetDataPresent(DataFormats.Text))
{
this.textTextBox.Text = dataObject.GetData(DataFormats.Text).ToString();
}
else
{
this.textTextBox.Clear();
}
if(dataObject.GetDataPresent(DataFormats.Html))
{
this.htmlTextBox.Text = dataObject.GetData(DataFormats.Html).ToString();
}
else
{
this.htmlTextBox.Clear();
}
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] OleDbEnumerator 클래스 : OLEDB 공급자 조회하기 (0) | 2018.12.23 |
---|---|
[C#/COMMON] 정규식 사용하기 (0) | 2018.12.22 |
[C#/COMMON] CPU 부하 생성하기 (0) | 2018.12.21 |
[C#/COMMON] 파스칼/카멜 표기법 사용하기 (0) | 2018.12.13 |
[C#/COMMON] Clipboard 클래스 : 데이터 포맷 구하기 (0) | 2018.12.11 |
[C#/COMMON] Clipboard 클래스 : 객체 사용하기 (0) | 2018.12.11 |
[C#/COMMON] 진수 변환하기 (0) | 2018.12.09 |
[C#/COMMON] 오일러의 체(Euler's Sieve)를 사용해 소수 구하기 (0) | 2018.12.09 |
[C#/COMMON] 에라토스테네스의 체(Sieve of Eratosthenes)를 사용해 소수 구하기 (0) | 2018.12.09 |
[C#/COMMON] TimeZoneInfo 클래스 : GetSystemTimeZones 정적 메소드를 사용해 표준 시간대 나열하기 (0) | 2018.12.08 |
댓글을 달아 주세요