简体   繁体   English

无法更改pictureBox的背景图像

[英]Can not change the background image of a pictureBox

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. 我正在将Visual C#2010 Express与Windows窗体一起使用。

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#。]谢谢。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM