Search code examples
vb.netactivereports

Set Watermark in ActiveReports


I have created a Section Report using ActiveReports 9 Designer. I need to set watermark based on a flag. If flag is ON, watermark should be set for that particular page. If flag is OFF, watermark should be nothing.

I'm having the flag textbox and watermark image in group header. So I thought of toggling the watermark in GROUPHEADER1_BeforePrint of Report script.

Sub GroupHeader1_BeforePrint
    if(TxtFlg.text = "1") Then
        rpt.Watermark = imgWaterMark.Image
    else
        rpt.Watermark = nothing
    End If
End Sub

My problem is - the first page is skipping and it is continuing from next page. The 1st page watermark is displayed in 2nd page, 2nd page watermark is displayed in 3rd page and so on. Why is it displaying like this ?

Can anyone please help me . Thanks in advance .


Solution

  • If we want to display watermark in active report based on conditions its bit difficult with watermark property of the report. Instead we can use DrawText which appears similar to watermark on the report.

    Code goes like this :

    Sub GroupHeader1_BeforePrint
        if(TxtFlg.text = "1") Then
            Me.rpt.CurrentPage.ForeColor = Color.FromArgb(80, 128,128,128)
            Me.rpt.CurrentPage.Font = New Font("Arial", 45F)
            Me.rpt.CurrentPage.DrawText("DRAFT", 0.489F, 5F, 8, 2)
        else
            Me.rpt.CurrentPage.ForeColor = Color.FromArgb(80, 255, 255, 255)
            Me.rpt.CurrentPage.Font = New Font("Arial", 20F)
            Me.rpt.CurrentPage.DrawText("", 1.5F, 3F, 2, 2)
        End If
    End Sub