gpt4 book ai didi

ReportViewer - 修改工具栏?

转载 作者:行者123 更新时间:2023-12-04 09:22:50 25 4
gpt4 key购买 nike

有没有人对如何修改 WinForms 版本的 ReportViewer 工具栏的工具栏有好主意?
也就是说,我想删除一些按钮和各种按钮,但看起来解决方案是创建一个全新的工具栏,而不是修改现有的工具栏。

就像,我不得不删除导出到 excel,并这样做:

  // Disable excel export
foreach (RenderingExtension extension in lr.ListRenderingExtensions()) {
if (extension.Name == "Excel") {
//extension.Visible = false; // Property is readonly...
FieldInfo fi = extension.GetType().GetField("m_isVisible", BindingFlags.Instance | BindingFlags.NonPublic);
fi.SetValue(extension, false);
}
}

如果你问我,有点棘手。
对于删除工具栏按钮,一种可能的方法是遍历 ReportViewer 内的 Control 数组并更改按钮的 Visible 属性以隐藏,但它一直被重置,所以这不是一个好方法..

顺便说一句,MS 什么时候发布新版本?

最佳答案

是的。你可以用一种有点棘手的方式做到这一点。
我有一项任务是为缩放报告添加更多比例因子。我是这样做的:

    private readonly string[] ZOOM_VALUES = { "25%", "50%", "75%", "100%", "110%", "120%", "125%", "130%", "140%", "150%", "175%", "200%", "300%", "400%", "500%" };
private readonly int DEFAULT_ZOOM = 3;
//--

public ucReportViewer()
{
InitializeComponent();
this.reportViewer1.ProcessingMode = ProcessingMode.Local;

setScaleFactor(ZOOM_VALUES[DEFAULT_ZOOM]);

Control[] tb = reportViewer1.Controls.Find("ReportToolBar", true);

ToolStrip ts;
if (tb != null && tb.Length > 0 && tb[0].Controls.Count > 0 && (ts = tb[0].Controls[0] as ToolStrip) != null)
{
//here we go if our trick works (tested at .NET Framework 2.0.50727 SP1)
ToolStripComboBox tscb = new ToolStripComboBox();
tscb.DropDownStyle = ComboBoxStyle.DropDownList;

tscb.Items.AddRange(ZOOM_VALUES);
tscb.SelectedIndex = 3; //100%

tscb.SelectedIndexChanged += new EventHandler(toolStripZoomPercent_Click);

ts.Items.Add(tscb);
}
else
{
//if there is some problems - just use context menu
ContextMenuStrip cmZoomMenu = new ContextMenuStrip();

for (int i = 0; i < ZOOM_VALUES.Length; i++)
{
ToolStripMenuItem tsmi = new ToolStripMenuItem(ZOOM_VALUES[i]);

tsmi.Checked = (i == DEFAULT_ZOOM);
//tsmi.Tag = (IntPtr)cmZoomMenu;
tsmi.Click += new EventHandler(toolStripZoomPercent_Click);

cmZoomMenu.Items.Add(tsmi);
}

reportViewer1.ContextMenuStrip = cmZoomMenu;
}
}

private bool setScaleFactor(string value)
{
try
{
int percent = Convert.ToInt32(value.TrimEnd('%'));

reportViewer1.ZoomMode = ZoomMode.Percent;
reportViewer1.ZoomPercent = percent;

return true;
}
catch
{
return false;
}
}


private void toolStripZoomPercent_Click(object sender, EventArgs e)
{
ToolStripMenuItem tsmi = sender as ToolStripMenuItem;
ToolStripComboBox tscb = sender as ToolStripComboBox;

if (tscb != null && tscb.SelectedIndex > -1)
{
setScaleFactor(tscb.Items[tscb.SelectedIndex].ToString());
}
else if (tsmi != null)
{
if (setScaleFactor(tsmi.Text))
{
foreach (ToolStripItem tsi in tsmi.Owner.Items)
{
ToolStripMenuItem item = tsi as ToolStripMenuItem;

if (item != null && item.Checked)
{
item.Checked = false;
}
}

tsmi.Checked = true;
}
else
{
tsmi.Checked = false;
}
}
}

关于ReportViewer - 修改工具栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/114733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com