通过单击TImage组件更改图片 - Delphi [英] Changing pictures by clicking on the TImage component - Delphi
问题描述
我想更改图片加载到 Image1 - 从一个名为 1active.png 的第二个名为 1inactive.png ,反之亦然点击Image1组件上的。
I want to change picture loaded into Image1 - from one called 1active.png to second called 1inactive.png and vice versa by clicking on the Image1 component.
有没有办法做到这一点?
Is there any way to do it?
推荐答案
成分:
- 1布尔值变量
- 1 TImage组件
- 1行添加到表单OnCreate事件处理程序
- 1 TImage.OnClick事件处理程序
- 1 boolean variable
- 1 TImage component
- 1 line added to form OnCreate event handler
- 1 TImage.OnClick event handler
说明:
1)在表单声明的私有部分中创建一个布尔变量。对于此示例,请调用此变量fImageActive。
1) Create a boolean variable in the private section of your form declaration. For this example, call this variable fImageActive.
private
fImageActive : boolean;
2)从表单设计器中,在表单上删除(或选择一个现有的)TImage组件并选择onClick事件,双击切换到编辑。然后添加以下代码:
2) From the form designer, drop (or select an existing) TImage component on the form and select the onClick event, and double click to switch into editing. Then add the following code:
fImageActive := not fImageActive;
if fImageActive then
Image1.Picture.LoadFromFile('1active.png')
else
Image1.Picture.LoadFromFile('1inactive.png')
3)从表单设计器中,找到picture属性并单击省略号为初学者加载1active.png文件。
3) From the form designer, find the picture property and click the ellipsis to load the 1active.png file for starters.
4)点击表格,找到名为OnCreate的事件,双击并添加以下代码(这将设置初始状态):
4) Click on the form, find the event named "OnCreate", double click and add the following code (this will set the initial state):
fImageActive := true;
这篇关于通过单击TImage组件更改图片 - Delphi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!