VFP以其强大的面向对象功能,方便易用的界面设计等为广大的微机用户提供了极大的方便,在它的表单中继承了Windows的复制和粘贴功能,从而提高了工作效率,方便了用户。然而当你将表单设置为顶层表单并独立运行于Windows下,就会发现表单中复制粘贴功能失效,给实际工作造成极大的不便,从而使编制的软件达不到专业水准。* W) a: x: q: O3 g
通过认真分析与实践,笔者认为,造成这一问题的原因是微软设计VFP时,只考虑了位于系统选单下的表单的复制和粘贴情况,即位于系统选单下的表单可使用复制及粘贴热键,而处于Windows下的表单完全脱离了系统选单的控制,因此复制及粘贴热键失效。
: a) j- Q6 m& V! P' Z 解决的办法是可在表单的控件(本文示例为文本框)中,为KeyPress Event编写如下事件处理程序,该事件处理程序首先将选择内容复制到Windows剪贴板上,然后再将剪贴板上的内容添加到控件中。
5 C r( U$ h% d& f { KeyPress Event
) W/ q3 R( l6 d4 G8 u- @& @* z LPARAMETERS nKeyCode, nShiftAltCtrl! O& l, Z% l. [9 e6 \ D2 z9 j$ \
if nkeycode=3
9 W4 R! M/ `% Z L && CTRL+C 复制
: [9 k. I. S( E/ m) l1 o& t0 [2 c- [ —cliptext=this.seltext
% q( v( P+ i6 U4 d8 Z endif
5 A8 X, f) ?, U5 w( M if nkeycode=22( B* C$ O2 f5 E+ J2 E
&& CTRL+V 粘贴
f: _4 d6 u0 ?! x. f5 r! l0 M do case7 D, r& v2 U8 H4 h( J# ?
case this.selstart=0' A0 I7 \9 e5 Q8 Y
this.value=—cliptext+this.value
* A# C/ ?' I- j* v case this.selstart〉=1 and this.selstart〈=len(this.value)
" J# H9 `' P* V# D5 u this.value=subs(this.value,1,this.selstart)+) e4 \/ C! L. O8 t: H% k2 N `
—cliptext+subs(this.value,this.selstart+1)) j6 {) D5 B2 N. d2 C, b
endcase
9 E2 C* F0 V8 T5 _, U- ^ endif
% o: Y7 h$ H6 C; } thisform.grid1.column1.setfocus()
- x5 U1 P3 n. c0 w) n sele recetem
" b* `# D, t6 }( E* L# t+ L if not eof()
3 c p# E U! u+ P& k* [0 s2 V skip" g- k: J' T5 I g1 u% f T) [; A3 n
endif
4 l6 c2 ]" Z w) P& Q, r# u/ P$ { thisform.refresh |