How do you call “Document Format” programmatically

2019-01-19 19:58发布

I'm writing a simple VS add-in and would like to programmatically invoke the "Document Format" option (under Edit) within code. Google isn't being very friendly to me today....

3条回答
▲ chillily
2楼-- · 2019-01-19 20:48

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.

查看更多
来,给爷笑一个
3楼-- · 2019-01-19 20:58

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

查看更多
甜甜的少女心
4楼-- · 2019-01-19 20:58
Command cmd = _applicationObject.Commands.Item("Edit.FormatDocument", -1);
object dummy = null;
_applicationObject.Commands.Raise(cmd.Guid, cmd.ID, ref dummy, ref dummy);
查看更多
登录 后发表回答