C# 文档截面宽度
我想要一个在MigraDoc中设置相对列宽的方法,我找到了这个主题。问题是,它对我不起作用。我从那篇文章中复制了确切的代码:C# 文档截面宽度,c#,migradoc,C#,Migradoc,我想要一个在MigraDoc中设置相对列宽的方法,我找到了这个主题。问题是,它对我不起作用。我从那篇文章中复制了确切的代码: Section section = document.AddSection(); section.PageSetup.PageFormat = PageFormat.A4; int sectionWidth = (int)(section.PageSetup.PageWidth - section.PageSetup.LeftMargin - section.PageS
Section section = document.AddSection();
section.PageSetup.PageFormat = PageFormat.A4;
int sectionWidth = (int)(section.PageSetup.PageWidth - section.PageSetup.LeftMargin - section.PageSetup.RightMargin);
int columnWidth = sectionWidth / 2;
但是,如果我在代码中插入一个断点(就在int columnWidth=…
之后),它表示节页宽度为零:
很明显,从截面宽度得到的所有东西,也都变成了零。但是为什么呢?如您所见,
PageFormat
已正确设置为“A4”。我不明白…我设法找到了一个解决方案(有点巧合)。这篇文章描述了section.PageSetup
中的一个类似问题。解决方案是在修改默认页面设置之前创建默认页面设置的克隆。新代码如下所示:
Section section = document.AddSection();
section.PageSetup = document.DefaultPageSetup.Clone(); // <-- This has been added
section.PageSetup.PageFormat = PageFormat.A4;
int sectionWidth = (int)(section.PageSetup.PageWidth - section.PageSetup.LeftMargin - section.PageSetup.RightMargin);
int columnWidth = sectionWidth / 2;
Section节=document.AddSection();
section.PageSetup=document.DefaultPageSetup.Clone()//