how to interpret c ++ code on vb.net?

  • Thread starter Thread starter Royer12
  • Start date Start date
R

Royer12

Guest
hello I have doubts in the interpretation of a code where I have created a class with the name GridPrintHelper, and this fulfills the function of printing a DataGridView.

namespace PrintGridDemo
{
public class GridPrintHelper //name of file GridPrintHelper
{
PrintDocument printDoc = new PrintDocument();
PrintDialog printDlg;
DataGridView dgPrint;
public void PrintDataGridView(DataGridView dg)
{
printDlg = new PrintDialog();
printDlg.Document= printDoc;

printDoc.BeginPrint +=printDoc_BeginPrint;
printDoc.PrintPage +=printDoc_PrintPage;

if(printDlg.ShowDialog() != DialogResult.OK)
{
printDoc.BeginPrint -=printDoc_BeginPrint;
printDoc.PrintPage -=printDoc_PrintPage;
return;
}
dgPrint = dg;
printDoc.DefaultPageSettings.Landscape = false;
printDoc.Print();
}
private void printDoc_PrintPage(object sender, PrintPageEventArgs e)
{
//throw new NotImplementedException();
int leftMargin = e.MarginBounds.Left;
int topMargin = e.MarginBounds.Top + 2;

//print header
int printLeftPosition = leftMargin + 5;
int headerHeight = (int)e.Graphics.MeasureString(dgPrint.Columns[0].HeaderText,
dgPrint.Columns[0].InheritedStyle.Font)-Height+11;

foreach(DataGridViewColumn column in dgPrint.Columns)
{
e.Graphics.DrawString(column.headerText,column.InheritedStyle.Font,
new SolidBrush(column.InheritedStyle.ForeColor),
new Rectangle(printLeftPosition,topMargin,column.Width,headerHeight));

printLeftPosition += column.Width + 2;
}
e.HasMorePages =false;
}
int totalWidth;
private void printDoc_BeginPrint(object sender, PrintPageEventArgs e)
{
//throw new NotImplementedException();
totalWidth = dgPrint.Columns.ofType<DataGridViewColumn>().Sum(c => c.Width);
}
}


So far I have managed to interpret this: VB.NET code

Imports System.Drawing.Printing
Public Class GridPrintHelper
Dim printDoc As PrintDocument = New PrintDocument()
Dim printDlg As PrintDialog
Dim dgPrint As DataGridView
'=================================
Public Sub PrintDataGridView(ByVal dg As DataGridView)
printDlg = New PrintDialog()
printDlg.Document = printDoc
'printDoc.BeginPrint += printDoc_BeginPrint() error 1
'printDoc.PrintPage += printDoc_PrintPage() error 2
'00000000000000
If (printDlg.ShowDialog() <> DialogResult.OK) Then
'printDoc.BeginPrint -= printDoc_BeginPrint() error 1
'printDoc.PrintPage -= printDoc_PrintPage() error 2
End If
End Sub
End Class


I can not create the private sub

Private Sub printDoc_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)

End Sub

Private Sub printDoc_BeginPrint(ByVal sender As Object, ByVal e As PrintPageEventArgs)

End Sub


Parameter sender not specified

Continue reading...
 
Back
Top