例如有四个文本框,分别为进价、数量、售价、利润
如何让其填完前三个文本框,第四个文本框就能自动出值呢?
vb怎样让文本框自动求值
答案:4 悬赏:30 手机版
解决时间 2021-02-02 11:32
- 提问者网友:留有余香
- 2021-02-02 01:56
最佳答案
- 五星知识达人网友:动情书生
- 2021-02-02 02:43
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub
Private sub lirun()
if text1.text<>"" and text2.text<>"" and text3.text<>"" then
text4.text=(val(text1.text)-val(text2.text))*val(text3.text)
end if
End sub
Private Sub Text1_Change()
lirun
End Sub
Private Sub Text2_Change()
lirun
End Sub
Private Sub Text3_Change()
lirun
End Sub
text1为售价,text2为进价,text3为数量,text4为利润
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub
Private sub lirun()
if text1.text<>"" and text2.text<>"" and text3.text<>"" then
text4.text=(val(text1.text)-val(text2.text))*val(text3.text)
end if
End sub
Private Sub Text1_Change()
lirun
End Sub
Private Sub Text2_Change()
lirun
End Sub
Private Sub Text3_Change()
lirun
End Sub
text1为售价,text2为进价,text3为数量,text4为利润
全部回答
- 1楼网友:骨子里都是戏
- 2021-02-02 06:01
可以在第三个文本框中加入LostFoucus事件(建议),或KeyPressed事件
离开第三个文本框时就开始运算
利润=(售价-进价)*数量
- 2楼网友:人類模型
- 2021-02-02 05:17
好东东!可惜我e文也不太好...给你翻译一点:
先在左上角把类给下载了,然后,使用方法----
this sample presents a small class that allows you to tile a bitmap into the background of a textbox. note that the technique only works on multi-line text boxes, as the drawing of single-line textboxes is done in a different way and cannot be easily overridden in code.
这例子向你展示怎么用一个类给textbox贴上背景图片。要注意的是,这种方法只能用在多行文本框上。至于单行文本框,要用另外一种方法,并且不是那么容易用代码实现的。
......(中间省略无数行)
the ctextboxbackground class
to make this easier to use, i've wrapped the code up in a simple class. this class has the following methods:
为了让用着方便些,我把代码都打包到一个简单的类里面了。这个类有下面这些方法:
attach(byval hwnda as long)
attaches the class to the multi-line text box with the specified hwnd. don't call this method until you've set up the background picture first.
让类与多行文本框连接(attach),需指定hwnd。你必须先设置好背景图片,才能call这个方法。
detach()
detaches from the class so the text box painting goes back to normal. called automatically when the textbox is destroyed.
取消连接,使文本框会到原来的模式。文本框被摧毁(例如unload窗体)时会自动执行。
setbackdrop(pic as ipicture)
sets the background bitmap from a standard vb picture object (for example, a stdpicture returned from loadpicture or the picture returned by a picturebox's picture property.
用一个标准的vb图片对象(例如一个由loadpicture()函数返回的stdpicture对象,或者picturebox的picture 属性)设置背景位图
tilearea(byval hdcto as long, byval x as long, byval y as long, byval width as long, byval height as long)
the bitmap tiling function is exposed to allow you to tile the bitmap onto any other objects with a hdc property. this is used in the second sample form in the demo to tile the background of the form.
这个方法能让你通过把位图贴到其它对象上,只要你能提供它的hdc属性。在示例里的第二个窗体有用这个方法贴窗体背景的例子。
tileoffsetx() as long
gets or sets the initial x offset in the bitmap to start tiling from.
返回或者设置位图绘制起始点的x坐标。
tileoffsety() as long
gets or sets the initial y offset in the bitmap to start tiling from.
返回或者设置位图绘制起始点的y坐标。
to use it, first add a textbox to a form, set it to multi-line mode and then create a form level instance of the ctextboxbackground class (here i'm assuming it's called m_clargetextboxback). then set the background picture and attach it to the text box as follows:
使用的时候,先放上一个textbox,设置为multi-line模式;然后声明一个模块级的ctextboxbackground实例(我假定是那实例叫m_clargetextboxback)。最后像下面那样设置背景图片并把它贴到textbox上:
set m_clargetextboxback = new ctextboxbackground
m_clargetextboxback.setbackdrop loadpicture(app.path & "\back.bmp")
m_clargetextboxback.attach txttest.hwnd
要考四级了,算是练习吧...555...祝我好运...
- 3楼网友:像个废品
- 2021-02-02 03:42
'text1为进价,text2为售价,text3为数量,text4为利润
Private Sub Countd()
Text4.Text = (Val(Text2.Text) - Val(Text1.Text)) * Val(Text3.Text)
End Sub
Private Sub Text1_LostFocus()
Countd
End Sub
Private Sub Text2_LostFocus()
Countd
End Sub
Private Sub Text3_LostFocus()
Countd
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯