我有一个成功的构建使用一些截图代码,并得到拖放工作(但没有代码从那里),我试图显示一条消息在文件保存成功后,或者如果您拖放太多文件后,形式为。我不想使用MessageBox.Show
(即使我替换代码,此方法也可以),因为我想使用复选标记图片和按钮来打开屏幕截图位置的文件。我的问题是屏幕截图保存后,from#.designer.cs
崩溃。我已经看遍了如何解决这个问题,并没有帮助。我不注意触摸Form3.Designer.cs
文件,因为评论说不要。我的代码列在下面。在表1C# - DisplayDialog()不工作FileSave和拖放
截图/屏幕截图代码:
private void saveScreenshotToolStripMenuItem_Click(object sender, EventArgs e)
{
// ** SAVE A SCREENSHOT *** (Working)
Bitmap bitmap = new Bitmap(this.Width, this.Height);
DrawToBitmap(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
bitmap.Save((boxFileName.Text) + "_ScreenCap.JPEG",ImageFormat.Jpeg);
// If i replace the following 2 lines with MessageBox.Show("FileSave successful"); it works fine. Why is this code not working????
Form3 f3 = new Form3();
f3.ShowDialog();
}
代码,在Form3.Designer.CS
// Form3
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 121);
this.Controls.Add(this.button1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.pictureBox1);
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(300, 150);
this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(300, 150);
this.Name = "Form3";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.Text = "ScreenCap Result";
this.Load += new System.EventHandler(this.Form3_Load);
/// the following line crashed
((System.ComponentModel.ISupportInitialize)(this.performanceCounter1)).EndInit();
// end line that crashed
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
这里崩溃是从的DragDrop代码:
void Form1_DragDrop(object sender, DragEventArgs e)
{
var files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (files.Length == 1)
{
/// WORKING
MessageBox.Show("Reading files from Drag and Drop not fully implimentd.");
}
else
{
// NOT WORING (crashes)
Form3 f3 = new Form3();
f3.ShowDialog();
}
任何帮助将是赞赏。
那么,什么异常导致它崩溃?文本告诉你什么? –
您可以在设计器中打开Form3.cs,还是会崩溃? –
@ThomasWeller号码成功编译。它只会在应用程序运行时事件触发时崩溃。 –