|
|
|
|
- Presentación
- Ejemplo de arrastrar y soltar entre un control List Box y un botón
- Ejemplo de arrastrar y soltar entre un control TreeView y un control Tabla TreeView
WINDEV: Ejemplo de arrastrar y soltar programado
Esta página de ayuda presenta dos ejemplos de arrastrar y soltar programados en una aplicación WINDEV: Ejemplo de arrastrar y soltar entre un control List Box y un botón El siguiente código se utiliza para borrar los datos encontrados en un control List Box por arrastrar y soltar a un botón gráfico que contiene una papelera de reciclaje. Sólo se permite el movimiento (cortar/pegar). El cursor de movimiento se muestra durante el movimiento (cortar/pegar) entre el control List Box y el botón "Bin". - Definición de la fuente: la control List Box
//- - Initialize the List Box control LIST_List..DnDSource = dndProgram
- Definición del objetivo: el botón BTN_Bin. En el código de inicialización del botón, los procedimientos para manejar el Arrastre y Suelta también son llamados por DnDEvent.
En este ejemplo: - el evento dndDragOver se utiliza para modificar el cursor del ratón (procedimiento"Rollover").
- el evento dndDrop se utiliza para programar el proceso de gestión de la gota. En nuestro caso, este proceso corresponde a la eliminación de un elemento de la control List Box (procedimiento"OnDrop").
//- - Initializing the BTN_Bin button BTN_Bin..DndTarget = dndProgram
// Call the OnDrop procedure when the left mouse button // is released on the BTN_Bin button DnDEvent("OnDrop", BTN_Bin, dndDrop)
// Call the OnRollover procedure when the mouse cursor // moves between the source list and the BTN_Bin button DnDEvent("OnRollover", BTN_Bin, dndDragOver)
- Definición de los procedimientos:
PROCEDURE OnRollover() // Cursor indicating the move DnDCursor(dndMove)
PROCEDURE OnDrop() // Only the move is allowed (not the copy) DnDAccept(dndMove) // Delete the element from the source control ListDelete(_DND.SourceControl)
Ejemplo de arrastrar y soltar entre un control TreeView y un control Tabla TreeView La ventana contiene: - una memoria control TreeView (llena por programación).
- una memoria control Tabla TreeView.
El siguiente ejemplo se utiliza para mover un elemento de control Treeview (o una rama y sus hijos) a una vista en árbol control Tabla. Se presentan los dos métodos de arrastrar y soltar programados. Método 1: Modo programado completo - Definición del control de la fuente: la control TreeView:
// -- Initialization code of TREE_MENU control TreeAdd(TREE_MENU, "STARTERS") TreeAdd(TREE_MENU, "STARTERS" + TAB + "Salad") TreeAdd(TREE_MENU, "STARTERS" + TAB + "Cooked meat") TreeAdd(TREE_MENU, "STARTERS" + TAB + "Prawn cocktail") TreeAdd(TREE_MENU, "MAIN COURSES") TreeAdd(TREE_MENU, "MAIN COURSES" + TAB + "Chicken stew") TreeAdd(TREE_MENU, "MAIN COURSES" + TAB + "Fish and chips") TreeAdd(TREE_MENU, "MAIN COURSES" + TAB + "Pasta with salmon") TreeAdd(TREE_MENU, "MAIN COURSES" + TAB + "Pasta alla carbonara") TreeAdd(TREE_MENU, "MAIN COURSES" + TAB + "Pork ribs") TreeAdd(TREE_MENU, "DESSERTS") TreeAdd(TREE_MENU, "DESSERTS" + TAB + "Caramel custard") TreeAdd(TREE_MENU, "DESSERTS" + TAB + "Chocolate cream") TreeAdd(TREE_MENU, "DESSERTS" + TAB + "Tiramisu") TreeAdd(TREE_MENU, "DESSERTS" + TAB + "Ice cream") TreeAdd(TREE_MENU, "DESSERTS" + TAB + "Apple pie") // Enable the programmed Drag and Drop TREE_MENU..DndSource = dndProgram
- Definición del objetivo: la control Tabla TreeView. En el código de inicialización de control Tabla TreeView, los procedimientos para manejar el Arrastre y Suelta también son llamados por DnDEvent.
En este ejemplo: - el evento dndDragOver se utiliza para modificar el cursor del ratón (procedimiento"pRollover").
- el evento dndDrop se utiliza para programar el proceso de gestión de la gota. En nuestro caso, este proceso corresponde a la copia de los elementos encontrados en la control Tabla en la control Tabla TreeView (procedimiento"pDrop")..
// -- Initializing the TreeView Table control TVT_MENU..DndTarget = dndProgram
DnDEvent(pRollover, TVT_MENU, dndDragOver) DnDEvent(pDrop, TVT_MENU, dndDrop)
- Definición de los procedimientos:
PROCÉDURE pRollover()
// Cursor indicating the move DnDCursor(dndMove)
PROCEDURE pDrop() // Only the move is allowed (not the copy) DnDAccept(dndMove) sRoot is string sLeaf is string sElement is string sChild is string sElement = TreeSelect(TREE_MENU) sRoot = ExtractString(sElement, 1, TAB, FromBeginning) sLeaf = ExtractString(sElement, 1, TAB, FromEnd) IF sLeaf = sRoot THEN IF TableSeekChild(COL_TREE, sRoot) = -1 THEN TableAddChild(TVT_MENU, 0, sRoot) END sChild = TreeGiveChild(TREE_MENU, sRoot, tvFirst) WHILE sChild <> "" TableAddChild(TVT_MENU, sRoot, sChild) sChild = TreeGiveChild(TREE_MENU, sRoot, tvNext) END ELSE IF TableSeekChild(COL_TREE, sRoot) = -1 THEN TableAddChild(TVT_MENU, 0, sRoot) END TableAddChild(TVT_MENU, sRoot, sLeaf) END
Método 2: Modo de programación simplificado - Definición del control de la fuente: la control TreeView.
TreeAdd(TREE_MENU1, "STARTERS") TreeAdd(TREE_MENU1, "STARTERS" + TAB + "Salad") TreeAdd(TREE_MENU1, "STARTERS" + TAB + "Cooked meat") TreeAdd(TREE_MENU1, "STARTERS" + TAB + "Prawn cocktail") TreeAdd(TREE_MENU1, "MAIN COURSES") TreeAdd(TREE_MENU1, "MAIN COURSES" + TAB + "Chicken stew") TreeAdd(TREE_MENU1, "MAIN COURSES" + TAB + "Fish and chips") TreeAdd(TREE_MENU1, "MAIN COURSES" + TAB + "Pasta with salmon") TreeAdd(TREE_MENU1, "MAIN COURSES" + TAB + "Pasta alla carbonara") TreeAdd(TREE_MENU1, "MAIN COURSES" + TAB + "Pork ribs") TreeAdd(TREE_MENU1, "DESSERTS") TreeAdd(TREE_MENU1, "DESSERTS" + TAB + "Caramel custard") TreeAdd(TREE_MENU1, "DESSERTS" + TAB + "Chocolate cream") TreeAdd(TREE_MENU1, "DESSERTS" + TAB + "Tiramisu") TreeAdd(TREE_MENU1, "DESSERTS" + TAB + "Ice cream") TreeAdd(TREE_MENU1, "DESSERTS" + TAB + "Apple pie") // Enable the programmed Drag and Drop TREE_MENU1..DndSource = dndProgram
- Definición del objetivo: Tabla TreeView
// -- Initializing the TreeView Table control TVT_MENU1..DndTarget = dndProgram
- Adición de EVENTOS específicos de Arrastrar y Soltar en el código del control de destino (código de control Tabla TreeView).
- Mostrar los eventos de la control Tabla TreeView ("Código" del menú emergente de control).
- Mostrar la ventana de eventos opcionales: haga clic en "Añadir otros eventos" debajo de los eventos de control actuales.
- En nuestro ejemplo, los eventos a añadir son:
- Desplácese en el destino Arrastrar / soltar (dndDragOver).
- Soltar en el objetivo Arrastrar / soltar (dndDrop).
- Introduzca el código correspondiente a las acciones a realizar:
- Evento para soltar en Arrastrar / soltar objetivo (dndDrop)
// Only the move is allowed (not the copy) DnDAccept(dndMove) sRoot is string sLeaf is string sElement is string sChild is string sElement = TreeSelect(TREE_MENU1) sRoot = ExtractString(sElement, 1, TAB, FromBeginning) sLeaf = ExtractString(sElement, 1, TAB, FromEnd) IF sLeaf = sRoot THEN IF TableSeekChild(COL_TREE1, sRoot) = -1 THEN TableAddChild(TVT_MENU1, 0, sRoot) END sChild = TreeGiveChild(TREE_MENU1, sRoot, tvFirst) WHILE sChild <> "" TableAddChild(TVT_MENU1, sRoot, sChild) sChild = TreeGiveChild(TREE_MENU1, sRoot, tvNext) END ELSE IF TableSeekChild(COL_TREE1, sRoot) = -1 THEN TableAddChild(TVT_MENU1, 0, sRoot) END TableAddChild(TVT_MENU1, sRoot, sLeaf) END
- Evento para el Rollover en el Drag/Drop del objetivo (dndDragOver)
// Cursor indicating the move DnDCursor(dndMove)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|