无法更改pictureBox的背景图像

时间:2012-05-06 11:44:58

标签: c# winforms image picturebox

当我将鼠标悬停在图片框上时,我正试图更改图片框中的图像。我正在使用带有Windows窗体的visual c#2010 express。

以下是我目前的基本代码:

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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void pbMV_MouseHover(object sender, EventArgs e)
        {
            pbMV.BackgroundImage = My.Resources.mvhov;
            tbname.Text = "Hello";

        }

        private void pbMV_MouseLeave(object sender, EventArgs e)
        {
            tbname.Text = "";
        }



    }
}

在以下一行中,我对My

的使用提出了错误
pbMV.BackgroundImage = My.Resources.mvhov;
  

当前上下文中不存在名称“我的”

那么当我将鼠标悬停在图片框上时,我在尝试更改图片框的背景图片时做错了什么?

很抱歉,如果这看起来很基本,那么我对c#一无所知。 感谢。

1 个答案:

答案 0 :(得分:3)

C#没有VB.Net的My关键字。

相反,您可以直接访问Resources课程:

Properties.Resources.SomeResourceName