动态用就是动态创建,这个很简单吧,哪儿要用就在哪儿new要打印的话,需要显示出来,把里面的内容复制,输出到打印机
解决方案 »
- Access Join的问题
- crystalreport 自定义打印纸, 只能指定一个型号的打印机能设成通用的吗?
- 股票软件实时数据与曲线的数据源实现方式
- 要是不嫌代码多,就来帮我找找我的问题,我就是个散分的!
- 关于SQL的问题
- 把 WCF 部署到服务器上,连接不上。抛出 CommunicationException 异常。"基础连接已经关闭: 连接被意外关闭"
- 现在一般的windows是不是都装有netframework?
- VS2005 WindowsService安装程序
- 怎样去掉字符串后面的三个字符?急呀!
- C#中MSXML2的responseXml问题,以及Session传递问题
- c#下socket通讯问题!急啊!
- C#修改指定文件夹的文件名
建议去下一个Barcode,这个蛮好用的,我一直用这个.
某些情况下要条码和文字信息一同打印,所以我全放到一个panel上,然后打印出来的
代码如下: public partial class BarCodeSetupBox : Form
{
public BarCodeSetupBox()
{
InitializeComponent();
} private void comType_SelectedIndexChanged(object sender, EventArgs e)
{
barcodeControl2.BarcodeType = GetBarcodeType(comType.Text);
Invalidate();
} BarcodeType GetBarcodeType(string cType)
{
BarcodeType bt = BarcodeType.CODE128A;
switch (cType.ToUpper())
{
case "C2OF5":
bt = BarcodeType.C2OF5;
break;
case "EAN128A":
bt = BarcodeType.EAN128A;
break;
}
return bt;
} private void cheCode39_CheckedChanged(object sender, EventArgs e)
{
barcodeControl2.ShowCode39StartStop = cheCode39.Checked;
Invalidate();
} private void txtData_TextChanged(object sender, EventArgs e)
{
barcodeControl2.Data = txtData.Text;
Invalidate();
} private void txtSubData_TextChanged(object sender, EventArgs e)
{
barcodeControl2.AddOnData = txtSubData.Text;
Invalidate();
} private void comDataShow_SelectedIndexChanged(object sender, EventArgs e)
{
barcodeControl2.TextPosition = GetTextPosition(comDataShow.Text);
Invalidate();
} BarcodeTextPosition GetTextPosition(string str)
{
switch (str)
{
case "顶部":
return BarcodeTextPosition.Above;
case "不显示":
return BarcodeTextPosition.NotShown;
case "底部":
default:
return BarcodeTextPosition.Below;
}
} private void BarCodeSetupBox_Load(object sender, EventArgs e)
{
comType.SelectedIndex = 0;
comDataShow.SelectedIndex = 0;
Invalidate();
} private void vistaButton1_Click(object sender, EventArgs e)
{
CaptureScreen();
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
PrintPreviewDialog cppd = new PrintPreviewDialog();
cppd.Document = pd;
cppd.ShowDialog();
} void pd_PrintPage(object sender, PrintPageEventArgs e)
{
//Graphics g = e.Graphics;
//barcodeControl2.Draw(g, barcodeControl2.ClientRectangle, GraphicsUnit.Inch, 0.01f, 0, null);
//g.Dispose();
e.Graphics.DrawImage(memoryImage, 0, 0); }
[System.Runtime.InteropServices.DllImport("gdi32.dll ")]
public static extern long BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memoryImage;
private void CaptureScreen()
{
//如果你只打印图片大小的话把this.控件名称.CreateGraphics()就行了,下面一样
Graphics mygraphics = this.panel1.CreateGraphics();//创建的是整个panel
Size s = this.panel1.Size;//取panel大小
memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
IntPtr dc1 = mygraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, this.panel1.ClientRectangle.Width, this.panel1.ClientRectangle.Height, dc1, 0, 0, 13369376);
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
} private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
barcodeControl2.StretchText = checkBox1.Checked;
} void txtTitle_TextChanged(object sender, System.EventArgs e)
{
barcodeControl2.CopyRight = txtTitle.Text;
} private void vistaButton3_Click(object sender, EventArgs e)
{
System.IO.Stream myStream;
SaveFileDialog fileDialog = new SaveFileDialog();
fileDialog.Filter = "GIF files (*.gif)|*.gif|PNG files (*.png)|*.png|JPEG files (*.jpg;*.jpeg)|*.jpg;*.jpeg|BMP files (*.bmp;*.dib)|*.bmp;*.dib|TIFF files (*.tif)|*.tif";
fileDialog.FilterIndex = 1;
fileDialog.FileName = DateTime.Now.ToString("yyyyMMddHHmmss");
fileDialog.RestoreDirectory = false;
ImageFormat[] afmt = { ImageFormat.Gif, ImageFormat.Png, ImageFormat.Jpeg, ImageFormat.Bmp, ImageFormat.Tiff }; if (fileDialog.ShowDialog() == DialogResult.OK)
{
if ((myStream = fileDialog.OpenFile()) != null)
{
int barcodeWidth = 1;
int barcodeHeight = 50;
barcodeControl2.MakeImage(afmt[fileDialog.FilterIndex - 1], barcodeWidth, barcodeHeight, true, false, null, myStream);
myStream.Close();
}
}
} private void vistaButton2_Click(object sender, EventArgs e)
{
Application.Exit();
}
}