是否可以避免对 SplitContainer 的关注?

发布于 2024-07-28 07:50:39 字数 279 浏览 4 评论 0原文

WinForm SplitContainer 在拖动或单击时获得焦点,而 Splitter 则不会。 这样做的副作用是,拖动 SplitContainer 栏会触发其他控件上的 Leave/Validate,我需要避免这种情况。

我已经尝试将 TabStop 和 CausesValidation 设置为 False,但没有成功。

有没有办法阻止 SplitContainer 获得焦点? (没什么大不了的,我仍然可以使用旧的 Splitter,但我失去了一些不错的 VS 属性......)

The WinForm SplitContainer gets the focus when it's dragged or clicked, while the Splitter does not.
The side-effect of this, is that dragging a SplitContainer bar fires Leave/Validate on other controls, and I need to avoid this.

I already tried setting TabStop and CausesValidation to False, but with no success.

Is there a way to stop the SplitContainer from getting focused? (not a big deal, I can still use the old Splitter, but I lose some nice VS properties...)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

删除会话 2024-08-04 07:54:30

Filini,

拆分容器唯一获得焦点的时间是当您实际移动拆分器时。 所以我会在你的验证和离开事件中做类似的事情。

private void Button_Leave(object sender, EventArgs e)
{
    if(SplitContainer.ContainsFocus)
        return;
}

我重现了您的问题,当我添加上面的内容时,它当然仍然调用该事件,但是代码执行不会发生,因为在您移动拆分器时 SplitContainer 具有焦点。

希望有帮助。

Filini,

The only time that the splitcontainer would have focus is when you are actually moving the splitter. So I would so something like this in your validating and leave events.

private void Button_Leave(object sender, EventArgs e)
{
    if(SplitContainer.ContainsFocus)
        return;
}

I reproduced your issue and when I added the above it still calls the event of course, but the code execution doesn't occur because the SplitContainer has focus while you are moving the splitter.

Hope that helps.

蓝海 2024-08-04 07:53:40

尝试使用以下代码:

//This code will move the focus from the splitContainer to TreeView shortly after moved.
private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e) {
    if(this.splitContainer1.CanFocus) {
       this.splitContainer1.ActiveControl = this.treeView1;
    }
}

Try with this code:

//This code will move the focus from the splitContainer to TreeView shortly after moved.
private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e) {
    if(this.splitContainer1.CanFocus) {
       this.splitContainer1.ActiveControl = this.treeView1;
    }
}
黑凤梨 2024-08-04 07:52:55

删除 SplitContainer 控件并手动将其替换为 Panel 和 Splitter 控件。 多一点努力,但结果会干净得多。

Remove the SplitContainer control and replace it manually with Panel and Splitter controls. A little more effort, but a much cleaner outcome.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文