C#初学者——第二个窗口小程序
来源:互联网 发布:辐射4捏脸数据导入 编辑:程序博客网 时间:2024/05/19 06:18
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 Smaple_Text_Editor
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void buttonBoid_Click(object sender, EventArgs e)
{
Font oldFont;
Font newFont;
oldFont = this.richTextBox1.SelectionFont;
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 buttonUnderline_Click(object sender, EventArgs e)
{
Font oldFont;
Font newFont;
oldFont = this.richTextBox1.SelectionFont;
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 buttonItalic_Click(object sender, EventArgs e)
{
Font oldFont;
Font newFont;
oldFont = this.richTextBox1.SelectionFont;
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 buttonCenter_Click(object sender, 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 ApplyTextSize(string txtSize)
{
float newSize = Convert.ToSingle(txtSize);
FontFamily currentFontFamily;
Font newFont;
currentFontFamily = this.richTextBox1.SelectionFont.FontFamily;
newFont = new Font(currentFontFamily,newSize);
this.richTextBox1.SelectionFont = newFont;
//throw new NotImplementedException();
}
private void textBox1_Validated(object sender, EventArgs e)
{
TextBox txt = (TextBox)sender;
ApplyTextSize(txt.Text);
this.richTextBox1.Focus();
}
private void richTextBox1_LinkClicked(object sender, LinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(e.LinkText);
}
private void buttonLoad_Click(object sender, EventArgs e)
{
try
{
richTextBox1.LoadFile("Test.rtf");
}
catch
{
MessageBox.Show("没有加载文件");
}
}
private void buttonSave_Click(object sender, EventArgs e)
{
try
{
richTextBox1.SaveFile("Test.rtf");
}
catch (System.Exception err)
{
MessageBox.Show(err.Message);
}
}
}
}
- C#初学者——第二个窗口小程序
- C#初学者——第一个window 应用小程序
- 初学者做android 第一个小程序
- C#初学者—— 终于写出了自己第一个比较满意的程序
- 第二篇 第一个窗口程序
- Android之路——第二个Android小程序(Android短信发送)
- Android之路——第二个Android小程序(Android短信发送)
- 第二个vb小程序:迷你记事本
- 实习期间第二个小程序
- nodejs的第二个小程序
- 【windows程序设计】第一个小窗口程序
- Java程序设计——窗口小程序
- C#开发第二天-第一个程序
- 初学者——编写的小程序,收获很大
- android学习——第二个程序
- 第一个爬虫程序实例——初学者
- java 初学者 第二个问题
- C#的第一个小程序
- 总结
- uva 10719 Quotient Polynomial(多项式相除)
- Struts常见错误汇总
- Java并发编程: 使用CountDownLatch协调子线程
- 通过后台service,产生通知,并调出activity时刷新的问题
- C#初学者——第二个窗口小程序
- Android之一键连接指定wifi
- 多个常见代码设计缺陷
- VB.NET 函数列表
- Android最佳实践之:StrictMode介绍
- 解决“要运行Visual Studio 2005 sp1,建议使用管理员权限”的问题
- Android 国际化
- Android JUnit单元测试基础实例
- 跨站脚本XSS