如何更改datagridview的位置? [英] How to change the position of the datagridview?

查看:70
本文介绍了如何更改datagridview的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我正在处理datagridview打印,我的代码正在工作,但不是我想要的样子,我想将datagridview的位置放在纸的底部,但是下面的代码将其打印在纸的上方,请帮忙我.我正在使用Visual Studio 2008

hello, im working on a datagridview print, my code is working but not how i want it to be, i want the position of the datagridview at the bottom of the paper but the code below print it above the paper, please help me. I''m using Visual Studio 2008

' Code for printing DataGridView
Dim leftMargin As Integer = 70
Dim position As Integer = leftMargin
Dim yPosition As Integer
Dim height As Integer = poDG.ColumnHeadersHeight / 2
yPosition = 0

position = leftMargin
yPosition = poDG.ColumnHeadersHeight / 2
For Each dr As DataGridViewColumn In poDG.Columns
    Dim totalWidth As Double = dr.Width
    e.Graphics.FillRectangle(New SolidBrush(Color.LightGray), New Rectangle(position, yPosition, totalWidth, height))
    e.Graphics.DrawRectangle(Pens.Black, New Rectangle(position, yPosition, totalWidth, height))
    e.Graphics.DrawString(dr.HeaderText, New Font("Verdana", 10, FontStyle.Bold), Brushes.Black, position, yPosition)
    position = position + totalWidth
Next

For Each dr As DataGridViewRow In poDG.Rows
    position = leftMargin
    yPosition = yPosition + poDG.ColumnHeadersHeight / 2
    For Each dc As DataGridViewCell In dr.Cells
        Dim totalWidth As Double = dc.OwningColumn.Width
        e.Graphics.FillRectangle(New SolidBrush(Color.White), New Rectangle(position, yPosition, totalWidth, height))
        e.Graphics.DrawRectangle(Pens.Black, New Rectangle(position, yPosition, dc.OwningColumn.Width, height))
        e.Graphics.DrawString(dc.Value, New Font("Verdana", 8, FontStyle.Regular), Brushes.Black, position, yPosition)
        position = position + totalWidth
    Next
Next

推荐答案

没关系,我解决了自己的问题,我将发布代码以供将来参考,希望对您有所帮助...

nevermind i solved my own question, i''ll post the code for future references, hope this helps...

' Code for printing DataGridView
        Dim leftMargin As Integer = 30
        Dim position As Integer = leftMargin
        Dim yPosition As Integer = 329  ' Change value to change the y-position of the DataGridView
        Dim height As Integer = poDG.ColumnHeadersHeight / 2

        position = leftMargin
        yPosition = yPosition + poDG.ColumnHeadersHeight / 2
        For Each dr As DataGridViewColumn In poDG.Columns
            Dim totalWidth As Double = dr.Width
            e.Graphics.FillRectangle(New SolidBrush(Color.White), New Rectangle(position, yPosition, totalWidth, height))
            e.Graphics.DrawRectangle(blackPen, New Rectangle(position, yPosition, totalWidth, height))
            e.Graphics.DrawString(dr.HeaderText, New Font("Times New Roman", 10, FontStyle.Bold Or FontStyle.Italic), Brushes.Black, position, yPosition, fmt)
            position = position + totalWidth
        Next

        For Each dr As DataGridViewRow In poDG.Rows
            position = leftMargin
            yPosition = yPosition + poDG.ColumnHeadersHeight / 2
            For Each dc As DataGridViewCell In dr.Cells
                Dim totalWidth As Double = dc.OwningColumn.Width
                e.Graphics.FillRectangle(New SolidBrush(Color.White), New Rectangle(position, yPosition, totalWidth, height))
                e.Graphics.DrawRectangle(Pens.White, New Rectangle(position, yPosition, dc.OwningColumn.Width, height))
                e.Graphics.DrawString(dc.Value, New Font("Verdana", 8, FontStyle.Regular), Brushes.Black, position, yPosition)
                position = position + totalWidth
            Next
        Next


这篇关于如何更改datagridview的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆