【问题标题】:Moving the toolbar in ReportViewer to the bottom of the page将 ReportViewer 中的工具栏移至页面底部
【发布时间】:2019-01-15 23:57:40
【问题描述】:

在使用 C# 的 WinForms 中,ReportViewer 相对较新。我想要做的是将报告的工具栏移动到底部。据推测,实现此目的的一种方法是在页面上放置一个工具条并从工具栏构建它。看起来比较简单,只需在 Load 事件中插入几行代码即可:

// move the toolbar from the report viewer to the toolstripcontainer
ToolStrip toolStrip = (ToolStrip)FirstTestReport.Controls.Find("toolStrip1", true)[0];
toolStrip.GripStyle = ToolStripGripStyle.Hidden;
this.toolStripContainer1.TopToolStripPanel.Controls.Add(toolStrip);
this.FirstTestReport.ShowToolBar = false;
this.toolStripContainer1.Visible = true;

有点工作。因此,顶部工具栏消失了,但底部工具栏从未出现。在单步执行代码时,我意识到 ToolStrip 的 Visible 值始终为 False。我尝试添加一行以使其可见(ToolStrip.Visible = True),但它没有运行代码;它给了我一个错误:

非静态字段、方法或属性“Control.Visible”需要对象引用

关于如何解决这个问题的任何想法?

【问题讨论】:

  • 你不应该将ShowToolBar设置为false,它将reportToolbar的可见性设置为false,它是toolBar1的父级。因此,toolBar1 的可见性将被评估为 false。

标签: c# .net winforms reportviewer toolstrip


【解决方案1】:

使用 ToolStripContainer

如果您希望将其添加到工具条容器的底部面板中:

var toolStrip = (ToolStrip)reportViewer1.Controls.Find("toolStrip1", true)[0];
toolStrip.GripStyle = ToolStripGripStyle.Visible;
var reportToolbar = toolStrip.Parent;
reportToolbar.Visible = false;
this.toolStripContainer1.BottomToolStripPanel.Controls.Add(toolStrip);

没有 ToolStripContainer

var toolStrip = (ToolStrip)reportViewer1.Controls.Find("toolStrip1", true)[0];
toolStip.Parent.Dock = DockStyle.Bottom;

截图

【讨论】:

  • 不知什么原因,第一个还是不行。但由于第二个给了我需要的结果,我会接受它。谢谢!
  • 不客气。我都试过了,它们对我来说都很好。确保您的测试环境是干净的。对我来说,我只是添加了一个工具条面板,并没有更改控件的任何设置,然后运行我共享的代码。
猜你喜欢
  • 1970-01-01
  • 2016-09-11
  • 1970-01-01
  • 2018-09-27
  • 2013-09-10
  • 1970-01-01
  • 2023-03-25
  • 1970-01-01
  • 2016-11-20
相关资源
最近更新 更多