Results 1 to 4 of 4

Thread: Make ControlLibrary user control Hide()

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    4

    Make ControlLibrary user control Hide()

    I've spent three days trying to get a user control to do some obvious things -- show, hide, and focus among other things. Done in vBASIC in Visual Studio 2010 Pro. The calling program is a Windows Forms Application, while the user control is a WPF Custom Control Library with a single object, a textbox. The reason it's a user control is that this textbox is connected to an async serial device; the reason it's in a Custom Control Library is that I'd like to be able to drop this functioning serial-port-connected textbox into future projects.

    No matter what syntax I attempt, the user control (neither the control nor the text box inside it) will Hide(). I've tried every variation I can think of with control.Visible = false, exposing public subs to do the work, etc. When the form appears and characters are typed in the field, the KeyPress routine is functioning -- it will only accept numeric digits.

    Here's the vastly reduced code to illustrate the problem:

    Calling Windows Forms Application Code:

    Imports DTRFormsControlLibrary2

    Public Class Form1

    Dim sbControl As ucDTRScanBox

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    sbControl = New ucDTRScanBox()
    sbControl.Hide()
    End Sub

    End Class

    Responding WPF Custom Control Library code:

    Public Class ucDTRScanBox

    Public Sub New()
    InitializeComponent()
    End Sub

    Private Sub sbRFIDTag_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles sbRFIDTag.KeyPress
    If Not IsNumeric(e.KeyChar) Then e.Handled = True
    End Sub
    End Class

    In spite of the call to sbControl.Hide(), the form opens with a very visible and enabled user control text box. The ability to control visibility, focus, and enable/disable seems fundamental to any control. It shouldn't be this hard. What am I missing?

    TIA to anyone who's dealt with this and is willing to set me straight...

  2. #2

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    4

    Re: Make ControlLibrary user control Hide()

    Should have mentioned that both projects (calling Windows Form and ControlLibrary) are present in the solution tree.

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    4

    Re: Make ControlLibrary user control Hide()

    Also should have mentioned that the textbox object inside the user control is named sbRFIDTag.

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2011
    Posts
    4

    Resolved Re: Make ControlLibrary user control Hide()

    Never mind! I was trying to refer to the user control by its name in the Control Library rather than its name on the calling program's form. I did have to drop the overloaded constructor to the control, but was able to incorporate a Public Sub within the control with byRef parameters to compensate for it.

    Imports System.IO.Ports
    Imports DTRFormsControlLibrary2

    Public Class Form1

    Dim comPort As SerialPort

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    ucScanBox1.Hide()
    ucScanBox1.OpenCOM(comPort, "COM1")
    bnScan.Focus()
    End Sub

    Private Sub bnScan_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bnScan.Click
    ucScanBox1.Show()
    ucScanBox1.Focus()
    ucScanBox1.sb_hide()
    End Sub
    End Class

    All of the calls to ucScanBox1 work now.

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