문제

시스템을 수정하려고합니다. Printing.Printing.PrinterSettings 객체가 사용자에게 표시된 후에 시스템이 표시된 후에 PrintDialog에서 얻을 수 있습니다. PrinterSettings 객체에서 속성 값을 변경할 수는 있지만 대화 상자가 표시된 후 대화 상자가 표시된 상태에서 변경 사항이 없었습니다.

여기에서 제가 의미하는 것의 예입니다.

//Show the printdialog and retreive the printersettings    
var printDialog = new PrintDialog();
if (printDialog.ShowDialog() != DialogResult.OK) 
            return;
var printerSettings = printDialog.PrinterSettings;

//Now modify the printersettings object
printerSettings.ToPage = 8;
.

이제 인쇄를 위해 PrinterSettings 객체를 사용합니다. 3 번째 파티 DLL aspose.words를 사용합니다. 단어를 인쇄해야하지만 문제가되지 않는 것 같습니다. 대화 상자가 표시된 후에 모든 설정이 이미 프린터에 커밋되어 프린터를 변경하지 않은 것처럼 보입니다. 이것이 일하는 방법에 대한 아이디어는 무엇입니까?

편집 :이 문제에 대한 몇 가지 해결 방법이 있습니다. 내가 여기서 원하는 것은 이러한 특정 질문에 대한 답을 얻는 것입니다. 대화 상자가 표시된 후 PrinterSettings 객체를 변경하고 이러한 변경 사항을 인쇄 할 수있는 것입니다. 누군가 가이 작업을 수행 할 수있는 방법 만 알고 있다면 (인쇄에 사용할 API를 결정할 수있는 API를 결정할 수 있습니다. Printersettings 객체가 사용되는 한 중요하지 않습니다), 매우 감사 할 것입니다.

도움이 되었습니까?

해결책

당신의 질문이 왜 아래로 투표를 얻었는지 확실하지는 않습니까 ????

anyhow, printDialog (귀하의 질문에 대답 할 수도 있고 대답하지 않을 수도 있음)로 알아 차리는 몇 가지 사항.

첫 번째 일은 Windows COM 대화 상자의 래퍼 클래스 일뿐입니다.

[DllImport("comdlg32.dll", CharSet=CharSet.Auto, SetLastError=true)]
        public static extern bool PrintDlg([In, Out] NativeMethods.PRINTDLG lppd);
.

및 두 번째, 그리고 가장 중요한 것은 귀하에게 질문을 참조하여 다음과 같습니다. PrintDialog 클래스에는 printDLG 호출을 닫은 후 호출되는이 루틴이 있습니다

if (!UnsafeNativeMethods.PrintDlg(data))
                return false;

            IntSecurity.AllPrintingAndUnmanagedCode.Assert();
            try { 
                UpdatePrinterSettings(data.hDevMode, data.hDevNames, data.nCopies, data.Flags, settings, PageSettings); 
            }
            finally { 
                CodeAccessPermission.RevertAssert();
            }
.

. ...에 .

// VSWhidbey 93449: Due to the nature of PRINTDLGEX vs PRINTDLG, separate but similar methods 
// are required for updating the settings from the structure utilized by the dialog.
// Take information from print dialog and put in PrinterSettings
private static void UpdatePrinterSettings(IntPtr hDevMode, IntPtr hDevNames, short copies, int flags, PrinterSettings settings, PageSettings pageSettings) {
        // Mode 
        settings.SetHdevmode(hDevMode);
        settings.SetHdevnames(hDevNames); 

        if (pageSettings!= null)
            pageSettings.SetHdevmode(hDevMode); 

        //Check for Copies == 1 since we might get the Right number of Copies from hdevMode.dmCopies...
        //this is Native PrintDialogs
        if (settings.Copies == 1) 
            settings.Copies = copies;

        settings.PrintRange = (PrintRange) (flags & printRangeMask); 
    }
.

여기에 다소 흥미로운 상호 작용이 있습니다 (PrinterSettings.topage를 설정하는 것을 염두에두고 있음) :

public PrinterSettings PrinterSettings {
   get { 
        if (settings == null)
        {
            settings = new PrinterSettings(); 
        }
        return settings; 
    } 
    set {
        if (value != PrinterSettings) 
        {
            settings = value;
            **printDocument = null;**
        } 
    }
} 
.

및 그 다음

public PrintDocument Document {
            get { return printDocument;}
            set {
                printDocument = value; 
                **if (printDocument == null)
                    settings = new PrinterSettings();** 
                else 
                    settings = printDocument.PrinterSettings;
            } 
        }
.

나는 알고있는 직접적인 대답이 아닙니다. 그러나 나는 그것이 작동하지 않는 이유의 올바른 방향으로 당신을 지적해야한다고 생각합니다. 대화의 사용 중에는 완료시 재창조 될 때 변경 사항에 대한 설정을 행복하게 무효화 할 수 있지만 대화가 완료되면 설정을 변경하면 문서 인쇄 설정이 다시 설정 될 때까지 실제로 무효화됩니다. 이 작업을 수동으로 수행 할 수도 있고, 일반적인 내부 / 개인 방식으로 M $의 LOCH \ KED가 많을 수 있습니다.

물론 (나는 알고 있지 않다) 통화가 끝난 후에 윈도우를 사용하기 만하면, 필요한 경우 자신의 래퍼를 짓기 위해 위의 전화 번호를 빌드하기 위해 위의 API 위조만을 사용하기 위해 옵션이 있습니다.

행운을 빈다.

다른 팁

adbode 설명서 :

AsposeWordsPrintDocument awPrintDoc = new AsposeWordsPrintDocument(doc);
awPrintDoc.PrinterSettings = printDlg.PrinterSettings;
.

그래서 Yuor 수정 된 Printersettings 객체를 인쇄하려는 Word 문서에 전달할 수있는 것 같습니다.이 작품인지 알려주시겠습니까?

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