如何在单一功能中调用图片框中的所有Click事件 [英] How can i call all Click Events in a picturebox at Single Function

查看:57
本文介绍了如何在单一功能中调用图片框中的所有Click事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Picturebox中插入了一张图像(印度地图),在该图像中,单击它时,文字(城市名称)已被选中(更改颜色).我所做的是,插入了图像(圆形)单击城市附近的图片框并在标签中键入城市名称,当我单击圆形"图像然后更改标签的颜色(城市名称)时,我做错了(每次单击事件中的全部).我必须在单个函数中将其触发,并调用picturebox id

I had Inserted a image(India map)in to Picturebox,In that image the texts (City names)have to Selected(Change the Color) When Clicking on it.That i had done is, Inserted images(Round Shaped)near the cities to the pictureboxes and Typed the name of cities in labels,when i am clicked the Round Shape image then change the color of label(name of cities)but i had done is wrong(All in each click Events). i have to fire it in a single function and Call that picturebox id

推荐答案

您不知道.

响应于系统中发生的某些事件(通常是用户输入,计时器或与数据相关的事件),会引发单击(以及所有其他)事件.您通常不会在代码中引发系统事件.

您可以将用于处理事件的代码放入一个单独的方法中,然后从Click事件处理程序以及您的代码中调用它们以模拟click.

您想实现什么,您认为这将是一个好主意?如果我们知道这是什么,可能会有更好的方法来处理它! :laugh:
You don''t.

Click (and all other) events are raised in response to something happening in the system - normally user input, timer or data related. You do not as a normal event raise system events in your code.

You can put the code for handling the event into a separate method, and then call that both from the Click event handler, and from your code to emulate the click.

What are you trying to achieve, that you think this would be a good idea? There may be a better way to handle it, if we knew what it was! :laugh:


首先,您完全不需要PictureBox.此控件仅对非常简单且几乎"静态的东西有用.许多人尝试使用可能具有交互性或动画性的东西,但这种控制方法根本没有带来任何好处,仅带来了额外的实现麻烦以及性能和资源的浪费.

您只需要使用Control,派生您的类并覆盖直接在其中渲染图片的OnPaint.这样,您可以将背景图与一些热点元素组合在一起,使它们可以单击.

有关更多详细信息,请参阅我过去的解决方案如何我要从旧图纸上清除面板吗? [
To start with, you don''t need PictureBox at all. This control is only good for something very simple and "almost" static. Many try to use if the something interactive or animated, which is possible, but then this control presents no benefits at all, only additional implementation hassles and waste of performance and resource.

You need to use just the Control, derive your class and override OnPaint where you render your picture directly. This way, you can combine your background map with some hot spot elements which you can make clickable.

For more detail, please see my past solution How do I clear a panel from old drawing[^].

Everything else depends on the graphical information you can obtain.

—SA


将其放在单个功能上,然后在每个按钮上调用它.

-爱德华
Put it on a single Function then call it on each of the buttons.

-Eduard


这篇关于如何在单一功能中调用图片框中的所有Click事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆