将2种形式锁定在一起 [英] Locking 2 forms together

查看:101
本文介绍了将2种形式锁定在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个具有应用程序启动器和wmi部分的应用程序,我想同时显示两个表单,但彼此连接.我找到了下面的代码,当我移动form2时,它会将Form 1锁定到它,但是当我尝试将其反转为Form 1时,它会起作用.请对此即时消息有所帮助.

Have an application that has an application launcher and a wmi section to it and i want to have both forms displaying at the same time but be connected to each other. I found the below code and when i move form2 it locks form 1 to it but when i try and reverse it for form one it dosent work. Please help with this im lost.

Private Sub Form1_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move, Me.Layout
        If Me.Focused Then
            form2.Left = Me.Right
            form2.Top = Me.Top
        End If
    End Sub
'on Form2:
Private Sub Form2_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move, Me.Layout
        If Me.Focused Then
            Form1.Left = Me.Left -Form1.Width
            Form1.Top = Me.Top
        End If
    End Sub

推荐答案

如果您确实需要它,则表明您的UI设计不好.您应该修改它.您不应阻止用户执行某项操作,这是用户自然权利的一部分:按照他们想要的方式排列各个顶层窗口.

如果我看到这样的行为,对我来说,这是明确的信息,请停止使用您的程序和任何产品.相信我,许多用户都会有同样的感觉.审查您的设计.

—SA
If you feel that you really need it, it tells me that your UI design is not good. You should revise it. You are not supposed to prevent the user from doing something with is the part of user''s natural rights: arrange individual top-level windows the way they want.

If I saw such behavior, for me, this is the clear message to stop using your program and any your products. Believe me, many user would feel the same. Review your design.

—SA


我认为您会发现活动表单没有集中精力,是的,这听起来很疯狂.将会发生的是表单上的子控件具有焦点.

一种解决方案是使用ContainsFocus属性,但另一种更好的方法是使用ActiveForm属性,因为您实际上对输入焦点不感兴趣,因此更好.它是一个共享属性,因此请单独使用ActiveForm而不是Me.ActiveForm.

例如
I think you''ll find that the active form is not focussed, and yes that does that sound crazy. What will be happening is that a child control on the form has the focus.

One solution would be to use the ContainsFocus property but an alternative, which is better, as you are not actually interested in the input focus, is to use the ActiveForm property. It''s a shared property so use ActiveForm on it''s own rather than Me.ActiveForm.

e.g.
If ActiveForm = Me Then
    Form1.Left = Me.Left -Form1.Width
    Form1.Top = Me.Top
End If



艾伦.



Alan.


这篇关于将2种形式锁定在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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