Visual Basic中的文本框和保存按钮 [英] Textbox and Save button in visual basic

查看:200
本文介绍了Visual Basic中的文本框和保存按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是Visual Basic的新手,所以我在这里有疑问.

我创建了一个表单,其中有3个文本框,分别是:名称,姓氏和地址.在下面,用户必须单击一个按钮,该信息将被保存到驱动器C.

Hello, I am new to Visual Basic so I have so me questions here.

I have created a form where there are 3 textboxes namely: Name, Last Name and Address. And below there is a button where the user has to click, the information will be saved to drive C.

推荐答案

有两种方法可以解决您的问题. br/>
1)方法优先:

(a)U应该更改保存"按钮的属性以在表单加载事件时启用false(或在设计时从VB 6.0中的属性窗口将保存"按钮的启用属性设置为False)

(b)然后仅在全部1或2或全部3的文本框属性(即名称,姓氏和地址文本框更改事件)下启用保存"按钮属性.
这样,您可以停止用户&验证是否有用户填充文本框,并且您可以停止用户单击保存按钮而不填充文本框,并且不会有空记录将被插入数据库.

2)方法二:
(a)U也可以更改保存"按钮的属性,以在运行时启用false.通过将以下代码放在表单加载事件上.

(假设您的保存按钮"名称为btnSave)


There are 2 ways to solve ur problem..

1) Method First:

(a)U should change the Property of "Save" Button to enable false at the time of form load event (or set the "Save" Button enable property to False at design time from the property window in VB 6.0)

(b) Then enable the "Save" Button Property only when Textbox properties of all 1 or 2 or all 3 (i.e. Name, Last Name & Address textbox changing event)

By this u can Stop the user & validate that whatever user fill the Text box and u can stop user to click on save button without filling the Textboxes and there will be no empty recorded will be inserted into the Database.

2) Method Second:
(a) U can also change the Property of "Save" Button to enable false at the Run-time. By placing the following code on the form load event.

(Assuming that ur Save Button name is btnSave)


Form Load()

   btnSave.enable=False

End Sub




(b)将以下代码放在TextBox更改事件上
(假设您的姓名,姓氏和地址文本框名称分别为txtName,txtLName和ampxAddress)






(b) Placed following code on the TextBox(s) changing event
(Assuming that ur Name, Last Name and Address Textboxes names are txtName, txtLName & txtAddress respectively)



Private Sub txtName_Changing(ByVal sender As Object, ByVal e As System.EventArgs)

        If Not txtName.Text = "" Then
            btnSave.Enabled = True
        End If

Private Sub txtLName_Changing(ByVal sender As Object, ByVal e As System.EventArgs)

        If Not txtLName.Text = "" Then
             btnSave.Enabled = True
        End If

Private Sub txtAddress_Changing(ByVal sender As Object, ByVal e As System.EventArgs)

        If Not txtAddress.Text = "" Then
             btnSave.Enabled = True
        End If



使用以下方法之一解决您的问题.



Use One of these method to solve ur problem.


再次问好,

现在您有3种不同的工具(不是文本框),即combobox,numecicupandown和maskedtextbox
保留您的保存"按钮,将属性设置为False
地方代码如下:

1)对于组合框:(假设您的组合框是"cboDrawer")

私有子cboDrawer_SelectedIndexChanged(ByVal发送者作为System.Object,ByVal e作为System.EventArgs)处理cboDrawer.SelectedIndexChanged
如果不是cboDrawer.Text = cboDrawer.SelectedText然后
btnSave.Enabled = True
如果结束
结束子


2)对于Numecicupanddown :(假设您的盒子是"NupDown")

私有子NupDown_ValueChanged(ByVal发送者作为System.Object,ByVal e作为System.EventArgs)处理NupDown.ValueChanged
如果不是NupDown.Increment = Nothing then
btnSave.Enabled = True
如果结束
结束子


3)对于Maskedttextbox :(假设您的盒子是"mtxtValue")

私有子mtxtValue_LostFocus(ByVal发送者作为对象,ByVal e作为System.EventArgs)处理mtxtValue.LostFocus
如果不是mtxtValue.Text ="然后
btnSave.Enabled = True
如果结束
结束子


试试这个&祝你好运......
Hello again,

Now u have 3 different tools (which are not text boxes) i.e. combobox, numecicupandown and maskedtextbox
remain ur "Save" Button enable property to False
palce following codes:

1) For Combobox: (Assuming that ur combo box is "cboDrawer")

Private Sub cboDrawer_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboDrawer.SelectedIndexChanged
If Not cboDrawer.Text = cboDrawer.SelectedText Then
btnSave.Enabled = True
End If
End Sub


2) For Numecicupanddown: (Assuming that ur box is "NupDown")

Private Sub NupDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NupDown.ValueChanged
If Not NupDown.Increment = Nothing Then
btnSave.Enabled = True
End If
End Sub


3) For Maskedttextbox: (Assuming that ur box is "mtxtValue")

Private Sub mtxtValue_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles mtxtValue.LostFocus
If Not mtxtValue.Text = "" Then
btnSave.Enabled = True
End If
End Sub


Try This one & Best of Luck....!



因此,您希望禁止maskedtextbox填充...
我假设您同时拥有商品大小和成本的商品,但您的被屏蔽的文本框应仅启用两个组合框商品,即当您从商品组合框选择商品尺寸和成本组合框选择商品时

我假设您的第一个组合框是& amp;产品尺寸,第二个是成本

(假设第一个组合框名称为cboProductsize& amp; amp;第二个为cbocost& ampededtextbox名称为mtxtValue)

(1)首先将maskedtextbox Enable属性更改为False

(2)现在,如果您只希望在同时选中这两个组合框(即cboProductsize和cboCost)时都启用了maskedtextbox,则将以下代码放在成本损失焦点事件"组合框上,否则将其禁用.


私有子项cbocost_LostFocus(ByVal发送者作为对象,ByVal e作为System.EventArgs)处理cbocost.LostFocus
如果不是(cboProductsize.Text = cboProductsize.SelectedText)而不是(cbocost.Text = cbocost.SelectedText)那么
mtxtValue.Enabled = True
如果结束
结束子




(2)但是,如果您的第一个组合框是成本",第二个组合框是产品尺寸",则在产品尺寸组合框"的失去焦点事件"中将放置相同的代码...




私有子cboProductsize_LostFocus(ByVal发送者作为对象,ByVal e作为System.EventArgs)处理cboProductsize.LostFocus
如果不是(cboProductsize.Text = cboProductsize.SelectedText)而不是(cbocost.Text = cbocost.SelectedText)那么
mtxtValue.Enabled = True
如果结束
结束子


希望这个简单的代码能够解决您的问题.
Hi,
So u want the maskedtextbox to be disabled from filling...
I assume that u hv items Product Size and Cost but ur maskedtextbox should be enable only both Combo box Items are selected i.e. When u select Products size from Products combo box and cost from Cost combo box

I assume that ur first combo box is & Product Size and second one is Cost

(Assuming that first combo box name is cboProductsize & second one is cbocost & maskedtextbox name is mtxtValue)

(1) First change maskedtextbox Enable property to False

(2) Now place the following code on the Lost Focus Event of Cost combo box if u want ur maskedtextbox should be enabled only when both of these combo boxes (i.e. cboProductsize and cboCost) will be selected otherwise it will be disabled.


Private Sub cbocost_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbocost.LostFocus
If Not (cboProductsize.Text = cboProductsize.SelectedText) And Not (cbocost.Text = cbocost.SelectedText) Then
mtxtValue.Enabled = True
End If
End Sub


OR

(2) But if ur first combo box is Cost and second one is Product Size than same code will be placed on the Lost Focus Event of Product Size combo box...


i.e.

Private Sub cboProductsize_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboProductsize.LostFocus
If Not (cboProductsize.Text = cboProductsize.SelectedText) And Not (cbocost.Text = cbocost.SelectedText) Then
mtxtValue.Enabled = True
End If
End Sub


Hope this simple code solve ur problem..


这篇关于Visual Basic中的文本框和保存按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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