Question

i want to know how to delete the buttons "one page", "two pages", etc, and "page" in printPreviewDialog? i use C++ windows forms visual studio 2012. Thanks

Was it helpful?

Solution

PrintPreviewDialog is just a boilerplate implementation of a dialog that uses the PrintPreviewControl. You are supposed to implement your own dialog if you want your own design.

Nevertheless, this can be messed with in .NET. These buttons are private members of the class so you can't access them in your own code. Reflection support in .NET provides a backdoor, you can get to private fields with BindingFlags::NonPublic. Make that look similar to this (using the default names):

using namespace System::Reflection;
...
    Form1(void)
    {
        InitializeComponent();
        array<String^>^ names = gcnew array<String^> {"onepageToolStripButton", 
            "twopagesToolStripButton", "threepagesToolStripButton", 
            "fourpagesToolStripButton", "sixpagesToolStripButton",
            "separatorToolStripSeparator1"};
        for (int ix = 0; ix < names->Length; ix++) {
            FieldInfo^ fi = printPreviewDialog1->GetType()->GetField(names[ix], 
                BindingFlags::NonPublic | BindingFlags::Instance);
            ToolStripItem^ item = safe_cast<ToolStripItem^>(fi->GetValue(printPreviewDialog1));
            delete item;
        }
   }

Looks like this at runtime:

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top