国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

按鈕列的應用。(在datagrid中加入按鈕列,winforms)

2024-07-21 02:25:16
字體:
來源:轉載
供稿:網友
public class mybuttondatagridtablestyle1 
    inherits system.windows.forms.datagridtextboxcolumn 

#region " windows 窗體設計器生成的代碼 " 

    public sub new() 
        mybase.new() 

        '該調用是 windows 窗體設計器所必需的。 
        initializecomponent() 

        '在 initializecomponent() 調用之后添加任何初始化 

    end sub 

    'usercontrol 重寫 dispose 以清理組件列表。 
    protected overloads overrides sub dispose(byval disposing as boolean) 
        if disposing then 
            if not (components is nothing) then 
                components.dispose() 
            end if 
        end if 
        mybase.dispose(disposing) 
    end sub 

    'windows 窗體設計器所必需的 
    private components as system.componentmodel.icontainer 

    '注意:以下過程是 windows 窗體設計器所必需的 
    '可以使用 windows 窗體設計器修改此過程。 
    '不要使用代碼編輯器修改它。 
    <system.diagnostics.debuggerstepthrough()> private sub initializecomponent() 
        components = new system.componentmodel.container() 
    end sub 

#end region 
    public delegate sub datagridcellbuttonclickeventhandler(byval sender as object, byval e as datagridcellbuttonclickeventargs) 
    public event cellbuttonclicked as datagridcellbuttonclickeventhandler 

    private m_face as bitmap 
    private m_facepressed as bitmap 
    private m_columnnum as integer 
    private m_row as integer 


    public sub new(byval colnum as integer) 
        m_columnnum = colnum 
        m_row = -1 

        try 
            dim strm as system.io.stream = me.gettype().assembly.getmanifestresourcestream("btnface.bmp") 
            m_face = new bitmap(strm) 
            strm = me.gettype().assembly.getmanifestresourcestream("btnpressed.bmp") 
            m_facepressed = new bitmap(strm) 
        catch 
        end try 
    end sub 

    protected overloads overrides sub edit(byval [source] as system.windows.forms.currencymanager, byval rownum as integer, byval bounds as system.drawing.rectangle, byval [readonly] as boolean, byval instanttext as string, byval cellisvisible as boolean) 

    end sub 

   

    public sub handlemouseup(byval sender as object, byval e as mouseeventargs) 
        dim dg as datagrid = me.datagridtablestyle.datagrid 
        dim hti as datagrid.hittestinfo = dg.hittest(new point(e.x, e.y)) 
        dim isclickincell as boolean = hti.column = me.m_columnnum 

        m_row = -1 

        dim rect as new rectangle(0, 0, 0, 0) 

        if isclickincell then 
            rect = dg.getcellbounds(hti.row, hti.column) 
            isclickincell = e.x > rect.right - me.m_face.width 
        end if 
        if isclickincell then 
            dim g as graphics = graphics.fromhwnd(dg.handle) 
            g.drawimage(me.m_face, rect.right - me.m_face.width, rect.y) 
            g.dispose() 

            raiseevent cellbuttonclicked(me, new datagridcellbuttonclickeventargs(hti.row, hti.column)) 

        end if 
    end sub 

    public sub handlemousedown(byval sender as object, byval e as mouseeventargs) 
        dim dg as datagrid = me.datagridtablestyle.datagrid 
        dim hti as datagrid.hittestinfo = dg.hittest(new point(e.x, e.y)) 
        dim isclickincell as boolean = hti.column = me.m_columnnum 
        dim rect as new rectangle(0, 0, 0, 0) 
        if isclickincell then 
            rect = dg.getcellbounds(hti.row, hti.column) 
            isclickincell = e.x > rect.right - me.m_face.width 
        end if 

        if isclickincell then 

            dim g as graphics = graphics.fromhwnd(dg.handle) 
            g.drawimage(me.m_facepressed, rect.right - me.m_facepressed.width, rect.y) 
            g.dispose() 
            m_row = hti.row 
        end if 
    end sub 

    '重繪 
    protected overloads overrides sub paint(byval g as system.drawing.graphics, byval bounds as system.drawing.rectangle, byval [source] as system.windows.forms.currencymanager, byval rownum as integer, byval backbrush as system.drawing.brush, byval forebrush as system.drawing.brush, byval aligntoright as boolean) 

        dim parent as datagrid = me.datagridtablestyle.datagrid 
        '如果該行是選中行 或者 當前單元格的行號=點擊行的行號并且當前單元格的列號等于new的列號參數 
        dim current as boolean = parent.isselected(rownum) or (parent.currentrowindex = rownum and parent.currentcell.columnnumber = me.m_columnnum) 

        dim backcolor as color 
        if current then backcolor = parent.selectionbackcolor else backcolor = parent.backcolor 
        dim forecolor as color 
        if current then forecolor = parent.selectionforecolor else forecolor = parent.forecolor 

        '請空單元格 
        g.fillrectangle(new solidbrush(backcolor), bounds) 

        ' 繪制值 
        dim s as string = me.getcolumnvalueatrow([source], rownum).tostring() 'parent[rownum, 0].tostring() + ((parent[rownum, 1].tostring())+ "  ").substring(0,2); 
       
        g.drawstring(s, parent.font, new solidbrush(forecolor), bounds.x, bounds.y) 


        dim bm as bitmap 
        if m_row = rownum then bm = me.m_facepressed else bm = me.m_face 
        g.drawimage(bm, bounds.right - bm.width, bounds.y) 
    end sub 
end class 


調用代碼: 

private function getdatagridstyle(byval table as datatable) as datagridtablestyle 
        dim style as new datagridtablestyle() 
        style.mappingname = table.tablename 
        style.rowheaderwidth = 15 
        dim i as integer 
        for i = 0 to table.columns.count - 1 
            if i = 1 then 
                dim textbuttoncolstyle as new mybuttondatagridtablestyle1(i) 'pass the column# 
                textbuttoncolstyle.headertext = table.columns(i).columnname 
                textbuttoncolstyle.mappingname = table.columns(i).columnname 

                'hookup our cellbutton handler... 
                addhandler textbuttoncolstyle.cellbuttonclicked, addressof handlecellbuttonclick 

                style.gridcolumnstyles.add(textbuttoncolstyle) 

                'hook the mouse handlers 
                addhandler datagrid1.mousedown, addressof textbuttoncolstyle.handlemousedown 
                addhandler datagrid1.mouseup, addressof textbuttoncolstyle.handlemouseup 
            else 
                dim c as new datagridtextboxcolumn() 
                c.headertext = table.columns(i).columnname 
                c.mappingname = table.columns(i).columnname 
                style.gridcolumnstyles.add(c) 
            end if 
        next 
        return style 
    end function 
    private sub handlecellbuttonclick(byval sender as object, byval e as datagridcellbuttonclickeventargs) 
        messagebox.show(("row " + e.rowindex.tostring() + "  col " + e.colindex.tostring() + " clicked.")) 
    end sub 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 静安区| 静海县| 綦江县| 巢湖市| 炉霍县| 神木县| 察雅县| 浦北县| 双辽市| 桂阳县| 岳阳县| 武威市| 车险| 辽宁省| 缙云县| 中牟县| 格尔木市| 闻喜县| 堆龙德庆县| 确山县| 建平县| 南充市| 绥化市| 壤塘县| 阿拉善右旗| 天气| 嘉祥县| 天柱县| 凉山| 清徐县| 股票| 且末县| 兴海县| 忻州市| 靖江市| 花莲县| 徐闻县| 宝坻区| 连山| 应用必备| 昆山市|