문제

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

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top