0

A control of mine has a List<Point> as property which needs to be set when that control is constructed. The individual Point's have to be taken from mouse-clicks on the form and it has to happen in the Designmode of Visual Studio.

Now my idea was to open a new Form whenever that control is created which would duplicate the original Form, and on the new Form I could click a bit, register the Points, add them to the List Property and close the new Form when I'm done. But I can't seem to apply the original Forms properties to the new one and I guess it's because it doesn't happen while runtime.

This is what I have so far(I know it ain't much, its about the principle):

Showing a new Form when the control is created:

Public Sub New()
        InitializeComponent()
        Dim myForm As Form = Me.FindForm()
        Dim newForm As New newForm(myForm)
        scrInput.Show()
    End Sub

The new Form:

Public Class SourceForm
    Private additionlHeight As Integer = 50

    Public Sub New(ScrSource As Form)
        InitializeComponent()
        Me.Height = ScrSource.Height + additionlHeight
        Me.Width = ScrSource.Width
        Me.BackColor = ScrSource.BackColor
    End Sub
End Class

No updated height, width or background color to be seen on the new form... Any idea?

  • Try `Me.Refresh()` after setting Height, Width and BackColor. If this still doesn´t work add `Application.DoEvents()`. Or add a class variable `ScrSource` in your SoruceForm and set it in the constructor. But instead of adjusting the properties in the constrcutor, set Height, Width, and BackColor in the `Load` event of the SoruceForm. – Alex B. Apr 12 '16 at 09:50
  • First, that looks like a UserControl not a custom control. If you properly define the `List(Of Point)` property, VS/IDE will fire off the collection editor for you. – Ňɏssa Pøngjǣrdenlarp Apr 12 '16 at 13:20
  • @ Alex B. did all you suggested but it still doesn't work. @ Plutonix Sorry, I wasn't aware there is a difference between the two. It does indeed show me the collection editor, but that editor doesn't accomplish what i need (registering points per mouseclick). Thanks for your help anyway! – ziggystardust Apr 13 '16 at 07:20

1 Answers1

0

Just for documentation's sake:

Looks like I managed to solve my problem. I tried many different things, but I believe that creating the new Form in the Load event of the control solved it in the end. The Refresh() methode helped as well.

So here is the working code. For the control:

Private Sub myControl_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim myForm As Form = Me.FindForm()
        Dim controlInputForm As New myControlInputForm(myForm)
        controlInputForm.Show()
End Sub

For the new Form class:

Public Class myControlInputForm

        Private additionlHeight As Integer = 50
        Private sourceForm As Form

        Public Sub New(sourceForm As Form)
            InitializeComponent()

            Me.sourceForm = sourceForm

            Me.Height = Me.sourceForm.Height + additionlHeight
            Me.Width = Me.sourceForm.Width
            Me.BackColor = Me.sourceForm.BackColor

            Me.Refresh()
        End Sub 
End Class

EDIT: typing errors.