How do you call “Document Format” programmatically from C#?

核能气质少年 提交于 2019-11-28 12:24:07
Command cmd = _applicationObject.Commands.Item("Edit.FormatDocument", -1);
object dummy = null;
_applicationObject.Commands.Raise(cmd.Guid, cmd.ID, ref dummy, ref dummy);

If you have a reference to your document (of type Window), and you have a reference to the _DTE object, you can call it like this:

myDocument.Activate();
myDTE.ExecuteCommand("Edit.FormatDocument", string.Empty);

Most of the time, you can get a reference to the _DTE object from the parameters passed into your add-in.

You'll need to use the standard command editors, called with the VSStd2KCmdId.FORMATDOCUMENT command enumeration.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!