Subclassing Winforms?

This forum is meant for anything you would like to share with other visitors
Post Reply
ic2
Posts: 1798
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Subclassing Winforms?

Post by ic2 »

Consider the following:

Winforms Windows A consists of a map with a table with driven distances below it. Now basically the same map with code to populate routes etc. on it is needed but instead of the table, it should show totally different info (read: controls) below.

In VO you would either copy the whole map-part and create a 2nd window, or put both set of controls on the 2nd half of the windows and hide/display depending on situation 1 or 2.

In WPF you have the option to "insert" a full alternative WPF form within WPF window A, so it all looks a lot cleaner.

Is there any recommended way to do the same for Winforms? Note that the (3rd party) tool depends on Winforms, we can not switch to WPF.

Dick/Jelle
User avatar
lumberjack
Posts: 723
Joined: Fri Sep 25, 2015 3:11 pm

Subclassing Winforms?

Post by lumberjack »

Dick,
ic2 wrote:Winforms Windows A. Now basically the same map with code to populate routes etc. on it is needed but instead of the table, it should show totally different info (read: controls) below.

In VO you would either copy the whole map-part and create a 2nd window, or put both set of controls on the 2nd half of the windows and hide/display depending on situation 1 or 2.

Is there any recommended way to do the same for Winforms? Note that the (3rd party) tool depends on Winforms, we can not switch to WPF.
How about this:

Code: Select all

class MapForm inherit Form
  protect oA as Panel
  protect oB as Panel

  method InitializeMapForm() as void
    oA := Panel{}
    // Populate PanelA with what you need
    oA:DockStyle := DockStyle.Fill
    // Poputlate PanelB
    oB := Panel{}
    // Populate PanelB with what you need
    oB:Anchor := DockStyle.Bottom
    oB:Visible := false
    self:Controls:Add(oA)
    self:Controls:Add(oB)
    // When needed
    oB:Visible := true
HTH,
MathiasHakansson
Posts: 50
Joined: Fri Feb 16, 2018 7:52 am

Subclassing Winforms?

Post by MathiasHakansson »

A good ways of doing it in winforms would be either to;

1. Create a user Control and put situation 2 controls on it. That way you only have to switch between the table in situation 1 and the user control in situation 2 or...

2. Put all controls in situation 2 in a container control, like the table layout Control. I often use the table layout control when doing multilingual applications as it makes is easy to make your layout grow and shrink depending on text lengths.

3. Use a tabcontrol and put the table in tab 1 and the situation 2 controls in tab 2. Then you can either choose to hide or show the tab captions.

/Mathias
ic2
Posts: 1798
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Subclassing Winforms?

Post by ic2 »

Hello Johan, Mathias,

The solutions you both gave are a good starter. Jelle came along additional problems but before he was about to find out how these could be solved they decided a change of course on this part of the project. I am sure the info will come in handy in future screens.

Dick
User avatar
lumberjack
Posts: 723
Joined: Fri Sep 25, 2015 3:11 pm

Subclassing Winforms?

Post by lumberjack »

Hi Dick,
ic2 wrote:The solutions you both gave are a good starter. I am sure the info will come in handy in future screens.
Just remember there are trillions of alternatives to use to get the job done.
I probably gave the real quick and dirty option, Mathias gave a more professional solution. There are also splitcontainers etc. that will do the job just as good.
Regards,
Post Reply