c#下任意文件 c#代码自动修改解决方案下任意文件实例

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

c#下任意文件 c#代码自动修改解决方案下任意文件实例

  2021-03-20 我要评论
想了解c#代码自动修改解决方案下任意文件实例的相关内容吗,在本文为您仔细讲解c#下任意文件的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:c#,解决方案,文件,下面大家一起来学习吧。

命名空间

复制代码 代码如下:

using EnvDTE;
using EnvDTE80;

private DTE2 _applicationObject;

 

public void AutoAddControl(插件 v_form1)
        {
            //得到当前文件的名称
            string v_pathfile = _applicationObject.ActiveDocument.FullName;
            //打开文件 "Form1.Designer.cs"
            if (!(v_pathfile.EndsWith(".cs")))
            {
                MessageBox.Show("当前文件不是.cs文件");
                return;
            }
            v_pathfile = System.IO.Path.ChangeExtension(v_pathfile, ".Designer.cs");
            _applicationObject.ItemOperations.OpenFile(v_pathfile);
            string v_file = System.IO.Path.GetFileName(v_pathfile);
            _applicationObject.Windows.Item(v_file).Activate();
            //修改文件内容 "Form1.Designer.cs"
            Document v_doc = _applicationObject.ActiveDocument;
            TextSelection selection = (TextSelection)_applicationObject.ActiveDocument.Selection;
            selection.SelectAll();
            string v_text = selection.Text;
            v_text = v_form1.ChangeDoc1(v_text);
            selection.SelectAll();
            selection.Text = "";
            selection.Insert(v_text);
            //保存文件 "Form1.Designer.cs" 
            _applicationObject.ActiveDocument.Save();
            _applicationObject.ExecuteCommand("Window.CloseDocumentWindow");

         //vsSaveChangesYes保存并关闭当前活动窗体
            //_applicationObject.ActiveWindow.Close(vsSaveChanges.vsSaveChangesYes);
        }

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们