处理工作 - 有人可以仔细检查 [英] Handle Worked - can someone please double check

查看:49
本文介绍了处理工作 - 有人可以仔细检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望某些文本框(只有某些文本框)总是被修剪,所以

空格不在开头,

也不是结束输入的文字。


我创建了自己的Handle? - 我希望这是正确的术语,

并且它有效。这是正确的方法吗?

我必须使用DirectCast来获取文本框名称。


Private Sub TrimValues(ByVal sender As System.Object ,ByVal e As

EventArgs)_

处理txtOne.Leave,txtTwo.Leave,txtThree.Leave,txtFour.Leave,_

txtFive .Leave,txtSix.Leave,txtSeven.Leave


DirectCast(sender,TextBox).Text = Trim(DirectCast(发件人,

TextBox).Text)


End Sub


谢谢,


Miro

I wanted certain text boxes ( only certain ones ) to always be Trim''d so
that spaces are not in the begining,
nor the end of the text entered.

I created my own "Handle ?" - i hope thats the right terminology,
and it works. Is this the right way to do this?
I had to use DirectCast to get the textbox name.

Private Sub TrimValues(ByVal sender As System.Object, ByVal e As
EventArgs) _
Handles txtOne.Leave, txtTwo.Leave, txtThree.Leave, txtFour.Leave, _
txtFive.Leave, txtSix.Leave, txtSeven.Leave

DirectCast(sender, TextBox).Text = Trim(DirectCast(sender,
TextBox).Text)

End Sub

Thanks,

Miro

推荐答案

Miro,


使用VB.Net,有更多的道路通往罗马,但有我的

想法你的解决方案没什么问题。


你可以使用一个通用的句柄设置实例

加载表单事件


\\\

Private Sub Form1_Load(ByVal sender As Object,_

ByVal e As System.EventArgs处理MyBase.Load < br $>
doset(Me)

End Sub

Private Sub doSet(ByVal parentCtr As Control)

Dim ctr As Control

For each ctr in parentCtr.Controls

如果TypeOf ctr是Textbox那么

AddHandler ctr.LostFocus,AddressOf TrimValues

doSet(ctr)

下一页

结束子

////


和那么你的程序。


这是一种递归方法,因为实例中的文本框也必须处理组合框




我希望这有点帮助吗?


Cor


" Miro" < mi ****** @ golden.netschreef in bericht

新闻:O5 ************** @ TK2MSFTNGP04.phx.gbl ...
Miro,

Using VB.Net, there are more roads that leads to Rome, but there is in my
idea nothing wrong with your solution.

You can use as well a kind of generic setting of the handle in by instance
the load form event

\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
doset(Me)
End Sub
Private Sub doSet(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
if TypeOf ctr Is Textbox then
AddHandler ctr.LostFocus, AddressOf TrimValues
doSet(ctr)
Next
End Sub
////

And then your procedure.

This is a recursive method, because the textboxes in by instance a groupbox
have to be handled as well.

I hope this helps a little bit?

Cor

"Miro" <mi******@golden.netschreef in bericht
news:O5**************@TK2MSFTNGP04.phx.gbl...

>我希望某些文本框(只有某些文本框)始终被修剪,以便空间不在开头,

也不是输入文本的结尾。


我创建了自己的Handle? - 我希望这是正确的术语,

并且它有效。这是正确的方法吗?

我必须使用DirectCast来获取文本框名称。


Private Sub TrimValues(ByVal sender As System.Object ,ByVal e As

EventArgs)_

处理txtOne.Leave,txtTwo.Leave,txtThree.Leave,txtFour.Leave,

_

txtFive.Leave,txtSix.Leave,txtSeven.Leave


DirectCast(发件人,TextBox).Text = Trim(DirectCast(发件人,

TextBox).Text)


结束子


谢谢,


Miro
>I wanted certain text boxes ( only certain ones ) to always be Trim''d so
that spaces are not in the begining,
nor the end of the text entered.

I created my own "Handle ?" - i hope thats the right terminology,
and it works. Is this the right way to do this?
I had to use DirectCast to get the textbox name.

Private Sub TrimValues(ByVal sender As System.Object, ByVal e As
EventArgs) _
Handles txtOne.Leave, txtTwo.Leave, txtThree.Leave, txtFour.Leave,
_
txtFive.Leave, txtSix.Leave, txtSeven.Leave

DirectCast(sender, TextBox).Text = Trim(DirectCast(sender,
TextBox).Text)

End Sub

Thanks,

Miro



确实如此,

1.第一个没问题

2。我可以通过你给我的第二个选项。


慢慢地这个vb的东西开始ot make sence :)


非常感谢你的帮助!!

我很感激。


Miro


" Cor Ligthert [MVP] QUOT; < no ************ @ planet.nlwrote in message

news:uT ************* @ TK2MSFTNGP06.phx。 gbl ...
It does,
1. That the first is ok
2. That I can go thru what you have given me as the second option.

Slowely this vb stuff is starting ot make sence :)

Thank you very much for the help!!
I appreciate it.

Miro

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:uT*************@TK2MSFTNGP06.phx.gbl...

Miro,


使用VB.Net,有更多的道路通往罗马,但那里在我的

想法中你的解决方案没有任何问题。


你可以使用一个通用的句柄设置实例

加载表单事件


\\\

Private Sub Form1_Load(ByVal sender As Object,_

ByVal e As System.EventArgs)处理MyBase.Load

doset(Me)

End Sub

Private Sub doSet(ByVal parentCtr As控制)

Dim ctr As Control

For each ctr in parentCtr.Controls

如果TypeOf ctr是Textbox那么

AddHandler ctr.LostFocus,AddressOf TrimValues

doSet(ctr)

下一页

结束子

/// /


然后是你的程序。


这是一种递归方法,因为实例中的文本框也必须处理

组合框。


我希望这有点帮助吗?


Cor


" Miro" < mi ****** @ golden.netschreef in bericht

新闻:O5 ************** @ TK2MSFTNGP04.phx.gbl ...
Miro,

Using VB.Net, there are more roads that leads to Rome, but there is in my
idea nothing wrong with your solution.

You can use as well a kind of generic setting of the handle in by instance
the load form event

\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
doset(Me)
End Sub
Private Sub doSet(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
if TypeOf ctr Is Textbox then
AddHandler ctr.LostFocus, AddressOf TrimValues
doSet(ctr)
Next
End Sub
////

And then your procedure.

This is a recursive method, because the textboxes in by instance a
groupbox have to be handled as well.

I hope this helps a little bit?

Cor

"Miro" <mi******@golden.netschreef in bericht
news:O5**************@TK2MSFTNGP04.phx.gbl...

>>我希望某些文本框(只有某些文本框)总是被修剪,所以
空间不在开头,<也没有输入文本的结尾。

我创建了自己的Handle?。 - 我希望这是正确的术语,
并且它有效。这是正确的方法吗?
我必须使用DirectCast来获取文本框名称。

私有子TrimValues(ByVal发送者为System.Object,ByVal e As
EventArgs)_
处理txtOne.Leave,txtTwo.Leave,txtThree.Leave,txtFour.Leave,
_
txtFive.Leave,txtSix.Leave,txtSeven.Leave

DirectCast(发件人,TextBox).Text = Trim(DirectCast(发件人,
TextBox).Text)

结束子

谢谢,

Miro
>>I wanted certain text boxes ( only certain ones ) to always be Trim''d so
that spaces are not in the begining,
nor the end of the text entered.

I created my own "Handle ?" - i hope thats the right terminology,
and it works. Is this the right way to do this?
I had to use DirectCast to get the textbox name.

Private Sub TrimValues(ByVal sender As System.Object, ByVal e As
EventArgs) _
Handles txtOne.Leave, txtTwo.Leave, txtThree.Leave, txtFour.Leave,
_
txtFive.Leave, txtSix.Leave, txtSeven.Leave

DirectCast(sender, TextBox).Text = Trim(DirectCast(sender,
TextBox).Text)

End Sub

Thanks,

Miro






罗马的另一条路径。 ..


如果你想在其他表格上重现这个功能...即。修剪文本
文本框中的
...您需要在每个表单上复制此代码。

剪切/粘贴/查找和替换。

对于可重用性...创建自己的类 - myTextBox - 继承自

基类--Windows.Forms.TextBox ...并覆盖/延长休假

活动。


这样,您可以将myTextBox放在表单上......您即可参加

比赛......需要在表单上编写任何代码...如果你需要

改变修剪的行为...你在一个地方改变它......完成。


-------------------------------------------- -


导入System.Windows.Forms


命名空间myControls


公共类myTextBox


继承System.Windows.Forms.TextBox


受保护覆盖​​Sub OnLeave(ByVal e As System.EventArgs)


MyBase.OnLeave(e)

Me.Text = Trim(Me.Text)


结束分


结束课


结束命名空间


------- --------------------------------------


现在,如果你想进一步扩展这个...你可以包括一个

属性... _TrimText ...只要你想要
$ b $在设计师中设置它b修剪空格......这样你总是可以使用myTextBox控件,并且

相应地设置属性。原因,如果你将一个文本控件添加到

表单中...用它做你的东西...编码,设置属性等......

然后实现你需要修剪文本......你不必删除

控件,添加你的myTextBox,编码它......再次配置它。如果你使用你的基本控件 - myTextBox - 从开始,TrimText现在是

a属性,设置它,完成它。

-------------------------------------

命名空间GlobalContainer


导入System.Windows.Forms


公共类myTextBox

继承System.Windows.Forms。 TextBox


私有_TrimText为布尔

< System.ComponentModel.Description("你想修剪

textbox。"),

System.ComponentModel.Category(" Behavior")_

Public Property TrimText()As Boolean

获取

返回_TrimText

结束获取

设置(ByVal值为布尔值)

_TrimText = value

结束集

结束财产


受保护的覆盖Sub OnLeave(ByVal e As System.EventArgs)

MyBase.OnLeave(e)


如果TrimText那么

调用ueTrimText()

结束如果


结束子


Public Sub ueTrimText()


Me.Text =修剪(Me.Text)


结束分


结束课

结束命名空间


-----------------------------------------


在这种情况下继承是你的朋友。


杰夫。


" Miro" < mi ****** @gold.netwrote in message

news:O5 ************** @ TK2MSFTNGP04.phx.gbl ...

And another path to rome ...

If you want to reproduce this functionality on other forms ... ie. trim text
in text boxes ... you will need to duplicate this code on each form.
cut/paste/find and replace.

For reuseability ... create your own class - myTextBox - that inherits from
the base class - Windows.Forms.TextBox ... and override / extend the leave
event.

This way, you can drop the myTextBox on the form ... you are off to the
races ... no need to code anything on the form ... and if you ever need to
change the behavior of the trim ... you change it in one place ... done.

---------------------------------------------

Imports System.Windows.Forms

Namespace myControls

Public Class myTextBox

Inherits System.Windows.Forms.TextBox

Protected Overrides Sub OnLeave(ByVal e As System.EventArgs)

MyBase.OnLeave(e)
Me.Text = Trim(Me.Text)

End Sub

End Class

End Namespace

---------------------------------------------

Now, if you want to extend this a little further ... you could include a
property ... _TrimText ... set this in the designer whenever you want to
trim the spaces... This way you can always use the myTextBox control, and
set the property accordingly. Reason, if you add a text control to a
form...do your stuff with it ... coding, setting properties and so on ...
then realize you need to ''trim the text'' ... you do not have to delete the
control, add your myTextBox, code it ... configure it ... again. If you
used your base control - myTextBox - from the begining, the TrimText is now
a property, set it, have it - done.

-------------------------------------
Namespace GlobalContainer

Imports System.Windows.Forms

Public Class myTextBox
Inherits System.Windows.Forms.TextBox

Private _TrimText As Boolean

<System.ComponentModel.Description("Do you want to trim the
textbox."),
System.ComponentModel.Category("Behavior")_
Public Property TrimText() As Boolean
Get
Return _TrimText
End Get
Set(ByVal value As Boolean)
_TrimText = value
End Set
End Property

Protected Overrides Sub OnLeave(ByVal e As System.EventArgs)
MyBase.OnLeave(e)

If TrimText Then
Call ueTrimText()
End If

End Sub

Public Sub ueTrimText()

Me.Text = Trim(Me.Text)

End Sub

End Class
End Namespace

-----------------------------------------

Inheritance is your friend in this case.

Jeff.

"Miro" <mi******@golden.netwrote in message
news:O5**************@TK2MSFTNGP04.phx.gbl...

>我希望某些文本框(只有某些文本框)始终被修剪,以便空间不在开头,

也不是输入文本的结尾。


我创建了自己的Handle? - 我希望这是正确的术语,

并且它有效。这是正确的方法吗?

我必须使用DirectCast来获取文本框名称。


Private Sub TrimValues(ByVal sender As System.Object ,ByVal e As

EventArgs)_

处理txtOne.Leave,txtTwo.Leave,txtThree.Leave,txtFour.Leave,

_

txtFive.Leave,txtSix.Leave,txtSeven.Leave


DirectCast(发件人,TextBox).Text = Trim(DirectCast(发件人,

TextBox).Text)


结束子


谢谢,


Miro
>I wanted certain text boxes ( only certain ones ) to always be Trim''d so
that spaces are not in the begining,
nor the end of the text entered.

I created my own "Handle ?" - i hope thats the right terminology,
and it works. Is this the right way to do this?
I had to use DirectCast to get the textbox name.

Private Sub TrimValues(ByVal sender As System.Object, ByVal e As
EventArgs) _
Handles txtOne.Leave, txtTwo.Leave, txtThree.Leave, txtFour.Leave,
_
txtFive.Leave, txtSix.Leave, txtSeven.Leave

DirectCast(sender, TextBox).Text = Trim(DirectCast(sender,
TextBox).Text)

End Sub

Thanks,

Miro



这篇关于处理工作 - 有人可以仔细检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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