fbpx

Subclassing Winforms?

More
5 months 2 weeks ago #1 by Dick
Subclassing Winforms? was created by Dick
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

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago #2 by Johan Nel
Replied by Johan Nel on topic Subclassing Winforms?
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:
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,

______________________
Johan Nel
George, South Africa

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago #3 by Mathias Håkansson
Replied by Mathias Håkansson on topic Subclassing Winforms?
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

Please Log in or Create an account to join the conversation.

More
5 months 2 weeks ago #4 by Dick
Replied by Dick on topic Subclassing Winforms?
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

Please Log in or Create an account to join the conversation.

More
5 months 1 week ago #5 by Johan Nel
Replied by Johan Nel on topic Subclassing Winforms?
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,

______________________
Johan Nel
George, South Africa

Please Log in or Create an account to join the conversation.