楼主啊,反正我这里用textObject是能够编译成功的。
用FieldObject也应该能够顺利编译啊!

解决方案 »

  1.   

    : polarlm(polarlm)
    还是上次的老问题,一直没有解决。
    我设置文本内容,颜色都没有问题,就是设置Left,Top时候老是错误,你试看。谢谢了!
      

  2.   

    如下例程在我这里运行良好啊!
    给我你的mail!我给你发过去,连的是水晶报表自带的数据库
      

  3.   

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using CrystalDecisions.Shared;
    using CrystalDecisions.CrystalReports.Engine;namespace Cr
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer1;
    private Cr.ex ex1;
    private System.Windows.Forms.Button button1;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.crystalReportViewer1 = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
    this.ex1 = new Cr.ex();
    this.button1 = new System.Windows.Forms.Button();
    this.SuspendLayout();
    // 
    // crystalReportViewer1
    // 
    this.crystalReportViewer1.ActiveViewIndex = -1;
    this.crystalReportViewer1.DisplayGroupTree = false;
    this.crystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill;
    this.crystalReportViewer1.Location = new System.Drawing.Point(0, 0);
    this.crystalReportViewer1.Name = "crystalReportViewer1";
    this.crystalReportViewer1.ReportSource = null;
    this.crystalReportViewer1.Size = new System.Drawing.Size(376, 266);
    this.crystalReportViewer1.TabIndex = 0;
    this.crystalReportViewer1.Load += new System.EventHandler(this.crystalReportViewer1_Load);
    // 
    // ex1
    // 
    this.ex1.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.DefaultPaperOrientation;
    this.ex1.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.DefaultPaperSize;
    this.ex1.PrintOptions.PaperSource = CrystalDecisions.Shared.PaperSource.Upper;
    this.ex1.PrintOptions.PrinterDuplex = CrystalDecisions.Shared.PrinterDuplex.Default;
    // 
    // button1
    // 
    this.button1.Location = new System.Drawing.Point(304, 0);
    this.button1.Name = "button1";
    this.button1.TabIndex = 1;
    this.button1.Text = "button1";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(376, 266);
    this.Controls.Add(this.button1);
    this.Controls.Add(this.crystalReportViewer1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void crystalReportViewer1_Load(object sender, System.EventArgs e)
    {
    this.crystalReportViewer1.ReportSource=this.ex1;
    } private void button1_Click(object sender, System.EventArgs e)
    {
        TextObject temp= GetTextObject(this.ex1,"Text6");
    temp.Left=0;
    temp.Top=0;
    temp.Color=Color.Red;
    temp.Text="I love you!"; FieldObject obj=GetFieldObject(this.ex1,"Field1");
                obj.Left=0;
    obj.Top=0;
    obj.Color=Color.Blue; this.crystalReportViewer1.RefreshReport();
    } // 按名称获取 ReportObject,将其转换为 TextObject,并返回此对象。
    private TextObject GetTextObject(ReportDocument  Report,string reportObjectName) 
    {
    TextObject text; text = Report.ReportDefinition.ReportObjects[reportObjectName] as TextObject;
    if (text != null)
    return text;
    else
    return null;
    }
    // 按名称获取 ReportObject,将其转换为 FieldObject,
    // 并返回此对象。
    private FieldObject GetFieldObject(ReportDocument  Report,string reportObjectName) 
    {
    FieldObject field;
    field = Report.ReportDefinition.ReportObjects[reportObjectName] as FieldObject;
    if (field != null) return field;
    else return null;
    } }
    }