Gedde
Gedde

Reputation: 1160

Find out if the Ruler in PowerPoint is visible with VSTO

How can I check whether the ruler in PowerPoint design mode is visible/active from C# VSTO?

I have searched for hours in the PowerPoint object model. Have I missed the obvious, or isn't there a flag specifying whether the ruler is visible or not?

Are there any other workarounds available to check whether the ruler is on or not? (I don't need to adjust the ruler visibility, just read the value).


Old non-working work-around specified below (kept to keep the comments relevant)

As a workaround I have tried to extend the ribbon and read the value of the checkbox defined as idMso="ViewRulerPowerPoint"

XML

<?xml version="1.0" encoding="UTF-8"?>
<customUI onLoad="Ribbon_Load" xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <commands>
      <command idMso="ViewRulerPowerPoint" onAction="OnRulerAction" />
    </commands> 
</customUI>

Callback

public void OnRulerAction(Microsoft.Office.Core.IRibbonControl control, bool pressed)
{
    Debug.Print("Checkbox pressed");
}

But I just receive the following error message:

Callback signature mismatch: OnRulerAction

I have tried for hours to find a suitable callback signature, but none of my attempts have been successful.

Upvotes: 1

Views: 142

Answers (1)

Olle Sj&#246;gren
Olle Sj&#246;gren

Reputation: 5385

In VBA you can check if the checkbox is checked or not by using the following command, which will return True or False:

Application.CommandBars.GetPressedMso("ViewRulerPowerPoint")

In a C# VSTO add-in you can re-write this code as:

Globals.ThisAddIn.Application.CommandBars.GetPressedMso("ViewRulerPowerPoint")

Upvotes: 3

Related Questions