Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Change Constituent Controls Size or Lcation In Composite Control In Form Designer

Change Constituent Controls Size or Lcation In Composite Control In Form Designer

Change Constituent Controls Size or Lcation In Composite Control In Form Designer

I have composite control with a label, a textbox, and a combo box.
Is there a way to change the sizes or locations of these controls when the composite control is placed on the form designer?
The only thing I seem to be able to do is change the size of the entire composite control.
I want to be able to use the composite control for various items on a form that would require different sizes but not being able to change anything makes the composite control somewhat useless.

Sylvania/Toledo Ohio

RE: Change Constituent Controls Size or Lcation In Composite Control In Form Designer

OK, changed focus a bit and came up with this composite control to display the combo box value in a text box.

Notes: glbViewMode is an integer with a value of zero, any other value puts the control in Edit Mode.
cboAddWidth is a just a fudged integer value (17) to increase the size of the combo box when typing in the combo box.
And Yes it does make the combo box arrow move off the composite control visible space by design.
I was originally gong to make the whole control larger when the combo box size is changed, but decided I like it this way.

Any comments or suggestions are welcome.


Imports System.ComponentModel

' Purpose: Display the value of a ComboBox without the dimmed appearance when disabled
'          and without having to draw the ComboBox manually
' Control consists of a TexBox and a ComboBox
' TextBox and ComboBox are both set to the composite control width on loading
' TextBox is in front of the ComboBox
' TextBox.Text is set to the ComboBox.Text
' In Edit Mode the textBox is not visible allowing the ComboBox to be viewed and changed
' When NOT in Edit Mode the TextBox hides the ComboBox so it cannot be changed
' The ComboBox is always visible so its value will be changed when the binding source value changes

Public Class myComboTextBox
  ' Control Edit Mode
  Private EditMode As Integer
  ' This Control Width
  Private ThisControlWidth As Integer
  ' Original Combo Selected Index
  Private OrgSelectedIndex As Integer = -1
  ' cbo Width Has Changed Flag
  Private ComboWidthChanged As Boolean

  Public Sub New()
    ' This call is required by the Windows Form Designer.

    ' Add any initialization after the InitializeComponent() call.
  End Sub

  ' Set Initial Control Settings
  Private Sub myComboTextBox_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    ThisControlWidth = Me.Width
    ComboWidthChanged = False

    ' Change Backcolor Due To ReadOnly BackColor Is Not White
    txtBox.BackColor = myClrWhite

    txtBox.Width = ThisControlWidth
    cboBox.Width = ThisControlWidth
  End Sub

  ' Set View/Edit Mode
  Public Property PropComboTextCurrentMode() As Integer
      Return EditMode
    End Get
    Set(ByVal Value As Integer)
      EditMode = Value
      txtBox.Visible = CBool(IIf(EditMode = glbViewMode, True, False))
      cboBox.Enabled = CBool(IIf(EditMode = glbViewMode, False, True))
    End Set
  End Property

  ' Set Combo SelectedIndex
  Public Property PropSelectedIndex() As Integer
      Return cboBox.SelectedIndex
    End Get
    Set(ByVal Value As Integer)
      cboBox.SelectedIndex = Value
    End Set
  End Property

  ' Force Combo to Uppercase & Increase Width To Make AutoComplete DropDown Wider
  Private Sub cbo_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles cboBox.KeyPress
    If Not ComboWidthChanged = True Then
      cboBox.Width = cboBox.Width + cboAddWidth
      ComboWidthChanged = True
    End If

    If Char.IsLetter(e.KeyChar) Then
      e.KeyChar = Char.ToUpper(e.KeyChar)
    End If
  End Sub

  ' Restore Combo Width
  Private Sub cbo_LostLeave(ByVal sender As Object, ByVal e As EventArgs) Handles cboBox.LostFocus, cboBox.Leave, cboBox.MouseLeave
    If ComboWidthChanged = True Then
      cboBox.Width = ThisControlWidth
      ComboWidthChanged = False
    End If
  End Sub

  ' Save Original Combo Selected Index
  Private Sub cboBox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboBox.GotFocus
    OrgSelectedIndex = cboBox.SelectedIndex
  End Sub

  ' Check Combo For Invalid Selection, Restore Original SelectedIndex
  Private Sub cboSelection_Validating(ByVal sender As Object, ByVal e As CancelEventArgs) Handles cboBox.Validating
    ' Invalid Selection or No Selection Made
    If cboBox.SelectedIndex = -1 Then
      ' Invalid Selection but Text is Present
      If cboBox.Text.Trim.Length > 0 Then
        MessageBox.Show("Invalid selection", _
                  "Attention", _
                   MessageBoxButtons.OK, _
                   MessageBoxIcon.Exclamation, _
        e.Cancel = True

        If OrgSelectedIndex = -1 Then
          cboBox.Text = ""
          cboBox.SelectedIndex = OrgSelectedIndex
        End If
      End If
    End If
  End Sub

  ' Save Original Combo Selected Index
  Private Sub cboBox_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboBox.Validated
    OrgSelectedIndex = cboBox.SelectedIndex
  End Sub

  ' Set Textbox Text To Combo Text
  Private Sub cboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboBox.SelectedIndexChanged
    txtBox.Text = cboBox.Text
  End Sub

End Class 

Sylvania/Toledo Ohio

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close