【发布时间】:2015-02-18 06:07:43
【问题描述】:
我正在尝试创建一个自定义错误对话框,左侧有一个红色 x。以下是我的代码;
using JohnsonControls.FieldBusFDD.Properties;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace JohnsonControls.FieldBusFDD
{
public class ErrorDialog : Dialog
{
public static bool ShowDialog(string text, string title)
{
Form prompt = new Form();
prompt.Width = 435;
prompt.Height = 122;
prompt.FormBorderStyle = FormBorderStyle.FixedDialog;
prompt.Text = title;
prompt.StartPosition = FormStartPosition.CenterScreen;
PictureBox image = new PictureBox();
image.Image = Resources.red_x;
image.Location = new Point(10, 10);
image.Size = new Size(50, 50);
Label textLabel = new Label() { Left = 60, Top = 10, Width = 350, Text = text };
Button confirmation = new Button() { Text = "Ok", Left = 300, Width = 100, Top = 52 };
confirmation.Click += (sender, e) => { prompt.Close(); };
confirmation.DialogResult = DialogResult.OK;
prompt.Controls.Add(image);
prompt.Controls.Add(confirmation);
prompt.Controls.Add(textLabel);
prompt.AcceptButton = confirmation;
return prompt.ShowDialog() == DialogResult.OK ? true : false;
}
}
}
该文件存储在项目资源中,编译正常但不显示图像。
【问题讨论】:
-
您确定代码不适合您吗?我只是查看了代码并设法运行代码,并且能够获得带有指定图像(jpg文件)的对话框。我根本没有改变你的代码。您确定
red_x是正确的图像吗?您通过尝试使用图像查看器查看来验证这一点。 -
@fujiFX 是的,.png 不支持吗?
-
我猜图片的像素太大了?试试
image.SizeMode = PictureBoxSizeMode.Zoom;。 -
@ripple,这行得通。创建一个答案,我会选择它。谢谢!
标签: c# winforms picturebox