群聊天例子,觉得不错收藏下,利用richedit出效果图,然后截图打印。当然我个人觉得如果图片多还是调用web打印简单,各有好处。
import win.ui;
/*DSG{{*/
var winform = win.form(text="aardio form";right=498;bottom=444)
winform.add(
button={cls="button";text="打印";left=361;top=36;right=476;bottom=87;z=2};
richedit={cls="richedit";text="richedit";left=26;top=28;right=328;bottom=272;edge=1;multiline=1;wrap=1;z=1}
)
/*}}*/
import win.dlg.print;
import sys.printer;
import gdip.bitmap
import gdip.graphics;
import com.picture
math.randomize()
winform.richedit.text = string.random(100)
var start
for(i=1;5;1){
start = math.random(1,#winform.richedit.text)
winform.richedit.setsel(start,start+2)
winform.richedit.setSelCharformat( textColor = math.random(0,100000);backColor = math.random(0,100000);yHeight = math.random(200,500))
}
winform.button.oncommand = function(id,event){
bmp = com.picture.snapClient(winform.richedit.hwnd)
var printDlg = win.dlg.print(winform);
if(!printDlg.doModal()) return;
var pdc = sys.printer.device(printDlg.hdc);
pdc.start(
function(hdcPrinter){
var graphics = gdip.graphics(hdcPrinter)
graphics.drawImage(gdip.bitmap(bmp),0,0)
}
);
printDlg.free()
}
winform.show()
win.loopMessage();