首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Excel2003 ActionsPane中的AutoSize ElementHost

Excel2003 ActionsPane中的AutoSize ElementHost
EN

Stack Overflow用户
提问于 2009-05-21 22:13:51
回答 1查看 478关注 0票数 2

我在Excel2003 ActionsPane中托管了一个WPF图表。图表被设置为水平和垂直拉伸,但是,尽管ElementHost和图表水平填充ActionsPane,但我还没有找到一种使ElementHost能够垂直填充的方法。唯一对ElementHost布局有影响的属性是Height和Size属性。Anchor、Dock、AutoSize似乎都不会影响ActionsPane对象或ElementHost对象上的布局。

我是不是遗漏了什么?

致以敬意,

丹尼

代码语言:javascript
复制
// A snippet from ThisWorkbook.cs
public partial class ThisWorkbook
{
    private void ThisWorkbook_Startup(object sender, System.EventArgs e)
    {

        var ap = Globals.ThisWorkbook.ActionsPane;
        ap.Clear();
        ap.Visible = true;
        var plotControl1 = new Swordfish.WPF.Charts.TestPage();
        var elementHost1 = new System.Windows.Forms.Integration.ElementHost();
        elementHost1.AutoSize = true; // Doesn't seem to have an effect.
        elementHost1.Child = plotControl1;

        ap.Controls.Add(elementHost1);

    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-01-05 04:48:39

创建名为my ActionPane的自定义WPF窗体,并将其承载在ElementHost中。下面是我如何处理ElementHost本身:

代码语言:javascript
复制
private void ThisDocument_Startup(object sender, System.EventArgs e)
    {
        ActionPane actionPaneControl = new ActionPane();
        this.ActionsPane.Resize += new EventHandler(ActionsPane_Resize);
        this.ActionsPane.Controls.Add(new ElementHost { Child = actionPaneControl, AutoSize = true });
    }

基本上,我订阅了ActionsPane Resize事件,并根据该事件调整ElementHost对象的大小。这提供了WPF控制(具有顶点和水平拉伸)随Office应用程序窗口一起调整大小的附加好处

代码语言:javascript
复制
void ActionsPane_Resize(object sender, EventArgs e)
    {
        ((this.ActionsPane.Controls[0] as ElementHost).Child as ActionPane).Height = this.ActionsPane.Height;
    }
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/895507

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档