The c code automatically modifies any file instance under the solution

  • 2020-05-24 05:58:42
  • OfStack

The namespace


using EnvDTE;
using EnvDTE80;
private DTE2 _applicationObject;
 
public void AutoAddControl( The plug-in  v_form1)
        {
            // Gets the name of the current file 
            string v_pathfile = _applicationObject.ActiveDocument.FullName;
            // Open the file  "Form1.Designer.cs"
            if (!(v_pathfile.EndsWith(".cs")))
            {
                MessageBox.Show(" Current file is not .cs file ");
                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();
            // Modify file contents  "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);
            // Save the file  "Form1.Designer.cs"  
            _applicationObject.ActiveDocument.Save();
            _applicationObject.ExecuteCommand("Window.CloseDocumentWindow");
         //vsSaveChangesYes Save and close the currently active form 
            //_applicationObject.ActiveWindow.Close(vsSaveChanges.vsSaveChangesYes);
        }


Related articles: