Saturday, 1 August 2015
Monday, 6 July 2015
Remove duplicate strings from a string or int array in C#
string[] spdfIn =
{ "abc", "xyz","abc", "def", "ghi", "asdf", "ghi","xd", "abc" };
spdfIn = spdfIn.Distinct().ToArray();
int[] int1={1,2,3,4,4,5,1};
int1=int1
.Distinct().ToArray();
Friday, 24 April 2015
Panel printing
private void btnPrint_Click(object sender, EventArgs e)
{
System.Drawing.Printing.PrintDocument doc = new PrintDocument();
doc.PrintPage += this.Doc_PrintPage1;
PrintDialog dlgSettings = new PrintDialog();
dlgSettings.Document = doc;
//if (dlgSettings.ShowDialog() == DialogResult.OK) // hide this line default Printer is select
{
doc.Print();
}
}
private void Doc_PrintPage1(object sender, PrintPageEventArgs e)
{
float x = e.MarginBounds.Left;
float y = e.MarginBounds.Top;
Bitmap bmp = new Bitmap(this.pnlPrint.Width, this.pnlPrint.Height);
this.pnlPrint.DrawToBitmap(bmp, new Rectangle(0, 0, this.pnlPrint.Width, this.pnlPrint.Height));
e.Graphics.DrawImage((Image)bmp, 0, 0);
}
{
System.Drawing.Printing.PrintDocument doc = new PrintDocument();
doc.PrintPage += this.Doc_PrintPage1;
PrintDialog dlgSettings = new PrintDialog();
dlgSettings.Document = doc;
//if (dlgSettings.ShowDialog() == DialogResult.OK) // hide this line default Printer is select
{
doc.Print();
}
}
private void Doc_PrintPage1(object sender, PrintPageEventArgs e)
{
float x = e.MarginBounds.Left;
float y = e.MarginBounds.Top;
Bitmap bmp = new Bitmap(this.pnlPrint.Width, this.pnlPrint.Height);
this.pnlPrint.DrawToBitmap(bmp, new Rectangle(0, 0, this.pnlPrint.Width, this.pnlPrint.Height));
e.Graphics.DrawImage((Image)bmp, 0, 0);
}
Tuesday, 24 March 2015
Get Default Printer paper size and Printing Text
public void getPapersize() //Get Default Printer paper size
{
using (System.Drawing.Printing.PrintDocument PD = new System.Drawing.Printing.PrintDocument())
{
foreach (System.Drawing.Printing.PaperSize P in PD.PrinterSettings.PaperSizes)
{
Console.Write(P.PaperName + " ");
double W = P.Width / 100.0;
double H = P.Height / 100.0;
double[] M = { 1, 72, 200 };
for (int I = 0; I <= 2; I++)
{
MessageBox.Show((W * M[I]).ToString() + " " + (H * M[I]).ToString() + " ");
}
}
}
}
------------------------------
public void Print(string s)
{
System.Drawing.Printing.PrintDocument PD = new System.Drawing.Printing.PrintDocument();
PD.PrintController = new System.Drawing.Printing.StandardPrintController();
PD.PrintPage += delegate(object sender1, System.Drawing.Printing.PrintPageEventArgs e1)
{
e1.Graphics.DrawString(s, new Font("Times New Roman", 12), new SolidBrush(Color.Black), new RectangleF(0, 0, PD.DefaultPageSettings.PrintableArea.Width, PD.DefaultPageSettings.PrintableArea.Height));
};
try
{
PD.Print();
}
catch (Exception ex)
{
throw new Exception("Exception Occured While Printing", ex);
}
}
{
using (System.Drawing.Printing.PrintDocument PD = new System.Drawing.Printing.PrintDocument())
{
foreach (System.Drawing.Printing.PaperSize P in PD.PrinterSettings.PaperSizes)
{
Console.Write(P.PaperName + " ");
double W = P.Width / 100.0;
double H = P.Height / 100.0;
double[] M = { 1, 72, 200 };
for (int I = 0; I <= 2; I++)
{
MessageBox.Show((W * M[I]).ToString() + " " + (H * M[I]).ToString() + " ");
}
}
}
}
------------------------------
public void Print(string s)
{
System.Drawing.Printing.PrintDocument PD = new System.Drawing.Printing.PrintDocument();
PD.PrintController = new System.Drawing.Printing.StandardPrintController();
PD.PrintPage += delegate(object sender1, System.Drawing.Printing.PrintPageEventArgs e1)
{
e1.Graphics.DrawString(s, new Font("Times New Roman", 12), new SolidBrush(Color.Black), new RectangleF(0, 0, PD.DefaultPageSettings.PrintableArea.Width, PD.DefaultPageSettings.PrintableArea.Height));
};
try
{
PD.Print();
}
catch (Exception ex)
{
throw new Exception("Exception Occured While Printing", ex);
}
}
Subscribe to:
Posts (Atom)