表单功能.需要帮助. [英] Form Functions. Help Needed.

查看:81
本文介绍了表单功能.需要帮助.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我正在为游戏设计计算器.因此,我决定尝试对计算器进行编码,以使其尽可能地易于使用.

我需要帮助的是以下内容;

根据按钮更改其他窗体的效果,请单击主窗体.
示例;

如果我有两种形式,MainForm和SubForm.在MainForm中,我有一个文本框txtTotal,两个按钮btnAdd和btnSubtract.

在子窗体中,我有一个名为txtValue的文本框,两个按钮btnOK和btnCancel.

如果单击了MainForm中的btnAdd,则将单击子窗体加载",并且单击btnOK时,txtValue的值将添加到txtTotal中.

所以txtTotal已经具有5的值,在txtValue(来自SubForm)中,我另外输入了5并单击确定"-txtTotal现在将其值更改为10.

但是,如果单击btnSubtract,则单击btnOK时,将加载SubForm Loads,并且从txtTotal中减去txtValue的值.

所以如果SubForm.txtValue和MainForm.txtTotal为5,则txtTotal现在将为0.


还想知道如何更改依赖于MainForm btns的图像.例如,btnAdd会将SubForm的背景设置为"C:\ Some location",而btnSubtract会将SubForm的背景设置为"C:\ Some other Location"


你们当中有人知道关于类和效果指南的有用链接吗? :)

Hello Everyone.

I''m working on a Calculator for a game. So i decided to try to code the calculator to be as user friendly as possible.

What i need help with is the following;

Changing the effects of another form dependent on the button i click on my mainform.
Example;

If i have two forms, MainForm and SubForm. In the MainForm i have a textbox, txtTotal, two buttons, btnAdd and btnSubtract.

In the SubForm i have a Textbox, named txtValue, two buttons, btnOK and btnCancel.

If the btnAdd from the MainForm is clicked, SubForm Loads and the value of txtValue will be ADD to the txtTotal when the btnOK is clicked.

So e.g. txtTotal already have a value of 5, in txtValue(from SubForm) i put in an additional 5 and hit ok - txtTotal will now change its value to 10.

However if the btnSubtract is clicked, SubForm Loads and the value of txtValue will be Subtracted from the txtTotal when the btnOK is clicked.

So e.g. txtTotal will now be 0, if SubForm.txtValue and MainForm.txtTotal is 5.


Also would like to know how to change a image dependent on MainForm btns. Example the btnAdd will set the background of SubForm to "C:\Some location" and the btnSubtract will set the background of SubForm to "C:\Some other Location"


also does any of you know any useful links to a guide about Class''s and effects ? :)

推荐答案

方法是在子窗体中创建一个新事件:将其命名为NewValueAvailable或类似名称.还将字符串属性添加到返回TextBox值的子窗体.
您的Mainform在显示SubForm时会向其添加一个处理程序.

在子窗体中按下按钮时,将发出事件信号.
主窗体处理程序通过SubForm属性读取新值,并将其添加到总计中.


这样,子表单就不需要了解主表单的工作原理,反之亦然.
The way to do it is to create a new event in the subform: call it NewValueAvailable or similar. Also add a string Property to the subform which returns the TextBox value.
Your Mainform them adds a handler to it when it displays the SubForm.

When the button is pressed in the SubForm, it signals the event.
The main form handler reads the new value via the SubForm property, and adds it to the total.


This way, the subform does not need to know anything about how the main form works, and vice versa.


这篇关于表单功能.需要帮助.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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