无法更改pictureBox的背景图像

时间:2022-04-28 05:54:20

I am trying to change the image in a picturebox when I hover the mouse over it. I am using visual c# 2010 express with windows forms.

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

Here is the basic code I have at the moment:

这是我目前的基本代码:

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 = "";
        }



    }
}

In the following line it gives me an error in regard to the use of My .

在下面的行中,它给出了关于My的使用的错误。

pbMV.BackgroundImage = My.Resources.mvhov;

The name 'My' does not exist in the current context

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

SO what am I doing wrong in trying to change the background image of the picture box when I hover my mouse over it?

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

Sorry if this seems basic too you I have next to no knowledge in c#.] Thanks.

对不起,如果这看起来很基本,那我就不知道c#了。]谢谢。

1 个解决方案

#1


3  

C# does not have VB.Net's My keyword.

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

Instead, you can access the Resources class directly:

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

Properties.Resources.SomeResourceName

#1


3  

C# does not have VB.Net's My keyword.

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

Instead, you can access the Resources class directly:

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

Properties.Resources.SomeResourceName