【发布时间】: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