0

我只是想将另一个表单的背景图片设置为我添加的png文件图片资源

我的 MAstrategyBldrForm.cs 文件中有以下内容:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MAStrategyBuilder
{
    public partial class MAstrategyBldrForm : Form
    {

        private CrossPicsForm crossPic;

        public MAstrategyBldrForm()
        {
            InitializeComponent();

            crossPic = new CrossPicsForm();
        }

.... .... .... 稍后在同一文件中:

private void MAcrossPicButton_Click(object sender, EventArgs e)
{
    crossPic.BackgroundImage = (Bitmap) (Properties.Resources.ResourceManager.GetObject("Moving Avgs Cross.png"));
    crossPic.Show();
}

.... .... 在我的 CrossPicsForm.cs 文件中,我有:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MAStrategyBuilder
{
    public partial class CrossPicsForm : Form
    {
        public CrossPicsForm()
        {
            InitializeComponent();
        }
    }
}

一切都会编译,但是当我在 masterrategy... 表单中单击按钮控件时,会显示一个空白的 CrossPicsForm 窗口。该死!

4

1 回答 1

0

当您拼错资源名称时不会出现异常,ResourceManager 只返回 null 并且保持 BackgroundImage 属性不变。你这样做了,它通常被命名为“Moving_Avgs_Cross”,没有 .png 扩展名。

请改用资源设计器添加的属性。这应该类似于:

crossPic.BackgroundImage = Properties.Resources.Moving_Avgs_Cross;

使用 IntelliSense 助您跌入成功的陷阱。

于 2013-10-19T17:34:14.080 回答