Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 文档截面宽度_C#_Migradoc - Fatal编程技术网

C# 文档截面宽度

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

我想要一个在MigraDoc中设置相对列宽的方法,我找到了这个主题。问题是,它对我不起作用。我从那篇文章中复制了确切的代码:

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()//