插件,自动滚动-太自动(并且可能覆盖现有实例中的方法) [英] Plugins, Autoscroll - too auto (and maybe overriding a method in an existing instance)

查看:50
本文介绍了插件,自动滚动-太自动(并且可能覆盖现有实例中的方法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello world,
我想介绍一些目前困扰我的东西,希望你们中的一些人可能会发现这很有趣/很有趣;)

好的,在我们公司中,我们使用一个应用程序,该应用程序通过MEF导入其子应用程序,并将其作为MDI停靠在其形式中.
插件名称列在左侧列表中(用作菜单),单击后显示在右侧区域.
没什么特别的...

如果有人单击插件名称,则PluginManager对象会找出相关的插件并加载.然后,插件将表单(System.Windows.Form)返回给PluginManager,然后将其停靠/显示在righ区域中,如前所述.

在停靠之前,PluginManager将以下内容添加到表单:

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:

Form frm = GetForm(key);
frm.AutoScroll = true;
frm.AutoScrollMargin = new Size(5, 5);
frm.AutoScrollMinSize = frm.Size;



必要时会添加滚动条,因为我们的某些用户仍在使用小型监视器.
我不得不提到,上面的代码是最近添加到PluginManager的,并且从一开始就不存在.

到目前为止,还不错,可以滚动的形式...很可爱.
然后,我意识到单击这些表单中的控件"可以使表单自动滚动到该控件上,从而成为焦点(老实说,我不得不承认我一开始并不了解这种行为,现在我知道了).

然后我发现覆盖表格中的以下内容可以解决问题



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

protected override System.Drawing.Point ScrollToControl(Control activeControl)
{
    return DisplayRectangle.Location;
}



因此,现在唯一的问题是将其实现到大约30个现有插件中.
这是真正的麻烦开始的地方.
我考虑过将返回的插件形式更改为继承自System.Windows.Form并重写ScrollToControl方法的某种形式,但这需要重新编译每个插件...

如何在PluginManager返回的插件的现有形式实例中覆盖该方法...将以某种方式起作用?

更新:
我的主要目标不是在每个插件中实现某些功能(其中很多,我什至没有访问权限),而是让PluginManager在可能的情况下以某种方式处理此问题...


任何想法都很高兴,
欢呼和最诚挚的问候
安迪

PS ...也许不是那么有趣;)



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 ;)

推荐答案

AFAIK,原始ScrollToControl返回活动控件的AutoScrollOffset.您可以在插件中添加mousedown事件处理程序形成并设置
ActiveControl.AutoScrollOffset = DisplayRectangle.Location.

这是相同的逻辑,并且如果重写ScrollToControl可以正常工作.
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.


这篇关于插件,自动滚动-太自动(并且可能覆盖现有实例中的方法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆