Vf表单中如何设置当前时间日期,求热心人帮忙~

Vf表单中如何设置当前时间日期,求热心人帮忙~,第1张

如果仅需要激活页卡时显示时间,不需要即时变化时间,只要在页卡1(page1)的Activate事件中写代码

this.label1.Caption=TIME()

在页卡2(page2)的Activate事件中写代码:

this.label1.Caption=dtoc(date())

但如果要即时更新时间与日期,需要在表单中添加一个时间控件,设置Interval的属性值为1000,并添加timer事件方法代码:

thisform.pageframe1.page1.label1.Caption=TIME()

thisform.pageframe1.page2.label1.Caption=dtoc(date())

步骤如下:

1、通过VS/J2EE自定义组件功能

2、表单模板中(是通过xml文件配置)加入需要引用的自定义的组件文件

3、在表单中通过功能按钮来事件来调用自定义组件

试验通过测试。

以在E列显示日期时间选择控件为例:

首先从工具箱选择日期时间选择控件,并在工作表中绘制一个控件实例:DTPicker1

在工作表代码页写入如下代码

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

On Error Resume Next

Set rag = Application.Intersect(Target, Range("E:E"))

If rag Is Nothing Or rag.Address <>Target.Address Then

'这里的判断显得有些蹩脚,应该有更好办法,希望高手补充!

Else

With DTPicker1

.Top = Target.Cells(1).Top

.Left = Target.Cells(1).Left

.Width = Target.Cells(1).Width

.Height = Target.Cells(1).Height

'设置控件与所选单元格关联:

.LinkedCell = Target.Cells(1).Address

.Visible = True

End With

End If

End Sub

修正代码:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

On Error Resume Next

Set rag = Application.Intersect(Target, Range("E:E"))

'主要是这句有所区别

If (Not rag Is Nothing) Then

If Target.Address = rag.Address Then

With DTPicker1

.Visible = True

.Top = Target.Cells(1).Top

.Left = Target.Cells(1).Left

.Width = Target.Cells(1).Width

.Height = Target.Cells(1).Height

.LinkedCell = Target.Cells(1).Address

.Visible = True

End With

End If

Else

DTPicker1.Visible = False

End If

End Sub以上两种方法都可以实现在E列显示空间,在其它列不显示控件。

❤❤❤请高手回复的问题:

当代码改为如下所示时在所有的单元格都显示控件,这是为什么呢!!

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

On Error Resume Next

Set rag = Application.Intersect(Target, Range("E:E"))

'仅这句不同

If (Not rag Is Nothing) And Target.Address = rag.Address Then

With DTPicker1

.Top = Target.Cells(1).Top

.Left = Target.Cells(1).Left

.Width = Target.Cells(1).Width

.Height = Target.Cells(1).Height

.LinkedCell = Target.Cells(1).Address

.Visible = True

End With

End If

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11884685.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-19
下一篇2023-05-19

发表评论

登录后才能评论

评论列表(0条)

    保存