通过报告外部的代码更改文本框的字体 [英] Change the font of a textbox by code outside the report

查看:103
本文介绍了通过报告外部的代码更改文本框的字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我正在使用本地报告的报告服务。

是否可以通过代码更改文本框的字体?例如,您可以在数组中传递参数值,然后报表查看器绑定其值,如何在显示报表之前按代码传递或设置报表中文本框的字体?

是为了给用户提供在显示报告之前选择字体的可能性。字体将由字体对话框组件选择。

感谢所有,

Jesús

解决方案

HeyJesús,

这很容易做到并且你走在正确的轨道上。

在报表设计器中,为你想要自定义的字体的任何部分添加参数:FontFamily,FontStyle等。需要可自定义字体的文本框,转到PropertyPane并将字体属性设置为这些参数

FontFamily,设置为" = Parameters!MyFontFamilyParam.Value"例如

那么在代码中,只需从Font对象中设置这些参数:




















































private void OnFontButtonClick( object <字体style ="font-size:11px"> sender,EventArgs e)
{
FontDialog fd = new FontDialog类();
fd.ShowDialog( this );
字体chosenFont = fd.Font;
if (selectedFont!= null
{
DisplayReport( chosenFont);
}
}
private void DisplayReport(Font font)
{
。reportViewer1.LocalReport.SetParameters( new ReportParameter [] {
< font style ="color:blue"> new ReportParameter( " MyFontFamilyParam" ,font.Name),
new ReportParameter( " MyFontStyleParam" ,font.Style.ToString()),
new ReportParameter( " MyFontSizeParam" ,font.SizeInPoints.ToString()+ " pt"
});
。reportViewer1.RefreshReport();
}

Hi everybody!

I'm using reporting services with local report.

Is it possible to change the font of a textbox by code? For example, you can pass the parameters values in an array and then the reportviewer bind its values, how can I pass or set the font of a textbox in the report by code before the report is shown?

The idea is to give to the user the possibility of choose the Font before the report is shown. The Font would be chosen by a Font Dialog Component.

Thanks to all,

Jesús

解决方案

Hey Jesús,

This is pretty easy to do and you are on the right track.

In the report designer, add parameters for whatever part of the font you want to customize: FontFamily, FontStyle, etc. In the textbox that needs the customizable font, go to the PropertyPane and set the font properties to these parameters

FontFamily, set to "=Parameters!MyFontFamilyParam.Value" for example

Then in the code, just set those parameters from a Font object:



        private void OnFontButtonClick(object sender, EventArgs e)  
        {  
            FontDialog fd = new FontDialog();  
            fd.ShowDialog(this);  
 
            Font chosenFont = fd.Font;  
            if (chosenFont != null)  
            {  
                DisplayReport(chosenFont);  
            }  
        }  
 
        private void DisplayReport(Font font)  
        {  
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] {   
                new ReportParameter("MyFontFamilyParam", font.Name),  
                new ReportParameter("MyFontStyleParam", font.Style.ToString()),  
                new ReportParameter("MyFontSizeParam", font.SizeInPoints.ToString() + "pt")   
            });  
 
            this.reportViewer1.RefreshReport();  
        } 


这篇关于通过报告外部的代码更改文本框的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆