Click here to Skip to main content
15,891,431 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Distinguish between Reading from Barcode reader and Writing from standart keyboard Pin
Sascha Lefèvre25-Jan-16 22:36
professionalSascha Lefèvre25-Jan-16 22:36 
GeneralRe: Distinguish between Reading from Barcode reader and Writing from standart keyboard Pin
satc26-Jan-16 8:11
satc26-Jan-16 8:11 
GeneralRe: Distinguish between Reading from Barcode reader and Writing from standart keyboard Pin
Sascha Lefèvre26-Jan-16 8:44
professionalSascha Lefèvre26-Jan-16 8:44 
GeneralRe: Distinguish between Reading from Barcode reader and Writing from standart keyboard Pin
satc26-Jan-16 10:01
satc26-Jan-16 10:01 
GeneralRe: Distinguish between Reading from Barcode reader and Writing from standart keyboard Pin
Sascha Lefèvre26-Jan-16 10:15
professionalSascha Lefèvre26-Jan-16 10:15 
GeneralRe: Distinguish between Reading from Barcode reader and Writing from standart keyboard Pin
satc26-Jan-16 10:27
satc26-Jan-16 10:27 
GeneralRe: Distinguish between Reading from Barcode reader and Writing from standart keyboard Pin
Sascha Lefèvre26-Jan-16 11:23
professionalSascha Lefèvre26-Jan-16 11:23 
Questionbouton imprimer DGV complet Pin
Dorsaf Ouersighni25-Jan-16 4:54
Dorsaf Ouersighni25-Jan-16 4:54 
bonjour à Tous,
sa fait longtemps que je cherche du code pour imprimer mon DataGridView complet avec visual basic 2010 express et j'ai testé tous les codes qu'ils s'affichent avec des recherches sur google mais en vain.
Mais finalement, j'ai trouver un code c# que j'ai converti en VB qui me convient parfaitement mais le seul problème c qu'il boucle infiniment ( boucle infini au niveau du nombre de pages )
NB: Le code ne génère aucune erreur
Voici mon code :
VB.NET
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

VB.NET
Try
            Dim iHeaderHeight As Double
            'Set the left margin
            Dim iLeftMargin As Integer = e.MarginBounds.Left
            'Set the top margin
            Dim iTopMargin As Integer = e.MarginBounds.Top
            'Whether more pages have to print or not
            Dim bMorePagesToPrint As Boolean = False
            Dim iTmpWidth As Integer = 0
            'For the first page to print set the cell width and header height
            If bFirstPage Then
                For Each GridCol As DataGridViewColumn In DataGridView_impot.Columns
                    iTmpWidth = CType(Math.Floor(CType((CType(GridCol.Width, Double) / (CType(iTotalWidth, Double) * (CType(iTotalWidth, Double) * (CType(e.MarginBounds.Width, Double) / CType(iTotalWidth, Double))))), Double)), Integer)
                    iHeaderHeight = (CType(e.Graphics.MeasureString(GridCol.HeaderText, GridCol.InheritedStyle.Font, iTmpWidth).Height, Integer) + 11)
                    ' Save width and height of headers
                    arrColumnLefts.Add(iLeftMargin)
                    arrColumnWidths.Add(iTmpWidth)
                    iLeftMargin = (iLeftMargin + iTmpWidth)
                Next
            End If

            'Loop till all the grid rows not get printed
            Dim iRow As Double
            While (iRow <= (DataGridView_impot.Rows.Count - 1))
                Dim GridRow As DataGridViewRow = DataGridView_impot.Rows(iRow)
                'Set the cell height
                iCellHeight = (GridRow.Height + 5)
                Dim iCount As Integer = 0
                'Check whether the current page settings allows more rows to print
                If (iTopMargin + (iCellHeight >= (e.MarginBounds.Height + e.MarginBounds.Top))) Then
                    bNewPage = True
                    bFirstPage = False
                    bMorePagesToPrint = True
                    Exit While
                Else
                    If bNewPage Then
                        'Draw Header => raison sociale
                        e.Graphics.DrawString(Me.lbl_rs.Text, New Font(DataGridView_impot.Font, FontStyle.Bold), Brushes.Black, e.MarginBounds.Left, (e.MarginBounds.Top - (e.Graphics.MeasureString(Me.lbl_rs.Text, New Font(DataGridView_impot.Font, FontStyle.Bold), e.MarginBounds.Width).Height - 13)))
                        'Draw Date => date system
                        e.Graphics.DrawString(Me.lbl_date_now.Text, New Font(DataGridView_impot.Font, FontStyle.Bold), Brushes.Black, (e.MarginBounds.Left + (e.MarginBounds.Width - e.Graphics.MeasureString(Me.lbl_date_now.Text, New Font(DataGridView_impot.Font, FontStyle.Bold), e.MarginBounds.Width).Width)), (e.MarginBounds.Top - (e.Graphics.MeasureString(Me.lbl_rs.Text, New Font(New Font(DataGridView_impot.Font, FontStyle.Bold), FontStyle.Bold), e.MarginBounds.Width).Height - 13)))
                        'Draw Columns                 
                        iTopMargin = e.MarginBounds.Top
                        For Each GridCol As DataGridViewColumn In DataGridView_impot.Columns
                            e.Graphics.FillRectangle(New SolidBrush(Color.LightGray), New Rectangle(CType(arrColumnLefts(iCount), Integer), iTopMargin, CType(arrColumnWidths(iCount), Integer), iHeaderHeight))
                            e.Graphics.DrawRectangle(Pens.Black, New Rectangle(CType(arrColumnLefts(iCount), Integer), iTopMargin, CType(arrColumnWidths(iCount), Integer), iHeaderHeight))
                            e.Graphics.DrawString(GridCol.HeaderText, GridCol.InheritedStyle.Font, New SolidBrush(GridCol.InheritedStyle.ForeColor), New RectangleF(CType(arrColumnLefts(iCount), Integer), iTopMargin, CType(arrColumnWidths(iCount), Integer), iHeaderHeight), strFormat)
                            iCount = (iCount + 1)
                        Next
                        bNewPage = False
                        iTopMargin = (iTopMargin + iHeaderHeight)
                    End If

                    iCount = 0
                    'Draw Columns Contents
                    For Each Cel As DataGridViewCell In GridRow.Cells
                        If (Not (Cel.Value) Is Nothing) Then
                            e.Graphics.DrawString(Cel.Value.ToString, Cel.InheritedStyle.Font, New SolidBrush(Cel.InheritedStyle.ForeColor), New RectangleF(CType(arrColumnLefts(iCount), Integer), CType(iTopMargin, Single), CType(arrColumnWidths(iCount), Integer), CType(iCellHeight, Single)), strFormat)
                        End If

                        'Drawing Cells Borders 
                        e.Graphics.DrawRectangle(Pens.Black, New Rectangle(CType(arrColumnLefts(iCount), Integer), iTopMargin, CType(arrColumnWidths(iCount), Integer), iCellHeight))
                        iCount = (iCount + 1)
                    Next
                End If

                iRow = (iRow + 1)
                iTopMargin = (iTopMargin + iCellHeight)

            End While

            'If more lines exist, print another page.
            If bMorePagesToPrint Then
                e.HasMorePages = True
            Else
                e.HasMorePages = False
            End If

        Catch exc As Exception
            MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try


    End Sub

SuggestionRe: bouton imprimer DGV complet Pin
Richard Deeming25-Jan-16 5:15
mveRichard Deeming25-Jan-16 5:15 
GeneralRe: bouton imprimer DGV complet Pin
Dorsaf Ouersighni25-Jan-16 20:45
Dorsaf Ouersighni25-Jan-16 20:45 
QuestionXML Datagridview control & saving changes Pin
Dan Chapin25-Jan-16 3:40
Dan Chapin25-Jan-16 3:40 
QuestionSetting Primary Display Pin
Jayme6518-Jan-16 23:33
Jayme6518-Jan-16 23:33 
AnswerRe: Setting Primary Display Pin
Richard Andrew x6419-Jan-16 4:39
professionalRichard Andrew x6419-Jan-16 4:39 
GeneralRe: Setting Primary Display Pin
Jayme6519-Jan-16 6:46
Jayme6519-Jan-16 6:46 
GeneralRe: Setting Primary Display Pin
Richard Andrew x6419-Jan-16 8:05
professionalRichard Andrew x6419-Jan-16 8:05 
QuestionThread vs Task, seeking advice before I write code, design point of view. Pin
jkirkerx14-Jan-16 7:49
professionaljkirkerx14-Jan-16 7:49 
GeneralRe: Thread vs Task, seeking advice before I write code, design point of view. Pin
Sascha Lefèvre14-Jan-16 8:10
professionalSascha Lefèvre14-Jan-16 8:10 
GeneralRe: Thread vs Task, seeking advice before I write code, design point of view. Pin
jkirkerx14-Jan-16 8:33
professionaljkirkerx14-Jan-16 8:33 
AnswerRe: Thread vs Task, seeking advice before I write code, design point of view. Pin
Sascha Lefèvre14-Jan-16 9:40
professionalSascha Lefèvre14-Jan-16 9:40 
GeneralRe: Thread vs Task, seeking advice before I write code, design point of view. Pin
jkirkerx14-Jan-16 11:06
professionaljkirkerx14-Jan-16 11:06 
AnswerRe: Thread vs Task, seeking advice before I write code, design point of view. Pin
Wombaticus15-Jan-16 0:05
Wombaticus15-Jan-16 0:05 
GeneralRe: Thread vs Task, seeking advice before I write code, design point of view. Pin
jkirkerx15-Jan-16 6:06
professionaljkirkerx15-Jan-16 6:06 
GeneralRe: Thread vs Task, seeking advice before I write code, design point of view. Pin
Wombaticus15-Jan-16 6:19
Wombaticus15-Jan-16 6:19 
GeneralRe: Thread vs Task, seeking advice before I write code, design point of view. Pin
jkirkerx15-Jan-16 7:13
professionaljkirkerx15-Jan-16 7:13 
GeneralRe: Thread vs Task, seeking advice before I write code, design point of view. Pin
Wombaticus15-Jan-16 7:38
Wombaticus15-Jan-16 7:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.