winform实现编辑器(menu,toolstrip,checkedChanged)

该程序是通过WinForm通过C#创建一个类似于文本编辑器一样的东西,可以通过菜单和状态栏来改变字体是否字体,是否是粗体,斜体.下划线等等 ....
1.界面就是一个MENU控件,一个TOOLSTRIP控件.注意的是要实现CHECKedCHANG功能,那么就要把他们属性.,checkonchange设置为true;
2. 各个按纽改变时的控件程序:

         // 用Button设置粗体

        
private   void  toolStripButton1_CheckedChanged( object  sender, EventArgs e)
        
{
            Font oldFont;
            Font newFont;
            oldFont 
= richTextBox1.SelectionFont;
            
//得到当前按钮的状态,到底是checked状态还是没有checked的状态
            bool checkStatse = ((ToolStripButton)sender).Checked;
            
if (!oldFont.Bold && checkStatse)
            
{
                
//设置新的字体
                newFont = new Font(oldFont, oldFont.Style | FontStyle.Bold);
            }

            
else
            
{
                newFont 
= new Font(oldFont, oldFont.Style & ~FontStyle.Bold);
            }

            richTextBox1.SelectionFont 
= newFont;
            richTextBox1.Focus();
        }

        
// 用Button设置斜体
         private   void  toolStripButton2_CheckedChanged( object  sender, EventArgs e)
        
{
            Font oldFont;
            Font newFont;
            oldFont 
= richTextBox1.SelectionFont;
            
bool checkStatse = ((ToolStripButton)sender).Checked;
            
if (!oldFont.Italic && checkStatse)
            
{
                newFont 
= new Font(oldFont, oldFont.Style | FontStyle.Italic);
            }

            
else
            
{
                newFont 
= new Font(oldFont, oldFont.Style & ~FontStyle.Italic);
            }

            richTextBox1.SelectionFont 
= newFont;
            richTextBox1.Focus();
        }

        
// 用Button设置下划线
         private   void  toolStripButton3_CheckedChanged( object  sender, EventArgs e)
        
{

            Font oldFont;
            Font newFont;
            oldFont 
= richTextBox1.SelectionFont;
            
bool checkStatse = ((ToolStripButton)sender).Checked;
            
if (!oldFont.Underline && checkStatse)
            
{
                newFont 
= new Font(oldFont, oldFont.Style | FontStyle.Underline);
            }

            
else
            
{
                newFont 
= new Font(oldFont, oldFont.Style & ~FontStyle.Underline);
            }

            richTextBox1.SelectionFont 
= newFont;
            richTextBox1.Focus();
        }

        
private   void  boldToolStripMenuItem_CheckedChanged_1( object  sender, EventArgs e)
        
{
            
//menu上边的设置按钮的checled与否,再根据checkchange来改变
            toolStripButton1.Checked = boldToolStripMenuItem.Checked;
        }


        
private   void  下划线ToolStripMenuItem_CheckedChanged( object  sender, EventArgs e)
        
{
            toolStripButton3.Checked 
= 下划线ToolStripMenuItem.Checked;
        }




        
private   void  斜体ToolStripMenuItem_CheckedChanged_1( object  sender, EventArgs e)
        
{
            toolStripButton2.Checked 
= 斜体ToolStripMenuItem.Checked;
        }

3.下拉式选单选择字体:

         private   void  toolStripComboBox1_SelectedIndexChanged( object  sender, EventArgs e)
        
{
            
string str = ((ToolStripComboBox)sender).SelectedItem.ToString();
            Font newFont 
= new Font(str, 30, richTextBox1.SelectionFont.Style);
            richTextBox1.SelectionFont 
= newFont;
        }


3.另外,皮肤的设置是通过使用了主题控件DLL,然后直接调用实现的:

private   void  blueToolStripMenuItem_Click( object  sender, EventArgs e)
        
{
            
//设置皮肤
            skinEngine1.SkinFile = "DiamondBlue.ssk";
        }


 

转载于:https://www.cnblogs.com/sorry208/articles/941482.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值