private void 打开图形文件ToolStripMenuItem_Click(object sender, EventArgs e)
{
string NameFile;
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
NameFile = this.openFileDialog1.FileName;
if (NameFile != "")
{
this.pictureBox1.Image = Image.FromFile(NameFile);
}
}
}
private void 打开文本文件ToolStripMenuItem_Click(object sender, EventArgs e)
{
string Filename;
pictureBox1.Visible = false;
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
Filename = openFileDialog1.FileName;
if (Filename != "")
{
this.textBox1.Text = Filename;
this.richTextBox1.LoadFile(@Filename, RichTextBoxStreamType.PlainText);
}
}
}
//构造函数
this.textBox1.KeyPress += new KeyPressEventHandler(textBox1_KeyPress);
this.textBox1.Validating += new CancelEventHandler(textBox1_Validating);
this.richTextBox1.LinkClicked += new LinkClickedEventHandler(richTextBox1_LinkClicked);
//取消或置为粗体
private void button2_Click(object sender, System.EventArgs e)
{
Font oldFont = this.richTextBox1.SelectionFont;
Font newFont;
if (oldFont.Bold)
newFont = new Font(oldFont,oldFont.Style & ~FontStyle.Bold);
else
newFont = new Font(oldFont,oldFont.Style | FontStyle.Bold);
this.richTextBox1.SelectionFont = newFont;
this.richTextBox1.Focus();
}
//取消或置为斜体
private void button7_Click(object sender, System.EventArgs e)
{
Font oldFont = this.richTextBox1.SelectionFont;
Font newFont;
if (oldFont.Italic)
newFont = new Font(oldFont,oldFont.Style & ~FontStyle.Italic);
else
newFont = new Font(oldFont,oldFont.Style | FontStyle.Italic);
this.richTextBox1.SelectionFont = newFont;
this.richTextBox1.Focus();
}
//取消或加上下划线
private void button8_Click(object sender, System.EventArgs e)
{
Font oldFont = this.richTextBox1.SelectionFont;
Font newFont;
if (oldFont.Underline)
newFont = new Font(oldFont,oldFont.Style & ~FontStyle.Underline);
else
newFont = new Font(oldFont,oldFont.Style | FontStyle.Underline);
this.richTextBox1.SelectionFont = newFont;
this.richTextBox1
.Focus();
}
//取消或置为居中
private void button5_Click(object sender, System.EventArgs e)
{
if (this.richTextBox1.SelectionAlignment == HorizontalAlignment.Center)
this.richTextBox1.SelectionAlignment = HorizontalAlignment.Left;
else
this.richTextBox1.SelectionAlignment = HorizontalAlignment.Center;
this.richTextBox1.Focus();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar !=13)
{
e.Handled = true;
}
else if(e.KeyChar == 13)
{
TextBox txt = (TextBox)sender;
if(txt.Text.Length > 0)
ApplyTextSize(txt.Text);
e.Handled = true;
this.richTextBox1.Focus();
}
}
private void textBox1_Validating(object sender, CancelEventArgs e)
{
TextBox txt = (TextBox)sender;
ApplyTextSize(txt.Text);
this.richTextBox1.Focus();
}
//改变字体大小
private void ApplyTextSize(string textSize)
{
float newSize = Convert.ToSingle(textSize);
FontFamily currentFontFamily;
Font newFont;
currentFontFamily = this.richTextBox1.SelectionFont.FontFamily;
newFont = new Font(currentFontFamily, newSize);
this.richTextBox1.SelectionFont = newFont;
}
//打开网页
private void richTextBox1_LinkClicked(object sender, LinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(e.LinkText);
}
//打开文件
private void button1_Click(object sender, System.EventArgs e)
{
try
{
this.richTextBox1.LoadFile(@"..\..\test.txt");
}
catch(System.IO.FileNotFoundException)
{
MessageBox.Show("File not found!");
}
}
//保存文件
private void button6_Click(object sender, System.EventArgs e)
{
try
{
this.richTextBox1.SaveFile(@"..\..\test.txt");
}
catch(System.Exception err)
{
MessageBox.Show(err.Message);
}
}
public int Find(char[]);
private void button1_Click(object sender, System.EventArgs e)
{
MessageBox.Show(FindMyText(new char[]{'D','e','l','t','a'}).ToString());
}
public int FindMyText(char[] text)
{
// Initialize the return value to false by default.
int returnValue = -1;
// Ensure that a search string has been specified and a valid start point.
if (text.Length > 0)
{
// Obtain the location of the first character found in the control
// that matches any of the characters in the char array.
int indexToText = richTextBox1.Find(text);
// Determine whether the text was found in richTextBox1.
if(indexToText >= 0)
{
// Return the location of the character.
returnValue = indexToText;
}
}
return returnValue;
}
public int Find(string);
public int Find(char[], int);
public int Find(string, RichTextBoxFinds);
public bool FindMyText(string text)
{
// Initialize the return value to false by default.
bool returnValue = false;
// Ensure a search string has been specified.
if (text.Length > 0)
{
// Obtain the location of the search string in richTextBox1.
int indexToText = richTextBox1.Find(text, RichTextBoxFinds.MatchCase);
// Determine if the text was found in richTextBox1.
if(indexToText >= 0)
{
returnValue = true;
}
}
return returnValue;
}
public int Find(char[], int, int);
public int Find(string, int, RichTextBoxFinds);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有