2 Replies - 3030 Views - Last Post: 17 May 2012 - 02:13 AM Rate Topic: -----

#1 fadafas   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 20-March 12

Custom User Control

Posted 14 May 2012 - 04:36 AM

Hi there,

I 've created a custom user control (GNcalendar)using Windows Forms Control Library.
So GNcalendar is a combination of a datetimepicker and a combobox
The idea is that when the user select smtng from the combobox (predifined dates) the will appear directly in the datetimepicker.

Everything is OK but I face two problems when I add my control in my project (I add the controls in runtime):
1. GNcalendar.Name
I am not able to get the name of the GNcalendar during runtime

2. I create an event when I change the value of that control, but when I asked to return the type of the control it returns the type of the sub-controls (datetimepicker and combobox) depending which I clicked.

Here is the code for the events:

 Public Custom Event wwcValueChanged As EventHandler
        AddHandler(ByVal value As EventHandler)
            AddHandler dtp.ValueChanged, value
            AddHandler cb.SelectedValueChanged, value
        End AddHandler

        RemoveHandler(ByVal value As EventHandler)
            RemoveHandler dtp.ValueChanged, value
            RemoveHandler cb.SelectedValueChanged, value
        End RemoveHandler

        RaiseEvent(ByVal sender As Object, ByVal e As System.EventArgs)

        End RaiseEvent
    End Event

Private Sub dtp_ValueChanged(sender As System.Object, e As System.EventArgs) Handles dtp.ValueChanged
        Me.Value = dtp.Value
    End Sub
    Private Sub cb_SelectedValueChanged(sender As Object, e As System.EventArgs) Handles cb.SelectedValueChanged
        If cb.Items.Count > 0 Then
            If cb.SelectedIndex = 0 Then
                dtp.Visible = True
                Me.Value = dtp.Value
                Me.valueIsDate = True
                dtp.Visible = False
                Me.Value = cb.SelectedValue
                Me.valueIsDate = False
            End If
        End If
    End Sub

Any ideas?



Is This A Good Question/Topic? 0
  • +

Replies To: Custom User Control

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Custom User Control

Posted 14 May 2012 - 07:13 AM

I'm a C# guy so I can't give you exact VB code but are you trying to get the .Name of your INSTANCE and not the class name as you are showing the question?

Did you give your class a .Name property? Or inherit from a class with a .Name property?

If you really don't want the object throwing the event, but it's parent them check it's .Parent property.
Or give the UserControl events. When a child does something have the parent react and raise an event, then your form subscribes to the UserControl's event.
Was This Post Helpful? 1
  • +
  • -

#3 fadafas   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 20-March 12

Re: Custom User Control

Posted 17 May 2012 - 02:13 AM

tlhIn`toq, thanks for the help.

Your suggestion with the parent worked fine -thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1