Home > Archive > Visual Basic > February 2006 > Implement SelStart/SelLength/SelText in UserControl
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Implement SelStart/SelLength/SelText in UserControl
|
|
|
| Hello All,
I've got a user control that enhances a standard Textbox.
I would like to be able to use the SelStart/SelLength/SelText methods on
this user control. But for some reason, I can't seem to get it to work.
I set up properties in the user control for these features but I don't get
any text selected when I call the properties.
ucText1.SelStart=0
ucText1.SelLength=Len(ucText1)
Could someone provide some insight in how to implement this functionality in
my User Control.
PS... I used the ActiveX wizard to specify the properties. I must be
missing some other event call or logic.
Thanks,
Brian
| |
|
| Without testing try:
ucText1.SelStart=0
ucText1.SelLength=Len(ucText1.Text)
--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
Veign's Blog
http://www.veign.com/blog
--
"Brian" <bkstigler@usa.net> wrote in message
news:eTy9y0VOGHA.3888@TK2MSFTNGP10.phx.gbl...
> Hello All,
> I've got a user control that enhances a standard Textbox.
>
> I would like to be able to use the SelStart/SelLength/SelText methods on
> this user control. But for some reason, I can't seem to get it to work.
>
> I set up properties in the user control for these features but I don't get
> any text selected when I call the properties.
>
> ucText1.SelStart=0
> ucText1.SelLength=Len(ucText1)
>
> Could someone provide some insight in how to implement this functionality
> in
> my User Control.
>
> PS... I used the ActiveX wizard to specify the properties. I must be
> missing some other event call or logic.
>
> Thanks,
> Brian
>
>
| |
| Jan Hyde 2006-02-24, 6:55 pm |
| "Brian" <bkstigler@usa.net>'s wild thoughts were released on
Fri, 24 Feb 2006 08:13:03 -0800 bearing the following fruit:
>Hello All,
>I've got a user control that enhances a standard Textbox.
>
>I would like to be able to use the SelStart/SelLength/SelText methods on
>this user control. But for some reason, I can't seem to get it to work.
>
>I set up properties in the user control for these features but I don't get
>any text selected when I call the properties.
>
>ucText1.SelStart=0
>ucText1.SelLength=Len(ucText1)
Does
ucText1.SetFocus
solve the problem?
J
>Could someone provide some insight in how to implement this functionality in
>my User Control.
>
>PS... I used the ActiveX wizard to specify the properties. I must be
>missing some other event call or logic.
>
>Thanks,
>Brian
>
Jan Hyde (VB MVP)
--
Hardware, n.: The parts of a computer system that can be kicked.
| |
| Ken Halter 2006-02-24, 6:55 pm |
| "Brian" <bkstigler@usa.net> wrote in message
news:eTy9y0VOGHA.3888@TK2MSFTNGP10.phx.gbl...
> Hello All,
> I've got a user control that enhances a standard Textbox.
>
> I would like to be able to use the SelStart/SelLength/SelText methods on
> this user control. But for some reason, I can't seem to get it to work.
>
> I set up properties in the user control for these features but I don't get
> any text selected when I call the properties.
>
> ucText1.SelStart=0
> ucText1.SelLength=Len(ucText1)
>
> Could someone provide some insight in how to implement this functionality
> in
> my User Control.
>
> PS... I used the ActiveX wizard to specify the properties. I must be
> missing some other event call or logic.
>
> Thanks,
> Brian
That wizard is VB's best imo.... the usercontrol code below was generated by
the wizard (the code shown has been copied to Notepad and all of the
"Warnings" removed then copied back). Thing is, on one of the wizard pages,
there's a place to set which part of the usercontrol a property effects. In
this case, I told the wizard I wanted these properties to effect a Textbox
called Text1. One thing you /may've/ missed is.... the selection won't show
until you return focus to that box.
'=========Form1 Code
Option Explicit
Private Sub Command1_Click()
With UserControl11
.SelStart = 0
.SelLength = 100
.SetFocus
End With
End Sub
'=========UserControl code
Option Explicit
Public Property Get SelLength() As Long
SelLength = Text1.SelLength
End Property
Public Property Let SelLength(ByVal New_SelLength As Long)
Text1.SelLength() = New_SelLength
PropertyChanged "SelLength"
End Property
Public Property Get SelStart() As Long
SelStart = Text1.SelStart
End Property
Public Property Let SelStart(ByVal New_SelStart As Long)
Text1.SelStart() = New_SelStart
PropertyChanged "SelStart"
End Property
Public Property Get SelText() As String
SelText = Text1.SelText
End Property
Public Property Let SelText(ByVal New_SelText As String)
Text1.SelText() = New_SelText
PropertyChanged "SelText"
End Property
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Text1.SelLength = PropBag.ReadProperty("SelLength", 0)
Text1.SelStart = PropBag.ReadProperty("SelStart", 0)
Text1.SelText = PropBag.ReadProperty("SelText", "")
End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("SelLength", Text1.SelLength, 0)
Call PropBag.WriteProperty("SelStart", Text1.SelStart, 0)
Call PropBag.WriteProperty("SelText", Text1.SelText, "")
End Sub
'=========
--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Freeware 4 color Gradient Frame? http://www.vbsight.com/GradFrameCTL.htm
| |
|
| Veign/All,
Looks like that solved the problem. Not sure why it doesn't recognize the
default text property of the text box. But adding that corrected the issue.
Thanks.
Brian
"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:%23z0zhXWOGHA.3260@TK2MSFTNGP11.phx.gbl...
> "Brian" <bkstigler@usa.net> wrote in message
> news:eTy9y0VOGHA.3888@TK2MSFTNGP10.phx.gbl...
get[color=darkred]
functionality[color=darkred]
>
> That wizard is VB's best imo.... the usercontrol code below was generated
by
> the wizard (the code shown has been copied to Notepad and all of the
> "Warnings" removed then copied back). Thing is, on one of the wizard
pages,
> there's a place to set which part of the usercontrol a property effects.
In
> this case, I told the wizard I wanted these properties to effect a Textbox
> called Text1. One thing you /may've/ missed is.... the selection won't
show
> until you return focus to that box.
> '=========Form1 Code
> Option Explicit
>
> Private Sub Command1_Click()
> With UserControl11
> .SelStart = 0
> .SelLength = 100
> .SetFocus
> End With
> End Sub
> '=========UserControl code
> Option Explicit
>
> Public Property Get SelLength() As Long
> SelLength = Text1.SelLength
> End Property
>
> Public Property Let SelLength(ByVal New_SelLength As Long)
> Text1.SelLength() = New_SelLength
> PropertyChanged "SelLength"
> End Property
>
> Public Property Get SelStart() As Long
> SelStart = Text1.SelStart
> End Property
>
> Public Property Let SelStart(ByVal New_SelStart As Long)
> Text1.SelStart() = New_SelStart
> PropertyChanged "SelStart"
> End Property
>
> Public Property Get SelText() As String
> SelText = Text1.SelText
> End Property
>
> Public Property Let SelText(ByVal New_SelText As String)
> Text1.SelText() = New_SelText
> PropertyChanged "SelText"
> End Property
>
> Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
> Text1.SelLength = PropBag.ReadProperty("SelLength", 0)
> Text1.SelStart = PropBag.ReadProperty("SelStart", 0)
> Text1.SelText = PropBag.ReadProperty("SelText", "")
> End Sub
>
> Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
> Call PropBag.WriteProperty("SelLength", Text1.SelLength, 0)
> Call PropBag.WriteProperty("SelStart", Text1.SelStart, 0)
> Call PropBag.WriteProperty("SelText", Text1.SelText, "")
> End Sub
> '=========
>
> --
> Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
> DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
> Freeware 4 color Gradient Frame? http://www.vbsight.com/GradFrameCTL.htm
>
>
|
|
|
|
|