Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
I want to remove Print Icon in print preview page ,for this I want source code.

What I have tried:

I didn't get the correct code, it show error.
Posted
Updated 14-Oct-22 4:07am

It's a little bit difficult to do this.
To show you how it could be done I created a new customized PrintPreviewDialog-Class (which inherits from the original PrintPreviewDialog) :
VB.NET
Public Class RMPrintPreviewDialog
    Inherits PrintPreviewDialog

    Property ShowPrintButton As Boolean
        Get
            Return myShowPrintButton
        End Get
        Set(value As Boolean)
            myShowPrintButton = value
            Me.Invalidate()
        End Set
    End Property
    Private myShowPrintButton As Boolean = False

    Protected Overrides Sub CreateHandle()
        MyBase.CreateHandle()

        For Each c As Control In Me.Controls
             If c.GetType Is GetType(ToolStrip) Then
                ts = c
                For Each m As Object In ts.Items
                    If LCase(m.name) = "printtoolstripbutton" Then
                        printButton = m
                    End If
                Next
            End If
        Next

    End Sub
    Private ts As ToolStrip
    Private printButton As ToolStripButton

    Protected Overrides Sub OnActivated(e As System.EventArgs)
        printButton.Visible = myShowPrintButton
        MyBase.OnActivated(e)
    End Sub

End Class


This Class has a new Property which allows you to switch the Button to "unvisible".
To do this you have to iterate (like it's shown inside the code) through the Controls from the Dialog to find first the Toolstrip and after this you have to iterate through the ToolStrip-Items to find the PrintButton. Now, when you have the Reference, you can switch it on or off ...
 
Share this answer
 
v2
Comments
Ralf Meier 17-Oct-22 2:30am    
Hi ...
I'm glad to see that you have accepted the solution.
If this answer is working for you please be so kind and rate it.
There does not seem to be any simple way of doing it with PrintPreviewDialog Class (System.Windows.Forms) | Microsoft Learn[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900