2012-02-10 105 views

回答

2

我已经找到了使用GC(canvas)类将任意控件(widget)渲染成图像的方式。这里是:

dragSource.addDragListener(new DragSourceListener() { 
    @Override 
    public void dragStart(DragSourceEvent dragSourceEvent) { 
     // getting control widget - Composite in this case 
     Composite composite = (Composite) ((DragSource) dragSourceEvent.getSource()).getControl(); 
     // Getting dimensions of this widget 
     Point compositeSize = composite.getSize(); 
     // creating new GC 
     GC gc = new GC(composite); 
     // Creating new Image 
     Image image = new Image(Display.getCurrent(),compositeSize.x,compositeSize.y); 
     // Rendering widget to image 
     gc.copyArea(image,0,0); 
     // Setting widget to DnD image 
     dragSourceEvent.image = image; 
    } 
... other overriden methods ... 
} 
+0

记得把你的资源放在'dragFinished'中。 :) – GGrec 2013-08-09 15:10:41

0

您可以使用一个未遵循鼠标位置的未修饰Shell,并在该Shell中包含要显示的小部件。