Form on the form

KraiZ

New member
Joined
Aug 28, 2023
Messages
1
Programming Experience
Beginner
I'm trying to implement VB.Net scenario in C#.
In VB.Net I have an MDI application with MDI form and several child forms.
MDI has a List Bar control on the left.
Child forms load and occupying the entire client area of MDI.
On of the child form (frmCoordinator) may load another form (frmBidCalendar) and that form should have exact the same size and location as the caller.
There is the code in the frmBidCalendar_Load:

C#:
        Dim rectCaller As Rectangle
        Dim rectLocation As Rectangle
        Try
            rectCaller = frmCoordinator.ClientRectangle
            rectLocation = frmCoordinator.RectangleToScreen(rectLocation)

            Me.Size = rectCaller.Size
            Me.Location = rectLocation.Location

I tried this in C#:
C#:
                rectCaller = frmCoordinator.ClientRectangle();

and it says 'The name frmCoordinator doesn't exist in the current contents'
I tried this:

C#:
                rectCaller = Coordinator.ClientRectangle;

and it says 'An object reference is required...'
How can I translate VB.Net code to C#?

Thank you
 
VB (and consequently VB.NET) had a concept of the default instance for objects, and those default instances are globally available. C# has no such concept. You will need to to pass the instance of the parent form to the child form.
 
Why would the new form be sizing itself based on the old form if the old form is opening the new form in the first place? Why isn't the old form setting the size of the new form before it opens it? You seem to be trying to solve a problem that you created due to poor design.

By the way, don't set the Size and the Location separately. Set the Bounds property or call the SetBounds method. In your case, the former makes more sense.
 

Latest posts

Back
Top Bottom