2013-10-15 38 views
0

我想創建一個XtraReport模板類,它獲取報表對象並將其轉換爲我們的公司設計。起初,我創建了一個ReportHeaderBand,它爲Logo創建了一個XRPictureBox。如何將XRPictureBox放置在ReportHeaderBand的右側?在運行時設置XRPictureBox的對齊方式

這是我到目前爲止做:

internal class Kopfbereich: ReportHeaderBand 
    { 
     /// <summary> 
     /// Erstellt ein Objekt für den Kopfbereich eines Reports 
     /// </summary> 
     public Kopfbereich() 
     { 
      DruckeLogo(); 
     } 

     private void DruckeLogo() 
     { 
      XRPictureBox picBox = new XRPictureBox(); 
      picBox.Visible = true; 
      picBox.Sizing = ImageSizeMode.AutoSize; 
      picBox.Image = Resources.Brillux_Logo_Reports_ohne_Text; 
      this.Controls.Add(picBox); 
     } 
    } 

    //This Method is from other class and should print my report with template 
    public XtraReport DruckeMitVorlage(XtraReport report) 
    { 
     Kopfbereich kopfbereich = new Kopfbereich(); 
     report.Bands.Add(kopfbereich); 
     return report; 
    } 

我想在運行時創建它得到一個動態模板。所以Designer不是一種選擇。

我試着在右邊的代碼行設置XRPictureBox。

picBox.LocationF = new PointF(Report.PageWidth - picBox.WidthF - Report.Margins.Right.Width, 0); 

但是標誌在下一頁顯示一半。

回答

0

我建議您將此XRPictureBox控件添加到report header band而不是this.Controls。它可以控制圖片編輯在報告上打印的頂部,而不是在另一頁打印..

檢查代碼片段:

// Check if the TopMargin band is already present in the report. 
if(Bands.GetBandByType(typeof(ReportHeaderBand)) == null) { 
    // Create a new TopMargin band and add it to the report. 
    ReportHeaderBandtmBand = new ReportHeaderBand(); 
    Bands.Add(tmBand); 

    // Create a picture object 
    XRPictureBox picBox = new XRPictureBox(); 
    picBox.Visible = true; 
    picBox.Sizing = DevExpress.XtraPrinting.ImageSizeMode.AutoSize; 
    picBox.Image = Resources.Logo; 
    this.Controls.Add(picBox); 

    // Add the label to the ReportHeaderBand band. 
    tmBand.Controls.Add(picBox); 
} 

您可以通過如下報告的對象置於控制:

// Place the chart onto a report footer 
    rep.Bands[BandKind.ReportHeader].Controls.Add(picBox); 

參考:
How to create a report dynamically in the WinForms application

+0

我編輯我的職務。對不起,不要發佈完整的代碼。事實上,我做的和你一樣,我想。我只是不知道如何獲得右邊框上的XRPictureBox(alignment = right)。感謝您的快速回答。 – Sebi

+0

嘗試將面板添加到報告標題,然後將此圖片控件添加到它..然後嘗試在打印事件之前使用以獲取放置位置。 XRControls的Dock屬性可能是絕對的。 –

+0

問題是我不能得到點的地方。 BeforePrint事件只是給我一個PrintAction和一個取消。我怎樣才能得到ReportHeaderBand右側的位置爲我的XRPictureEdit設置?沒有對齊性質:-( – Sebi

相關問題