我正在使用 Visual Studio 2015 开发 C# 应用程序 它有 2 种形式,在 form1 上我有一个按钮,当点击 显示 form2,现在我想做的是打印 form2 完全加载后,我正在使用 printform 控件 在 form2 上执行此操作,如果我在 form_load 事件中使用它 它打印一个空白页然后显示表格,我有 还尝试在 form_Shown 上使用它,但是这会打印一个框 元素在哪里,但不是元素本身,就好像它们有 没有完成加载,可能有更好的方法来做到这一点 但我是 C# 的新手,所以还在学习
下面是我在 form2 上的代码示例
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MyApp
{
public partial class Form2: Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
this.Shown += new System.EventHandler(this.Form2_Shown);
}
private void Form2_Shown(object sender, EventArgs e)
{
printForm.Print();
}
}
}
最佳答案
Shown 事件触发有点过早。窗体的框架和背景已绘制,其余部分稍后再绘制。绘画是一项低优先级任务,仅在无需执行其他操作时才会执行,首先触发 Shown 事件。
解决方法很简单,只需调用窗体的 Update() 方法让窗体完成 self 更新。修复:
private void Form2_Shown(object sender, EventArgs e)
{
this.Update();
printForm.Print();
}
关于c# - 检查窗体上的所有元素是否已完全加载 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36387856/