我正在尝试打印富文本框的内容.我通过以下方式做到这一点:
TextRange从中获得一个FlowDocument.FlowDocument使用更小的字体创建一个新的TextRange.FlowDocument到打印机.我的问题是,字体似乎没有改变.我希望它下降到8号.相反,它仍保持固定的大小.这是我的代码:
private void button_Print_Click(object sender, RoutedEventArgs e)
{
IDocumentPaginatorSource ps = null;
FlowDocument fd = new FlowDocument();
PrintDialog pd = new PrintDialog();
Paragraph pg = new Paragraph();
Style style = new Style(typeof(Paragraph));
Run r = null;
string text = string.Empty;
// get the text
text = new TextRange(
this.richTextBox_Info.Document.ContentStart,
this.richTextBox_Info.Document.ContentEnd).Text;
// configure the style of the flow document
style.Setters.Add(new Setter(Block.MarginProperty, new Thickness(0)));
fd.Resources.Add(typeof(Paragraph), style);
// style the paragraph …Run Code Online (Sandbox Code Playgroud) 目前我正在 Atmel 的 AVR Studio 7.0(基于 VS2015-shell)工作,当涉及到 IDE 运行时创建的临时文件时,它有一些奇怪的行为。在进一步讨论之前,我想说我对 Atmel Studio 的根本问题不感兴趣,对于不同的网站来说这将是不同的问题。相反,我将询问如何在管理存储库中的文件方面处理短期内的行为。
所以无论如何,我会解释发生了什么,让大家了解我正在处理的事情。在 Atmel Studio 中创建的每个 C++ 项目都有一个.atsln随附的解决方案(文件)。然后,每个解决方案都有一个.atsuo文件。.atsuo每次解决方案关闭时,该文件都会被修改。我的问题是,我试图将所有内容签入存储库,但签入该文件实际上没有意义,因为即使我只打开项目一次,运行它,然后关闭它,它也会发生变化......
现在,让我进入真正好的部分...尽管我不想签入.atsuo文件,但我被迫...如果.atsuo文件被删除,那么解决方案文件将不再工作,我会收到“Atmel AVR Studio 7.0 已停止工作...”然后崩溃。因此,如果我不想每次都构建新的解决方案,就好像我被迫签入该文件!但我不想,因为它一直在变化!
我到底该怎么做才能在 Git 中管理这个文件呢?
更新
归根结底,更改的内容.atsuo不会造成任何损害。
背景
我正在编写一些执行以下操作的软件:
当我第一次单击“开始”时,一切正常,但之后就不行了。第一次单击开始时,我得到如下输出:
这看起来不错,没有什么问题。但是,当我第二次单击“开始”时,我得到以下输出。
现在,我相信我知道为什么会发生这种情况。据我所知,从我第一次单击“开始”开始,我的观察者就从未取消订阅,因此所有内容都会打印两次。单击开始按钮时,会发生以下情况:
/// <summary>
/// Starts the test.
/// </summary>
/// <param name="sender">The "start" button.</param>
/// <param name="e">Clicking on the "start" button.</param>
private void button_go_Click(object sender, RoutedEventArgs e)
{
var uiContext = SynchronizationContext.Current;
var results = Observable.FromEventPattern<TestResultHandler, TestResultArgs>(
handler => (s, a) => handler(s, a),
handler => this.myTest.Results += handler,
handler => this.myTest.Results -= handler)
.ObserveOn(uiContext)
.Subscribe(x => this.richTextBox_testResults.Document.Blocks.Add(new Paragraph(new Run(x.EventArgs.Results))));
// start running the test
this.runningTest = new Task(() => …Run Code Online (Sandbox Code Playgroud) 背景
所以我决定开始在某些C#程序中使用JSON而不是XML.当然,我发现的第一件事是Newtonsoft的JSON.NET.这似乎是在.NET世界中用于某些JSON解析的合理的事情,并且每个人都通过Microsoft提供的内置序列化程序建议它.这就是我决定使用的.到目前为止,我还没有能够反序列化任何东西,除了非常简单的例子,例如...... 这一个.
我试图将以下JSON反序列化为一个有意义的对象,我可以将其用于我的程序,但是每次我尝试这样做时应用程序都会崩溃.我对异常消息中发生的事情进行了非常含糊的解释.我没有得到一个行号或任何东西,只是说......
附加信息:无法将当前JSON数组(例如[1,2,3])反序列化为类型"JsonTest.testObjects",因为该类型需要JSON对象(例如{"name":"value"})才能正确反序列化.
要修复此错误,请将JSON更改为JSON对象(例如{"name":"value"})或将反序列化类型更改为数组或实现集合接口的类型(例如ICollection,IList),例如List从JSON数组反序列化.JsonArrayAttribute也可以添加到类型中以强制它从JSON数组反序列化.
也许它说我的第一个物体有问题?在进入子类之前,我没有在这里使用任何数组,不确定这里发生了什么.
{
"name":"myTest",
"testObjects":[
"testObject":
"name":"Operator Tests",
"index":1,
"description":"Test out the operator interface.",
"SubTests":[
"SubTest":
"name":"Display Test",
"index":4,
"description":"Testing for display faults.",
"Steps":[
"Step":
"name":"Configuration #1",
"Parameters":[
"Mode-A",
"Unit #1"
],
"Step":
"name":"Configuration #2",
"Parameters":[
"Mode-B",
"Unit #1"
],
"Step":
"name":"Configuration #3",
"Parameters":[
"Mode-C",
"Unit #1"
]
]
]
]
}
Run Code Online (Sandbox Code Playgroud)
好的,然后这里是反序列化代码.
Test newTest = null;
String testData = String.Empty;
// read the file
testData = File.ReadAllText("Test.json");
// de-serialize the JSON
newTest = JsonConvert.DeserializeObject<Test>(testData); …Run Code Online (Sandbox Code Playgroud)