button1.DoubleClick+=new EventHandler(button1_DoubleClick)使用这种方法在双击的时候并不会触发双击事件,而是会执行两次单击事件。
建议使用Label,在属性中选事件(像闪电的),双击Click和DoubleClick即可。可以改变image属性使它看起来像一个按钮。
如果一定要用Button按钮的话,可以添加一个Timer,这里起名button1和timer1。分别双击button1和timer1添加button1_Click和timer1_Tick。设置timer1的Interval为100(就是0.1秒)。
单击Button时如果Timer的Enabled为False,就启动Timer,否则关闭Timer,并执行双击 *** 作。代码如下:
private void button1_Click(object sender, EventArgs e)
{
if(timer1.Enabled)
{
timer1.Enabled = false
//以下为双击事件内容
//双击事件结束
}
else
{
Timer1.Enabled = True
}
}
Timer中启动时记录当前时间,如果当前时间距离上次记录时间超过1秒就关闭Timer并执行单击事件。代码如下:
private void timer1_Tick(object sender, EventArgs e)
{
if (timer1.Tag == "")
{
timer1.Tag = DateTime.Now.ToString()
}
else
{
if ((DateTime.Now - Convert.ToDateTime(timer1.Tag)).TotalSeconds >0.5)
{
timer1.Tag = ""
timer1.Enabled = false
//以下为单击事件内容
//单击事件结束
}
}
}
直接在 右击“ListView”属性,在出现属性的那个栏中的上面有个 闪电 的按钮,单击那个,就会出现这个"ListView"的所有事件,在里面找到一个doubleclick 的,在这的右边双击进去就会自动产生双击事件函数,Form1.Designer.cs里面也会自动添加这个双击事件
PROCESS BEFORE OUTPUT.MODULE STATUS_0500.
*
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0500.
*&---------------------------------------------------------------------*
*&Report Z_TEST12
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_TEST12.
*功能码返回值
DATA:OK_CODE TYPE SY-UCOMM,
SAVE_OK LIKE OK_CODE.
*定制对象
DATA:WA_CONTAINER TYPE SCRFNAME VALUE 'TREE1',
WA_CUSTOM_CONTAINER TYPE REF TO
CL_GUI_CUSTOM_CONTAINER,
WA_TREE TYPE REF TO CL_GUI_SIMPLE_TREE.
*NODE节点数
DATA:NODE_TABLE LIKE TABLE OF MTREESNODE,
*节点
NODE1 TYPE MTREESNODE.
*定义内表,变量需要传递,不加HEADER LINE
DATA:WA_SPFLI TYPE TABLE OF SPFLI."WITH HEADER LINE
*当双击时取得节点的KEY值与节点文本值变量
DATA:NODEKEY(200) VALUE 'NONE',NODETEXT(200) VALUE 'NONE'.
*定义对象,定义对象的双击方法,用于将该对象双击方法分*
*配到树双击事件
CLASS LCL_APPLICATION DEFINITION DEFERRED.
*----------------------------------------------------------------------*
* CLASS LCL_APPLICATION DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS LCL_APPLICATION DEFINITION.
PUBLIC SECTION.
*自定义双击方法,参数为节点关键字
METHODS HANDLE_NODE_DOUBLE_CLICK
FOR EVENT NODE_DOUBLE_CLICK
OF CL_GUI_SIMPLE_TREE
IMPORTING NODE_KEY.
ENDCLASS."LCL_APPLICATION DEFINITION
*&---------------------------------*
*对象方法实现
*&---------------------------------*
CLASS LCL_APPLICATION IMPLEMENTATION.
METHOD HANDLE_NODE_DOUBLE_CLICK.
*MESSAGE I208(00) WITH ’double’.
*取得KEY值,在窗口显示
NODEKEY = NODE_KEY.
*从节点内表中按关键字读取单个节点
READ TABLE NODE_TABLE
WITH KEY NODE_KEY = NODE_KEY
INTO NODE1.
*将节点文本在窗口显示
NODETEXT = NODE1-TEXT.
ENDMETHOD."HANDLE_NODE_DOUBLE_CLICK
ENDCLASS."LCL_APPLICATION IMPLEMENTATION
*定义自定义实例
DATA:G_APPLICATION TYPE REF TO LCL_APPLICATION.
START-OF-SELECTION.
*创建自定义对象
CREATE OBJECT G_APPLICATION.
*直接调用窗口,在窗口PBO分配双击对象
call SCREEN 0500.
*----------------------------------------------------------------------*
* MODULE USER_COMMAND_0500 INPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0500 INPUT.
SAVE_OK = OK_CODE.
CLEAR OK_CODE.
CASE SAVE_OK.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE."USER_COMMAND_0500 INPUT
*----------------------------------------------------------------------*
* MODULE STATUS_0500 OUTPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE STATUS_0500 OUTPUT.
SET PF-STATUS '500'.
IF WA_CUSTOM_CONTAINER IS INITIAL.
PERFORM CREATE_TREE.
ENDIF.
ENDMODULE."STATUS_0500 OUTPUT
*&--------------------------------*
*& 创建树及子节点
*&--------------------------------*
FORM CREATE_TREE.
*事件内表及单个事件对象
DATA:EVENTS TYPE CNTL_SIMPLE_EVENTS,
EVENT1 TYPE CNTL_SIMPLE_EVENT.
*建立定制对象
CREATE OBJECT WA_CUSTOM_CONTAINER
EXPORTING
CONTAINER_NAME = WA_CONTAINER.
*建立树对象
CREATE OBJECT WA_TREE
EXPORTING
*LIFETIME =
PARENT = WA_CUSTOM_CONTAINER
*SHELLSTYLE =
NODE_SELECTION_MODE = CL_GUI_SIMPLE_TREE=>NODE_SEL_MODE_SINGLE .
*HIDE_selectION =
*NAME=
*EXCEPTIONS
*LIFETIME_ERROR = 1
*CNTL_SYSTEM_ERROR = 2
*CREATE_ERROR = 3
*FAILED = 4
*ILLEGAL_NODE_selectION_MODE = 5
*OTHERS = 6.
IF SY-SUBRC <>0 .
*MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*WITH SY-MSGGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*开始建立树结构
CLEAR NODE1.
*节点关键字
NODE1-NODE_KEY = '国家'.
*第一层
CLEAR NODE1-RELATKEY.
CLEAR NODE1-RELATSHIP.
NODE1-HIDDEN = ''.
NODE1-DISABLED = ''.
NODE1-ISFOLDER = 'X'.
*不带ICON
CLEAR NODE1-N_IMAGE.
CLEAR NODE1-EXP_IMAGE.
CLEAR NODE1-EXPANDER.
*节点文本
NODE1-TEXT = '中国'.
*添加到节点表
APPEND NODE1 TO NODE_TABLE.
*二层节点
CLEAR NODE1.
NODE1-NODE_KEY = '成都'.
*上层关系
NODE1-RELATKEY = '国家'.
NODE1-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD
.
NODE1-HIDDEN = ''.
NODE1-DISABLED = ''.
NODE1-ISFOLDER = 'X'.
CLEAR NODE1-N_IMAGE.
CLEAR NODE1-N_IMAGE.
CLEAR NODE1-EXP_IMAGE.
CLEAR NODE1-EXPANDER.
NODE1-TEXT = '成都'.
APPEND NODE1 TO NODE_TABLE.
CLEAR NODE1.
NODE1-NODE_KEY = '深圳'.
*上层关系
NODE1-RELATKEY = '国家'.
NODE1-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD
.
NODE1-HIDDEN = ''.
NODE1-DISABLED = ''.
NODE1-ISFOLDER = 'X'.
CLEAR NODE1-N_IMAGE.
CLEAR NODE1-N_IMAGE.
CLEAR NODE1-EXP_IMAGE.
CLEAR NODE1-EXPANDER.
NODE1-TEXT = '深圳'.
APPEND NODE1 TO NODE_TABLE.
CLEAR NODE1.
NODE1-NODE_KEY = '武侯区'.
*上层关系
NODE1-RELATKEY = '成都'.
NODE1-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD
.
NODE1-HIDDEN = ''.
NODE1-DISABLED = ''.
NODE1-ISFOLDER = ''.
CLEAR NODE1-N_IMAGE.
CLEAR NODE1-EXP_IMAGE.
CLEAR NODE1-EXPANDER.
NODE1-TEXT = '武侯区'.
APPEND NODE1 TO NODE_TABLE.
CLEAR NODE1.
NODE1-NODE_KEY = '金牛区'.
*上层关系
NODE1-RELATKEY = '成都'.
NODE1-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD
.
NODE1-HIDDEN = ''.
NODE1-DISABLED = ''.
NODE1-ISFOLDER = ''.
CLEAR NODE1-N_IMAGE.
CLEAR NODE1-N_IMAGE.
CLEAR NODE1-EXP_IMAGE.
CLEAR NODE1-EXPANDER.
NODE1-TEXT = '金牛区'.
APPEND NODE1 TO NODE_TABLE.
CLEAR NODE1.
NODE1-NODE_KEY = '福田区'.
*上层关系
NODE1-RELATKEY = '深圳'.
NODE1-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD
.
NODE1-HIDDEN = ''.
NODE1-DISABLED = ''.
NODE1-ISFOLDER = ''.
CLEAR NODE1-N_IMAGE.
CLEAR NODE1-N_IMAGE.
CLEAR NODE1-EXP_IMAGE.
CLEAR NODE1-EXPANDER.
NODE1-TEXT = '福田区'.
APPEND NODE1 TO NODE_TABLE.
CLEAR NODE1.
NODE1-NODE_KEY = '南山区'.
*上层关系
NODE1-RELATKEY = '深圳'.
NODE1-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD
.
NODE1-HIDDEN = ''.
NODE1-DISABLED = ''.
NODE1-ISFOLDER = ''.
CLEAR NODE1-N_IMAGE.
CLEAR NODE1-N_IMAGE.
CLEAR NODE1-EXP_IMAGE.
CLEAR NODE1-EXPANDER.
NODE1-TEXT = '南山区'.
APPEND NODE1 TO NODE_TABLE.
*按照节点内表添加节点
CALL METHOD WA_TREE->ADD_NODES
EXPORTING
TABLE_STRUCTURE_NAME = 'MTREESNODE'
NODE_TABLE = NODE_TABLE.
*EXCEPTIONS
*ERROR)IN_NODE_TABLE = 1
*FAILED = 2
*DP_ERROR = 3
*TABLE_STRUCTURE_NAME_NOT_FOUND = 4
*OTHERS = 5.
IF SY-SUBRC <>0.
*MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*定义双击事件
EVENT1-EVENTID =
CL_GUI_SIMPLE_TREE=>EVENTID_NODE_DOUBLE_CLICK.
EVENT1-APPL_EVENT = 'X'.
APPEND EVENT1 TO EVENTS.
*添加事件内表
CALL METHOD WA_TREE->SET_REGISTERED_EVENTS
EXPORTING
EVENTS = EVENTS.
* EXCEPTIONS
* CNTL_ERROR = 1
* CNTL_SYSTEM_ERROR = 2
* ILLEAGL_EVENT_COMBINATION = 3
* OTHERS = 4
IF SY-SUBRC <>0.
*MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*将已定义的双击事件分配到树对象
SET HANDLER G_APPLICATION->HANDLE_NODE_DOUBLE_CLICK
FOR WA_TREE.
ENDFORM. "create_tree
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)