在c#中为picturebox添加click事件的动作

时间:2016-05-20 01:10:11

标签: c# events click picturebox

我得到了一个pictureboxe并尝试添加一个动作来更改背景图像在点击事件发生时,但没有动作。所以,这是代码:

pieces bishopBB = new pieces();        
public Form1()
        {              
         // object of picturebox
            bishopBB.Location = new Point(300, 455);
            bishopBB.Parent = this;
            bishopBB.Click += new System.EventHandler(pictureboxes_Click)
            InitializeComponent();
        }
private void pictureboxes_Click(object sender, EventArges e)
       {
            backgroundImage = Properties.Resources.black;
       }

3 个答案:

答案 0 :(得分:0)

要更改PictureBox控件的当前图像,您需要引用该控件并引用BackgroundImage属性(而不是'backgroundImage'):

@echo off
setlocal EnableDelayedExpansion

rem Get a CR control-char
for /F %%a in ('copy /Z "%~F0" NUL') do set "CR=%%a"

set /a time=0
cls
:up
echo/
echo Time: %time%
set /P "=Press "s" to start: " < NUL
CHOICE /c:s /n

:run1
set /a time=%time%+1
set /P "=Time: %time%, press "p" to pause:!CR!" < NUL
CHOICE /c:px /n /t 1 /d:x > nul
if errorlevel 2 goto run1
echo/
goto up

要更改表单的背景图片:

$(document).on('click', '.someDropdown', function(e) {
   $(this).append('<option class="someClass" value="foo">Foo</option>');
});

答案 1 :(得分:0)

要执行此操作,您可以使用图片框的on_click属性。然后,您可以使用类似picbox.image =无论图像位置是什么

答案 2 :(得分:0)

查看名称和其他指标,我会假设(并希望)<Image style={styles.logo} source={{uri: 'https://xxx.xxx.com/abc.jpg'}}/> 很多 pictureboxes_Click常用点击处理程序。

因此,要访问已点击的内容,您需要投射 PictureBoxessender,然后设置PictureBox

BackgroundImage

虽然您的private void pictureboxes_Click(object sender, EventArges e) { ((PictureBox)sender).BackgroundImage = Properties.Resources.black; } 拼写编译,但我有点惊讶。正确的拼写backgroundImage是指当前的类,通常是BackgroundImage,它也应该显示,除非您的Form已经有黑色背景..

相关问题