Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello world,
I want to bring something that is currently bugging me to light and hope that some of you might find this an interesting/entertaining one ;)

Ok, in our company we use a application that imports its sub-application via MEF and docks them as MDI's into its form.
Plugin-names are listed in a list on the left (serving as menu) and are shown in the right area upon click.
Nothing special...

If someone clicks a plugin-name, the related plugin is figured out by the PluginManager object and loaded. The plugin then returns a form (System.Windows.Form) to the PluginManager which is then docked/shown in the righ area as mentioned.

Before docking the PluginManager adds the following to the form:
C#
Form frm = GetForm(key);
frm.AutoScroll = true;
frm.AutoScrollMargin = new Size(5, 5);
frm.AutoScrollMinSize = frm.Size;


That adds scrollbars if necessary because some of our users still use small monitors.
I have to mention that the above code was added to the PluginManager lately and didn't exist from the beginning.

So far so good, scrollable forms... lovely.
Then I realized that clicking Controls within these forms made the form autoscroll to the control getting focused (honestly I have to admit that I wasn't aware of this behavior in first place - now I am).

I then figured out that overriding the following in the form fixed the problem
C#
protected override System.Drawing.Point ScrollToControl(Control activeControl)
{
    return DisplayRectangle.Location;
}


So now the only problem is implementing it into about 30 existing plugins.
Here is where the actual trouble starts.
I thought about changing the plugins returned form to something that inherits from System.Windows.Form and overrides the ScrollToControl method, but that requires recompiling every plugin...

What about overriding the method in an existing instance of the form that the plugin returns by the PluginManager... would that work somehow?

Update:
My main goal is not to implement something into every plugin (there are quite a few of that and to some I don't even have access) but to let the PluginManager handle this somehow if possible...


Any idea is happily appreciated,
cheers and best regards
Andy

PS...maybe it is not that entertaining ;)
Posted
Updated 15-Nov-11 23:33pm
v3
Comments
BillWoodruff 16-Nov-11 6:07am    
Just curious: are you saying that the Plug-In itself instantiates a Form, and passes that in to the Plug-In manager: rather than the Plug-In manager actually instantiates the Form ?
hoernchenmeister 16-Nov-11 6:53am    
The Plugin has a method that is called by the PluginManager and returns an instantiated form to the Pluginmanager which it then docks in the right area (tabbed MDI), so basically yes ;)
BillWoodruff 16-Nov-11 9:27am    
An interesting question +5. I suppose there is no way, using Reflection to somehow insert into the instance of the Form passed by the Plug-In an override method. And, I also assume the last thing you would want to do would be to recursively enumerate the Controls in the Plug-in Form and add some event handlder, or do some hack that might involve modifying their 'AutoScrollOffset problem. Wish I were wise enough to answer this :)
hoernchenmeister 16-Nov-11 11:20am    
Thanks BillWoodruff, even if it means that I will be stuck.
I guess thats one of the things people mean when they say "think about your interface design in the first place". But it is System.Windows.Form that the plugins return, nor a derived variant that already overrides ScrollToControl ;)
It seems that there is a little bit of candy in all this, it turns out that not too many of the plugins need scrolling...
I'll sleep over this and will think about it again tomorrow with a fresh mind ;)
That helps deciding ;)

1 solution

AFAIK ,original ScrollToControl return the active control's AutoScrollOffset.You can add mousedown event handler to plugin form and set
ActiveControl.AutoScrollOffset=DisplayRectangle.Location.

This is the same logic and should work if overriding ScrollToControl works.
 
Share this answer
 
Comments
hoernchenmeister 16-Nov-11 5:31am    
I would have to add the mousedown to every control on the form, the form itself would not be enough...
The autoscroll thingy is perfectly solved by overriding the ScrollToPoint method, my main goal is to not have to implement anything into the existing plugins, but to have the PluginManager handle this problem somehow...
I would have to recompile a lot of plugins, to some of them I don't even have access...

Thanks dieforwhat for your suggestion,
it is kindly appreciated

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900