VB中如何使多个窗口同步显示 30
比如在一个窗口输入参数的赋值数据,同时在另一边显示另一个窗口,并用第一个窗口中的数据进行同步的画图(或输完以后点按钮就可画出)...
比如在一个窗口输入参数的赋值数据,同时在另一边显示另一个窗口,并用第一个窗口中的数据进行同步的画图(或输完以后点按钮就可画出)
展开
4个回答
展开全部
我做了几行。
对无标题栏的窗体,或者不从标题栏移动的情况下可用。
有标题栏并且点住标题栏移动则不理想。
代码如下,仅供参考。
1、建立模块。
option
explicit
public
oldproc
as
long
public
declare
function
setwindowlong
lib
"user32"
alias
"setwindowlonga"
(byval
hwnd
as
long,
byval
nindex
as
long,
byval
dwnewlong
as
long)
as
long
public
declare
function
sendmessage
lib
"user32"
alias
"sendmessagea"
(byval
hwnd
as
long,
byval
wmsg
as
long,
byval
wparam
as
long,
byref
lparam
as
any)
as
long
public
declare
function
callwindowproc
lib
"user32"
alias
"callwindowproca"
(byval
lpprevwndfunc
as
long,
byval
hwnd
as
long,
byval
msg
as
any,
byval
wparam
as
any,
byval
lparam
as
any)
as
long
public
const
wm_move
=
&h3
public
const
wm_lbuttondown
=
&h201
public
const
wm_lbuttonup
=
&h202
public
const
gwl_wndproc
=
(-4)
public
bnhwnd
as
long
public
function
newproc(byval
hwnd
as
long,
byval
msg
as
long,
byval
wp
as
long,
byval
lp
as
long)
as
long
if
msg
=
wm_move
then
'捕获窗体移动事件
sendmessage
bnhwnd,
wm_lbuttondown,
1,
0
sendmessage
bnhwnd,
wm_lbuttonup,
1,
0
'将消息发送到按纽,使其发生click事件
end
if
newproc
=
callwindowproc(oldproc,
hwnd,
msg,
wp,
lp)
end
function
2、在窗体上有一个按钮(名称为eventbn)
dim
原垂直
as
single,
原水平
as
single
private
sub
eventbn_click()
msgbox
"移动了"
end
sub
private
sub
form_load()
form2.show
form3.show
bnhwnd
=
eventbn.hwnd
'获得按纽句丙
oldproc
=
setwindowlong(me.hwnd,
gwl_wndproc,
addressof
newproc)
eventbn.visible
=
false
end
sub
private
sub
form_mousedown(button
as
integer,
shift
as
integer,
x
as
single,
y
as
single)
if
button
=
1
then
原垂直
=
me.top
+
y
原水平
=
me.left
+
x
end
if
end
sub
private
sub
form_mouseup(button
as
integer,
shift
as
integer,
x
as
single,
y
as
single)
me.top
=
me.top
-
原垂直
+
y
me.left
=
me.left
-
原水平
+
x
form2.top
=
form2.top
-
原垂直
+
y
form2.left
=
form2.left
-
原水平
+
x
form3.top
=
form3.top
-
原垂直
+
y
form3.left
=
form3.left
-
原水平
+
x
end
sub
3、其他窗体基本都这样。
对无标题栏的窗体,或者不从标题栏移动的情况下可用。
有标题栏并且点住标题栏移动则不理想。
代码如下,仅供参考。
1、建立模块。
option
explicit
public
oldproc
as
long
public
declare
function
setwindowlong
lib
"user32"
alias
"setwindowlonga"
(byval
hwnd
as
long,
byval
nindex
as
long,
byval
dwnewlong
as
long)
as
long
public
declare
function
sendmessage
lib
"user32"
alias
"sendmessagea"
(byval
hwnd
as
long,
byval
wmsg
as
long,
byval
wparam
as
long,
byref
lparam
as
any)
as
long
public
declare
function
callwindowproc
lib
"user32"
alias
"callwindowproca"
(byval
lpprevwndfunc
as
long,
byval
hwnd
as
long,
byval
msg
as
any,
byval
wparam
as
any,
byval
lparam
as
any)
as
long
public
const
wm_move
=
&h3
public
const
wm_lbuttondown
=
&h201
public
const
wm_lbuttonup
=
&h202
public
const
gwl_wndproc
=
(-4)
public
bnhwnd
as
long
public
function
newproc(byval
hwnd
as
long,
byval
msg
as
long,
byval
wp
as
long,
byval
lp
as
long)
as
long
if
msg
=
wm_move
then
'捕获窗体移动事件
sendmessage
bnhwnd,
wm_lbuttondown,
1,
0
sendmessage
bnhwnd,
wm_lbuttonup,
1,
0
'将消息发送到按纽,使其发生click事件
end
if
newproc
=
callwindowproc(oldproc,
hwnd,
msg,
wp,
lp)
end
function
2、在窗体上有一个按钮(名称为eventbn)
dim
原垂直
as
single,
原水平
as
single
private
sub
eventbn_click()
msgbox
"移动了"
end
sub
private
sub
form_load()
form2.show
form3.show
bnhwnd
=
eventbn.hwnd
'获得按纽句丙
oldproc
=
setwindowlong(me.hwnd,
gwl_wndproc,
addressof
newproc)
eventbn.visible
=
false
end
sub
private
sub
form_mousedown(button
as
integer,
shift
as
integer,
x
as
single,
y
as
single)
if
button
=
1
then
原垂直
=
me.top
+
y
原水平
=
me.left
+
x
end
if
end
sub
private
sub
form_mouseup(button
as
integer,
shift
as
integer,
x
as
single,
y
as
single)
me.top
=
me.top
-
原垂直
+
y
me.left
=
me.left
-
原水平
+
x
form2.top
=
form2.top
-
原垂直
+
y
form2.left
=
form2.left
-
原水平
+
x
form3.top
=
form3.top
-
原垂直
+
y
form3.left
=
form3.left
-
原水平
+
x
end
sub
3、其他窗体基本都这样。
展开全部
在第一个窗口的文本框的 TextChanged 事件里修改第二个窗口就是了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你不要让同步二迷惑了,同步是肉眼,也有时间差的
sub cmd_click()
abcd=txt.text
form1.drawobj (abcd)
form2.drawobj (abcd)
form3.drawobj (abcd)
end sub
sub cmd_click()
abcd=txt.text
form1.drawobj (abcd)
form2.drawobj (abcd)
form3.drawobj (abcd)
end sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询