gpt4 book ai didi

C# - DisplayDialog() 不适用于 FileSave 和拖/放

转载 作者:行者123 更新时间:2023-12-02 15:47:07 31 4
gpt4 key购买 nike

我使用一些屏幕截图代码成功构建了,并且可以进行拖放操作(但没有代码),并且我尝试在文件后在表单上显示一条消息保存成功,或者拖放太多文件。我不想使用 MessageBox.Show (即使如果我替换代码,此方法也有效),因为我想使用复选标记图片和按钮来打开屏幕截图位置的文件。我的问题是保存屏幕截图后,from#.designer.cs 中的一行崩溃了。我已经到处寻找如何解决这个问题,但没有任何帮助。我不注意触摸 Form3.Designer.cs 文件,因为注释说不要这样做。下面列出了我的代码。

表格 1 中的屏幕截图/屏幕截图代码:

        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();
}

任何帮助将不胜感激。

最佳答案

您链接到的屏幕截图上的错误消息显示

InvalidOperationException

Additional information: failed to initialize because the CategoryName is missing.

Part of the screenshot provided by OP

Microsoft 似乎忘记在 EndInit() 上记录该异常。打电话,但这不是第一个。

因此,在 performanceCounter1 上,我假设其类型为 PerformanceCounter您需要为该属性提供一个值 CategoryName .

您无需手动修改 Form3.Designer.cs 文件即可完成此操作。相反,请在设计器中打开 Form3,选择 performanceCounter1 并从列表中选择一个值,如以下屏幕截图所示:

Select a value from the list of performance counters

关于C# - DisplayDialog() 不适用于 FileSave 和拖/放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45917698/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com