Results 1 to 11 of 11

Thread: user control

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Posts
    73

    user control

    I am working on a project where the developer has used user controls throughout his forms.

    My question is this, he has one that is simply just a label and text box together, hence the name ctlLabelandTextBox.

    My problem is that I cannot set the maxlength property which u normally get with a textbox.

    Does anyone know how to enable this - i've attached the file. I can think of many reasons for user controls but can't see any real advantage for this one, however - i need to keep with the program if u know what i mean.

    cheers
    Attached Files Attached Files

  2. #2
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    It is most likely that he did not include the property when he made the control. I am not sure that you can change it without having the source for the control.
    But then again... I have been wrong in the past.

    Mega.
    "If at first you don't succeed, then skydiving is not for you"

  3. #3
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    I updated it for you. Now theres a MaxLength property.
    Attached Files Attached Files
    Luke

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Posts
    73
    here is the code:

    Private Sub UserControl_ReadProperties(PropBag As PropertyBag)

    Text = PropBag.ReadProperty("Text", "")
    Midpoint = PropBag.ReadProperty("Midpoint", 1330)
    UserControl.Width = PropBag.ReadProperty("Width", 4800)
    Caption = PropBag.ReadProperty("Caption", "Caption")
    DataFormat = PropBag.ReadProperty("DataFormat", "")

    UserControl_Resize
    txtTextBox_LostFocus

    End Sub

    Private Sub UserControl_WriteProperties(PropBag As PropertyBag)

    PropBag.WriteProperty "Text", txtTextBox.Text
    PropBag.WriteProperty "Midpoint", Midpoint
    PropBag.WriteProperty "Width", UserControl.Width
    PropBag.WriteProperty "Caption", Caption
    PropBag.WriteProperty "DataFormat", msDataFormat
    'PropBag.WriteProperty "MaxLength", txtTextBox.MaxLength

    UserControl_Resize
    txtTextBox_LostFocus

    End Sub

    Private Sub UserControl_Resize()

    Dim lLeft As Long

    UserControl.Height = txtTextBox.Height
    txtTextBox.Width = UserControl.Width - txtTextBox.Left

    End Sub

    Public Property Get Midpoint() As Long
    Midpoint = txtTextBox.Left
    End Property

    Public Property Let Midpoint(lTwips As Long)
    txtTextBox.Left = lTwips
    UserControl_Resize
    End Property

    Public Property Get TextWidth() As Long
    TextWidth = txtTextBox.Width
    End Property

    Public Property Let TextWidth(lTwips As Long)
    txtTextBox.Width = lTwips
    End Property

    Public Property Get Text() As String
    Text = txtTextBox.Text
    End Property

    Public Property Let Text(sText As String)

    If msDataFormat > "" Then
    txtTextBox.Text = Format$(sText, msDataFormat)
    Else
    txtTextBox.Text = sText
    End If

    End Property

    Public Property Get Caption() As String
    Caption = lblLabel.Caption
    End Property

    Public Property Let Caption(sText As String)
    lblLabel.Caption = sText
    End Property

    Public Property Get Enabled() As Boolean
    Enabled = txtTextBox.Enabled
    End Property

    Public Property Let Enabled(bEnabled As Boolean)
    txtTextBox.Enabled = bEnabled
    txtTextBox.BackColor = IIf(bEnabled, vbWhite, RGB(220, 220, 220))
    End Property

    Public Property Get DataFormat() As String
    DataFormat = msDataFormat
    End Property

    Public Property Let DataFormat(sValue As String)
    msDataFormat = sValue
    End Property

  5. #5
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    Originally posted by wanhobi
    here is the code:

    Private Sub UserControl_ReadProperties(PropBag As PropertyBag)

    Text = PropBag.ReadProperty("Text", "")
    Midpoint = PropBag.ReadProperty("Midpoint", 1330)
    UserControl.Width = PropBag.ReadProperty("Width", 4800)
    Caption = PropBag.ReadProperty("Caption", "Caption")
    DataFormat = PropBag.ReadProperty("DataFormat", "")

    UserControl_Resize
    txtTextBox_LostFocus

    End Sub

    Private Sub UserControl_WriteProperties(PropBag As PropertyBag)

    PropBag.WriteProperty "Text", txtTextBox.Text
    PropBag.WriteProperty "Midpoint", Midpoint
    PropBag.WriteProperty "Width", UserControl.Width
    PropBag.WriteProperty "Caption", Caption
    PropBag.WriteProperty "DataFormat", msDataFormat
    'PropBag.WriteProperty "MaxLength", txtTextBox.MaxLength

    UserControl_Resize
    txtTextBox_LostFocus

    End Sub

    Private Sub UserControl_Resize()

    Dim lLeft As Long

    UserControl.Height = txtTextBox.Height
    txtTextBox.Width = UserControl.Width - txtTextBox.Left

    End Sub

    Public Property Get Midpoint() As Long
    Midpoint = txtTextBox.Left
    End Property

    Public Property Let Midpoint(lTwips As Long)
    txtTextBox.Left = lTwips
    UserControl_Resize
    End Property

    Public Property Get TextWidth() As Long
    TextWidth = txtTextBox.Width
    End Property

    Public Property Let TextWidth(lTwips As Long)
    txtTextBox.Width = lTwips
    End Property

    Public Property Get Text() As String
    Text = txtTextBox.Text
    End Property

    Public Property Let Text(sText As String)

    If msDataFormat > "" Then
    txtTextBox.Text = Format$(sText, msDataFormat)
    Else
    txtTextBox.Text = sText
    End If

    End Property

    Public Property Get Caption() As String
    Caption = lblLabel.Caption
    End Property

    Public Property Let Caption(sText As String)
    lblLabel.Caption = sText
    End Property

    Public Property Get Enabled() As Boolean
    Enabled = txtTextBox.Enabled
    End Property

    Public Property Let Enabled(bEnabled As Boolean)
    txtTextBox.Enabled = bEnabled
    txtTextBox.BackColor = IIf(bEnabled, vbWhite, RGB(220, 220, 220))
    End Property

    Public Property Get DataFormat() As String
    DataFormat = msDataFormat
    End Property

    Public Property Let DataFormat(sValue As String)
    msDataFormat = sValue
    End Property
    Beat you to it.
    Luke

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Posts
    73

    macai thanks but

    i get variable not defined on the line:

    MaxLength = PropBag.ReadProperty("MaxLength", "")

    within

    UserControl_ReadProperties

  7. #7
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    Are you trying to change the MaxLength property during runtime?
    Luke

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Posts
    73

    hi

    I copied in your control over mine, when i play the project i get the error. I have not yet tried to set the property. I was just checking to see that the app still runs with the new property available.

    I get a type mismatch on that line as soon as I load a form that contains the control.

    any ideas?

  9. #9
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    Thats weird. I tested it out and it works. Perhaps you should
    remove that control from the form, and then re-add it with the
    same name. It might be that the form is conflicting with the new
    control code.
    Luke

  10. #10
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: hi

    Originally posted by wanhobi
    I copied in your control over mine, when i play the project i get the error. I have not yet tried to set the property. I was just checking to see that the app still runs with the new property available.

    I get a type mismatch on that line as soon as I load a form that contains the control.

    any ideas?
    I assume that the problem is that the Property MaxLength is being declared as an Integer. In the read property section you are giving maxlength a string as it's default value.

    Originally posted by wanhobi
    i get variable not defined on the line:

    MaxLength = PropBag.ReadProperty("MaxLength", "")

    within

    UserControl_ReadProperties

  11. #11
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228

    Re: Re: hi

    Originally posted by MarkT
    I assume that the problem is that the Property MaxLength is being declared as an Integer. In the read property section you are giving maxlength a string as it's default value.
    Uhm....your smart.
    Luke

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width