亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 編程 > .NET > 正文

Dotnet總結(3)--打印

2024-07-21 02:17:02
字體:
來源:轉載
供稿:網友

eg:
private datagridprinter m_odatagridprinter;
protected system.windows.forms.printpreviewdialog printpreviewdialog1;
private system.windows.forms.printdialog printdialog1;
public system.drawing.printing.printdocument printdocument1;
// 預覽
try
            {   
m_odatagridprinter = new datagridprinter(this.datagrid_brand, printdocument1, (datatable)this.datagrid_brand.datasource);
                this.printpreviewdialog1.showdialog();
catch
            {
                messagebox.show("沒有找到打印機,不能預覽!");
            }


// 打印
        public dialogresult print()
        {
            try
            {
//                datatable odttmp = (datatable)this.datagrid_brand.datasource;
//                if (odttmp==null || odttmp.rows.count<=0)
//                {
//                    messagebox.show("主窗口中沒有數據,請進行/"查詢/"或者/"顯示所有/"等操作,將您要打印的數據顯示在主窗口中,然后再進行打印!");
//                    return dialogresult.cancel;                   
//                }
                m_odatagridprinter = new datagridprinter(this.datagrid_brand, printdocument1, (datatable)this.datagrid_brand.datasource);
               
                if (this.printdialog1.showdialog() == dialogresult.ok)
                {
                    this.printdocument1.print();
                    return dialogresult.ok;
                }
                else
                {
                    return dialogresult.cancel;
                }
            }
            catch
            {
                messagebox.show("沒有找到打印機,不能打印!");
                return dialogresult.cancel;
            }
            return dialogresult.ok;
        }

// 事件定義
this.printdocument1.documentname = "brand";
            this.printdocument1.printpage += new system.drawing.printing.printpageeventhandler(this.printdocument1_printpage);

// 事件響應
private void printdocument1_printpage(object sender, system.drawing.printing.printpageeventargs e)
        {                   
            e.hasmorepages = m_odatagridprinter.drawdatagrid(e.graphics);
            if (e.hasmorepages)
            {
                m_odatagridprinter.pagenumber += 1;
            }
            else
            {
                m_odatagridprinter.pagenumber = 1;
                m_odatagridprinter.rowcount = 0;
            }



// 基類定義
imports system.drawing.printing
imports system.windows.forms
imports system.drawing



public class datagridprinter

    public rowcount as integer = 0
    public pagenumber as integer = 1

    private m_datatable as datatable
    private m_datagrid as datagrid
    private m_imagearray(2) as image

    private m_pagewidth as integer
    private m_pagewidthminusmargins as integer
    private m_pageheight as integer
    private m_adjcolumnby as integer
    private m_istoowide as boolean
    private m_datagridwidth as integer

    private m_sselectstring as string

    private const c_topmargin as integer = 50
    private const c_bottommargin as integer = 50
    private const c_leftmargin as integer = 50
    private const c_rightmargin as integer = 50
    private const c_verticalcellleeway as integer = 10

    public sub new(byval dg as datagrid, byval pd as printdocument, byval dt as datatable)
        m_sselectstring = ""

        m_datagrid = dg
        m_datatable = dt

        'set the document as landscape
        pd.defaultpagesettings.landscape = true

        'extract our width and height values
        m_pageheight = pd.defaultpagesettings.papersize.width
        m_pagewidth = pd.defaultpagesettings.papersize.height
        m_pagewidthminusmargins = m_pagewidth - (c_leftmargin + c_rightmargin)

        'hard-coded images
        'm_imagearray(0) = image.fromfile("images/major.gif")
        'm_imagearray(1) = image.fromfile("images/medium.gif")
        'm_imagearray(2) = image.fromfile("images/minor.gif")

        m_datagridwidth = getdatagridwidth()

        'set up some adjustments to scale the output later
        if m_datagrid.width > m_pagewidthminusmargins then
            m_adjcolumnby = m_datagrid.width - m_pagewidthminusmargins
            m_datagridwidth = m_datagridwidth - m_adjcolumnby
            m_istoowide = true
        else
            m_adjcolumnby = m_pagewidthminusmargins - m_datagrid.width
            m_datagridwidth = m_datagridwidth + m_adjcolumnby
            m_istoowide = false
        end if
    end sub


    public sub new(byval dg as datagrid, byval pd as printdocument, byval dt as datatable, byval headstring as string)
        m_sselectstring = headstring

        m_datagrid = dg
        m_datatable = dt

        'set the document as landscape
        pd.defaultpagesettings.landscape = true

        'extract our width and height values
        m_pageheight = pd.defaultpagesettings.papersize.width
        m_pagewidth = pd.defaultpagesettings.papersize.height
        m_pagewidthminusmargins = m_pagewidth - (c_leftmargin + c_rightmargin)

        'hard-coded images
        'm_imagearray(0) = image.fromfile("images/major.gif")
        'm_imagearray(1) = image.fromfile("images/medium.gif")
        'm_imagearray(2) = image.fromfile("images/minor.gif")

        m_datagridwidth = getdatagridwidth()

        'set up some adjustments to scale the output later
        if m_datagrid.width > m_pagewidthminusmargins then
            m_adjcolumnby = m_datagrid.width - m_pagewidthminusmargins
            m_datagridwidth = m_datagridwidth - m_adjcolumnby
            m_istoowide = true
        else
            m_adjcolumnby = m_pagewidthminusmargins - m_datagrid.width
            m_datagridwidth = m_datagridwidth + m_adjcolumnby
            m_istoowide = false
        end if
    end sub


    public function drawdatagrid(byval g as graphics) as boolean
        try
            drawpageheader(g)
            return drawpagerows(g)
        catch ex as exception
            '      messagebox.show(ex.message.tostring())
            return false
        end try
    end function

    private sub drawpageheader(byval g as graphics)

        'use this format when drawing later
        dim cellformat as new stringformat
        cellformat.trimming = stringtrimming.word
        cellformat.formatflags = stringformatflags.nowrap or stringformatflags.linelimit

        if m_sselectstring.length > 0 then

            'temp width to draw this column
            dim columnwidth as integer = m_pagewidthminusmargins - 10

            'create a layout rectangle to draw within.
            dim cellbounds as new rectanglef(c_leftmargin + 12, c_topmargin - 9, columnwidth, m_datagrid.preferredrowheight + c_verticalcellleeway - 3)

            g.drawstring(m_sselectstring, m_datagrid.font, new solidbrush(m_datagrid.headerforecolor), cellbounds, cellformat)

            'create the header rectangle
            'dim headerbounds as new rectanglef(c_leftmargin, c_topmargin, m_pagewidthminusmargins, m_datagrid.headerfont.sizeinpoints + c_verticalcellleeway)
            dim headerbounds as new rectanglef(c_leftmargin + 12, c_topmargin - 3 - 9 - 9 + m_datagrid.preferredrowheight + c_verticalcellleeway, m_pagewidthminusmargins - 10, m_datagrid.preferredrowheight + c_verticalcellleeway - 3)

            'draw the header rectangle
            g.fillrectangle(new solidbrush(m_datagrid.headerbackcolor), headerbounds)
        else
            'create the header rectangle
            'dim headerbounds as new rectanglef(c_leftmargin, c_topmargin, m_pagewidthminusmargins, m_datagrid.headerfont.sizeinpoints + c_verticalcellleeway)
            dim headerbounds as new rectanglef(c_leftmargin + 12, c_topmargin - 9, m_pagewidthminusmargins - 10, m_datagrid.preferredrowheight + c_verticalcellleeway - 3)

            'draw the header rectangle
            g.fillrectangle(new solidbrush(m_datagrid.headerbackcolor), headerbounds)

        end if



        dim xposition as single = c_leftmargin + 12 ' +12 for some padding

        'find the column names from the tablestyle
        dim cs as datagridcolumnstyle
        for each cs in m_datagrid.tablestyles(0).gridcolumnstyles
            if cs.width > 0 then

                'temp width to draw this column
                dim columnwidth as integer = cs.width

                'scale the summary column width
                'note: just a quick way to fit the text to the page width
                'this is not the best way to do this but it handles the most
                'common ui path for this demo app
                if cs.mappingname = "tasksummary" and m_istoowide then
                    columnwidth -= m_adjcolumnby
                elseif cs.mappingname = "tasksummary" then
                    columnwidth += m_adjcolumnby
                end if

                if m_sselectstring.length > 0 then
                    'create a layout rectangle to draw within.
                    dim cellbounds as new rectanglef(xposition, c_topmargin - 9 + m_datagrid.preferredrowheight + c_verticalcellleeway - 3, columnwidth, m_datagrid.headerfont.sizeinpoints + c_verticalcellleeway)

                    'draw the column name
                    g.drawstring(cs.headertext, m_datagrid.headerfont, new solidbrush(m_datagrid.headerforecolor), cellbounds, cellformat)
                else
                    'create a layout rectangle to draw within.
                    dim cellbounds as new rectanglef(xposition, c_topmargin, columnwidth, m_datagrid.headerfont.sizeinpoints + c_verticalcellleeway)

                    'draw the column name
                    g.drawstring(cs.headertext, m_datagrid.headerfont, new solidbrush(m_datagrid.headerforecolor), cellbounds, cellformat)
                end if

                'adjust the next x pos
                xposition += columnwidth
            end if
        next


    end sub

    private function drawpagerows(byval g as graphics) as boolean

        'dim yposition as single = c_topmargin + m_datagrid.headerfont.sizeinpoints + (c_verticalcellleeway * 2)
        dim yposition as single = c_topmargin + m_datagrid.preferredrowheight
        if m_sselectstring.length > 0 then
            yposition += m_datagrid.preferredrowheight
        end if

        'use this format when drawing later
        dim cellformat as new stringformat
        cellformat.trimming = stringtrimming.word
        cellformat.formatflags = stringformatflags.nowrap or stringformatflags.linelimit

        try
            if m_datatable.defaultview.count <= 0 then
                dim xposition as single = c_leftmargin + 12 ' +12 for some padding
                dim cellbounds as new rectanglef(xposition, yposition, c_leftmargin - c_rightmargin, m_datagrid.preferredrowheight)
                g.drawstring("對不起,沒有找到您需要打印的數據,請您確認程序主窗口中有您需要打印的數據!", m_datagrid.font, new solidbrush(m_datagrid.headerforecolor), cellbounds, cellformat)
            end if
        catch ex as exception
            dim xposition as single = c_leftmargin + 12 ' +12 for some padding
            dim cellbounds as new rectanglef(xposition, yposition, c_leftmargin - c_rightmargin, m_datagrid.preferredrowheight)
            g.drawstring("對不起,沒有找到您需要打印的數據,請您確認程序主窗口中有您需要打印的數據!", m_datagrid.font, new solidbrush(m_datagrid.headerforecolor), cellbounds, cellformat)
            return false
        end try



            'loop each visible row
            dim i as integer = 0
            for i = rowcount to (m_datatable.defaultview.count - 1)

                dim xposition as single = c_leftmargin + 12 ' +12 for some padding
                'g.drawline(new pen(m_datagrid.gridlinecolor, 1), xposition - 3, yposition - 3, xposition - 3, yposition + m_datagrid.preferredrowheight + c_verticalcellleeway - 1)

                'loop the columns of this row, if the column is visible
                'then print the cell value
                dim cs as datagridcolumnstyle
                for each cs in m_datagrid.tablestyles(0).gridcolumnstyles
                    if cs.width > 0 then

                        'temp width to draw this column
                        dim columnwidth as integer = cs.width

                        'scale the summary column width
                        'note: just a quick way to fit the text to the page width
                        'this is not the best way to do this but it handles the most
                        'common ui path for this demo app
                        if cs.mappingname = "tasksummary" and m_istoowide then
                            columnwidth -= m_adjcolumnby
                        elseif cs.mappingname = "tasksummary" then
                            columnwidth += m_adjcolumnby
                        end if

                        'create a layout rectangle to draw within.
                        'dim cellbounds as new rectanglef(xposition, yposition, columnwidth, m_datagrid.font.sizeinpoints + c_verticalcellleeway)
                        dim cellbounds as new rectanglef(xposition, yposition, columnwidth, m_datagrid.preferredrowheight)

                        'draw the item value
                        if cs.mappingname = "商標圖片" then
                            try
                                'draw image


                                dim by as byte() = ctype(m_datatable.defaultview.item(i).item(cs.mappingname), byte())

                                dim imagetodraw as image
                                dim omemorystream as system.io.memorystream
                                omemorystream = new system.io.memorystream(by, 0, by.length)
                                'omemorystream = new system.io.memorystream((byte[])this.getcolumnvalueatrow(source, rownum),  0, ctype(m_datatable.defaultview.item(i).item(cs.mappingname), byte))
                                'omemorystream = new system.io.memorystream(ctype(m_datatable.defaultview.item(i).item(cs.mappingname), [] byte), 0, ctype(m_datatable.defaultview.item(i).item(cs.mappingname), byte))

                                'memorystream omemorystream=new memorystream((byte[])this.getcolumnvalueatrow(source, rownum),0,((byte[])this.getcolumnvalueatrow(source, rownum)).length);

                                imagetodraw = system.drawing.image.fromstream(omemorystream)
                                g.drawimage(imagetodraw, new rectangle(xposition, yposition, 125, 36))
                                'select case m_datatable.defaultview.item(i).item("prioritytext")
                                '    case "major"
                                '        g.drawimage(m_imagearray(0), new point(convert.toint32(cellbounds.x) - 5, convert.toint32(cellbounds.y)))
                                '    case "medium"
                                '        g.drawimage(m_imagearray(1), new point(convert.toint32(cellbounds.x) - 5, convert.toint32(cellbounds.y)))
                                '    case "minor"
                                '        g.drawimage(m_imagearray(2), new point(convert.toint32(cellbounds.x) - 5, convert.toint32(cellbounds.y)))
                                'end select

                            catch ex as exception
                            end try
                        else
                            'draw as short date format or regular string
                            'if m_datatable.defaultview.item(i).item(cs.mappingname).gettype() is gettype(datetime) then
                            '    g.drawstring(string.format("{0:d}", m_datatable.defaultview.item(i).item(cs.mappingname)), m_datagrid.font, new solidbrush(m_datagrid.headerforecolor), cellbounds, cellformat)
                            'else
                        cellbounds.y = cellbounds.y + 8
                        'cellbounds.height = cellbounds.height - 8
                            try
                                g.drawstring(ctype(m_datatable.defaultview.item(i).item(cs.mappingname), string), m_datagrid.font, new solidbrush(m_datagrid.headerforecolor), cellbounds, cellformat)
                                'end if
                            catch ex as exception
                            end try
                        cellbounds.y = cellbounds.y - 8
                        'cellbounds.height = cellbounds.height + 8
                        end if

                        g.drawline(new pen(m_datagrid.gridlinecolor, 1), xposition, yposition - 4, xposition, yposition + m_datagrid.preferredrowheight + c_verticalcellleeway - 1)

                        'adjust the next x pos
                        xposition += columnwidth

                    end if
                next


                'set the rowcount (which is used for a possible next page)
                rowcount += 1

                g.drawline(new pen(m_datagrid.gridlinecolor, 1), m_pagewidthminusmargins + c_leftmargin - 1, yposition - 4, m_pagewidthminusmargins + c_leftmargin - 1, yposition + m_datagrid.preferredrowheight + c_verticalcellleeway - 1)

                'finished with this row, draw a nice line
                g.drawline(new pen(m_datagrid.gridlinecolor, 1), c_leftmargin + 12, yposition + m_datagrid.preferredrowheight + c_verticalcellleeway - 2, m_pagewidthminusmargins + c_leftmargin, yposition + m_datagrid.preferredrowheight + c_verticalcellleeway - 2)

                'adjust the next y pos
                'yposition += m_datagrid.headerfont.sizeinpoints + c_verticalcellleeway + 3
                yposition += m_datagrid.preferredrowheight + c_verticalcellleeway + 3

                'if at end of page exit out for next page
                if yposition * pagenumber > pagenumber * (m_pageheight - (c_bottommargin + c_topmargin)) then
                    return true
                end if
            next


        return false
    end function

    private function getdatagridwidth() as integer
        try
            dim cs as datagridcolumnstyle
            dim dgwidth as integer = 0
            for each cs in m_datagrid.tablestyles(0).gridcolumnstyles
                if cs.width <> 0 then
                    dgwidth = dgwidth + cs.width
                end if
            next
            return dgwidth
        catch ex as exception
            throw ex
        end try
    end function
end class
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
欧美精品在线免费| 久久亚洲国产精品成人av秋霞| 最新中文字幕亚洲| 精品夜色国产国偷在线| 久久精品青青大伊人av| 日韩网站免费观看高清| 久久久国产精彩视频美女艺术照福利| 黑人与娇小精品av专区| 中文字幕久热精品在线视频| 欧美一区二区大胆人体摄影专业网站| 欧美一级淫片videoshd| 亚洲精品免费一区二区三区| 欧美黑人性视频| 91av福利视频| 亚洲国产另类久久精品| 日韩大片免费观看视频播放| 久久久久久亚洲精品不卡| 欧美激情性做爰免费视频| 国产精品久久久精品| 亚洲乱码一区av黑人高潮| 日韩在线观看免费| 韩日精品中文字幕| 午夜精品久久久久久久99黑人| 国产自摸综合网| 亚洲精品久久久久久久久| 成人免费高清完整版在线观看| 久久久电影免费观看完整版| 韩国日本不卡在线| 欧美激情一区二区久久久| 国产精自产拍久久久久久| 亚洲日本成人女熟在线观看| 国产欧美精品一区二区三区-老狼| 一本色道久久综合狠狠躁篇怎么玩| 久久久视频精品| 精品高清一区二区三区| 亚洲欧洲视频在线| 亚洲第一福利网站| 97在线观看免费高清| 国产精品女主播| 国产精品色婷婷视频| 久久久视频免费观看| 日韩成人久久久| 欧美精品videossex88| 隔壁老王国产在线精品| 欧美夜福利tv在线| 91久热免费在线视频| 日韩在线视频线视频免费网站| 精品美女永久免费视频| 国产精品久久久久久久久久久新郎| 欧美电影电视剧在线观看| 亚洲精品天天看| 成年无码av片在线| 国产一区二区在线免费| 亚洲理论在线a中文字幕| 中文字幕视频在线免费欧美日韩综合在线看| 在线精品国产成人综合| 久久久久久噜噜噜久久久精品| 亚洲二区中文字幕| 国产精品盗摄久久久| 成人免费观看49www在线观看| 日韩美女视频在线观看| 亚洲欧美综合另类中字| 91麻豆桃色免费看| 日韩av理论片| 日韩毛片在线观看| 奇米影视亚洲狠狠色| 成人h片在线播放免费网站| 成人羞羞国产免费| 欧美性开放视频| 国产999精品久久久影片官网| 伊人久久免费视频| 欧美黑人性猛交| 91精品国产综合久久久久久久久| 亚洲**2019国产| 亚洲免费人成在线视频观看| 欧美亚洲国产视频| 久久免费视频网站| 91精品久久久久久综合乱菊| 国内外成人免费激情在线视频网站| 久久人人97超碰精品888| 欧美在线视频导航| 国模私拍视频一区| 成人激情视频在线播放| 国产精品入口日韩视频大尺度| 日本一区二区在线播放| 97色在线播放视频| 日韩高清av一区二区三区| 国产日韩欧美成人| 2020久久国产精品| 亚洲人成网站777色婷婷| 成人在线中文字幕| 成人亚洲欧美一区二区三区| 国产精品视频白浆免费视频| 国产日韩综合一区二区性色av| 日韩免费精品视频| 久久精品中文字幕电影| 在线观看精品自拍私拍| 日韩黄色在线免费观看| 亚洲男人天天操| 日本高清+成人网在线观看| 日韩中文字幕在线| 亚洲人在线观看| 日韩欧美亚洲国产一区| 久久久噜噜噜久久久| 国产精品福利网| 色综合久久精品亚洲国产| 欧美人交a欧美精品| www.美女亚洲精品| 日韩精品视频在线免费观看| 久久av资源网站| 久久成人免费视频| 欧美成人精品一区二区| 亚洲一区二区久久| 国产精品网址在线| 韩日精品中文字幕| 欧美一级大片在线观看| 亚洲另类激情图| 国产欧美精品在线| 国产精品日韩在线播放| 中日韩美女免费视频网站在线观看| 这里只有精品久久| 欧美壮男野外gaytube| 国产成人精品视频在线观看| 欧美激情中文字幕乱码免费| www.亚洲成人| 国产视频在线一区二区| 亚洲va欧美va在线观看| 日韩精品一区二区视频| 欧美午夜片欧美片在线观看| 色哟哟网站入口亚洲精品| 精品一区二区三区三区| 韩国国内大量揄拍精品视频| 高清欧美性猛交xxxx黑人猛交| 国产91网红主播在线观看| 国产精品一区久久| 最近2019年手机中文字幕| 亚洲爱爱爱爱爱| 日韩**中文字幕毛片| 国产中文欧美精品| 欧美激情性做爰免费视频| 日韩精品视频在线观看网址| 国产suv精品一区二区三区88区| 国产一区在线播放| 色妞在线综合亚洲欧美| 91免费福利视频| 日韩资源在线观看| 亚洲免费伊人电影在线观看av| 不卡av电影院| 欧美日韩成人免费| 国产精品一区=区| 日本午夜人人精品| 91亚洲精品在线观看| 国产日韩精品视频| 日韩av一区在线| 成人激情综合网| 成人黄色av免费在线观看| 亚洲欧美视频在线| 日韩禁在线播放| 亚洲激情 国产| 韩国精品久久久999| 国产在线播放91| 啊v视频在线一区二区三区| 日韩a**站在线观看| 欧美成人性色生活仑片|