Page 1 of 1
Subclassing Winforms?
Posted: Mon Jul 30, 2018 9:49 am
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
Subclassing Winforms?
Posted: Mon Jul 30, 2018 11:08 am
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,
Subclassing Winforms?
Posted: Tue Jul 31, 2018 5:58 am
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
Subclassing Winforms?
Posted: Tue Jul 31, 2018 8:26 am
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
Subclassing Winforms?
Posted: Fri Aug 03, 2018 11:35 am
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,