好多VB.NET教程打印部分只教怎样实现Windows“记事本”的打印功能(打印出的文字格式相同),如何才能实现Windows“写字板”的打印功能?(每个文字都可以有它自己的格式)(最好给代码)
此外,如何打印ACCESS2003中的记录(给个提示就可以)
2、为什么在DataGrid中无法显示日期+时间?
数据库为access2003 mdb,表log中有DateTime列(类型为“日期/时间”),用access2003打开可以看到datetime列以“2005-5-19 9:18:07”的格式显示,但用以下代码调用时,DataGrid的DateTime列里只显示“2005-5-19”(DataGrid列宽已足够,可以容纳下日期+时间),如果下面代码不对请给出确代码。
Dim Sel As New OleDbCommand("select datetime,username,operation from log", OleDbConnection1)
OleDbDataAdapter1.SelectCommand = Sel
OleDbConnection1.Open()
OleDbDataAdapter1.Fill(DataSet1, "log")
DataGrid1.DataSource = DataSet1.Tables("log")
先谢过回帖的朋友
8 个解决方案
#1
datagrid1.databind()
#2
不要在VS2003上花时间了,下一个版本DATAGRID改为DATAVIEW了,打印功能也没有增强
#3
自己顶一下,好心人帮看一下啊。
#4
日期和时间的格式调整一下
#5
RichTextbox每个字都可以设置为不同颜色,试试下面的代码:
private void WriteTextToRichTextBox()
{
richTextBox1.Clear();
richTextBox1.SelectionFont = new Font("Arial", 10);
richTextBox1.SelectionColor = Color.Red;
richTextBox1.SelectedText = "A";
richTextBox1.SelectionColor = Color.Blue;
richTextBox1.SelectedText = "p";
richTextBox1.SelectionColor = Color.Green;
richTextBox1.SelectedText = "p";
richTextBox1.SelectionColor = Color.Orange;
richTextBox1.SelectedText = "l";
richTextBox1.SelectionColor = Color.Brown;
richTextBox1.SelectedText = "e";
}
颜色能定义当然字体也能定义了!
private void WriteTextToRichTextBox()
{
richTextBox1.Clear();
richTextBox1.SelectionFont = new Font("Arial", 10);
richTextBox1.SelectionColor = Color.Red;
richTextBox1.SelectedText = "A";
richTextBox1.SelectionColor = Color.Blue;
richTextBox1.SelectedText = "p";
richTextBox1.SelectionColor = Color.Green;
richTextBox1.SelectedText = "p";
richTextBox1.SelectionColor = Color.Orange;
richTextBox1.SelectedText = "l";
richTextBox1.SelectionColor = Color.Brown;
richTextBox1.SelectedText = "e";
}
颜色能定义当然字体也能定义了!
#6
还可以考虑用
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim PrintFont, HeaderFont, PrintFont_A, PrintFont_B, PrintFont_C As Font ’要用到的字体
Dim Height_H, Width_H As Single '每行高度,宽度
’定义字体的格式
PrintFont = New Font("仿宋_GB2312", 11, FontStyle.Regular)
PrintFont_A = New Font("仿宋_GB2312", 11, FontStyle.Bold)
PrintFont_B = New Font("仿宋_GB2312", 13, FontStyle.Regular)
PrintFont_C = New Font("仿宋_GB2312", 11, FontStyle.Regular)
HeaderFont = New Font("仿宋_GB2312", 22, FontStyle.Bold)
'同时表格的颜色也可以改变
e.Graphics.DrawString("日报表", HeaderFont, Brushes.Black, 360, 40, New StringFormat())
e.Graphics.DrawString("单位:", PrintFont_B, Brushes.Black, 15, 40, New StringFormat())
e.Graphics.DrawString("值班:", PrintFont_B, Brushes.Black, 400, 50, New StringFormat())
e.Graphics.DrawString("填表日期:_________", PrintFont_B, Brushes.Black, 805, 50, New StringFormat())
End Sub
至于你是怎么从ACCESS2003中把数据读过来,我想我就不用说了吧!
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim PrintFont, HeaderFont, PrintFont_A, PrintFont_B, PrintFont_C As Font ’要用到的字体
Dim Height_H, Width_H As Single '每行高度,宽度
’定义字体的格式
PrintFont = New Font("仿宋_GB2312", 11, FontStyle.Regular)
PrintFont_A = New Font("仿宋_GB2312", 11, FontStyle.Bold)
PrintFont_B = New Font("仿宋_GB2312", 13, FontStyle.Regular)
PrintFont_C = New Font("仿宋_GB2312", 11, FontStyle.Regular)
HeaderFont = New Font("仿宋_GB2312", 22, FontStyle.Bold)
'同时表格的颜色也可以改变
e.Graphics.DrawString("日报表", HeaderFont, Brushes.Black, 360, 40, New StringFormat())
e.Graphics.DrawString("单位:", PrintFont_B, Brushes.Black, 15, 40, New StringFormat())
e.Graphics.DrawString("值班:", PrintFont_B, Brushes.Black, 400, 50, New StringFormat())
e.Graphics.DrawString("填表日期:_________", PrintFont_B, Brushes.Black, 805, 50, New StringFormat())
End Sub
至于你是怎么从ACCESS2003中把数据读过来,我想我就不用说了吧!
#7
至于DataGrid中显示日期+时间,可以用DataGridTextBoxColumn(1~N)的FORMAT属性进行设置!
如果你的DataGrid的列可以确定,DataGrid1—》属性—》TableStyle—》点...—》GridColumnStyles—》点...—》点“添加”,对它的属性,进行设置!
如果列不确定,那就有点麻烦!
如果你的DataGrid的列可以确定,DataGrid1—》属性—》TableStyle—》点...—》GridColumnStyles—》点...—》点“添加”,对它的属性,进行设置!
如果列不确定,那就有点麻烦!
#8
可能我的意思没有表达明确,我是想将在Richtextbox1中已经由我设定好的带有各种格式的文本打印出来,而不是每个字自己设定一种格式。
#1
datagrid1.databind()
#2
不要在VS2003上花时间了,下一个版本DATAGRID改为DATAVIEW了,打印功能也没有增强
#3
自己顶一下,好心人帮看一下啊。
#4
日期和时间的格式调整一下
#5
RichTextbox每个字都可以设置为不同颜色,试试下面的代码:
private void WriteTextToRichTextBox()
{
richTextBox1.Clear();
richTextBox1.SelectionFont = new Font("Arial", 10);
richTextBox1.SelectionColor = Color.Red;
richTextBox1.SelectedText = "A";
richTextBox1.SelectionColor = Color.Blue;
richTextBox1.SelectedText = "p";
richTextBox1.SelectionColor = Color.Green;
richTextBox1.SelectedText = "p";
richTextBox1.SelectionColor = Color.Orange;
richTextBox1.SelectedText = "l";
richTextBox1.SelectionColor = Color.Brown;
richTextBox1.SelectedText = "e";
}
颜色能定义当然字体也能定义了!
private void WriteTextToRichTextBox()
{
richTextBox1.Clear();
richTextBox1.SelectionFont = new Font("Arial", 10);
richTextBox1.SelectionColor = Color.Red;
richTextBox1.SelectedText = "A";
richTextBox1.SelectionColor = Color.Blue;
richTextBox1.SelectedText = "p";
richTextBox1.SelectionColor = Color.Green;
richTextBox1.SelectedText = "p";
richTextBox1.SelectionColor = Color.Orange;
richTextBox1.SelectedText = "l";
richTextBox1.SelectionColor = Color.Brown;
richTextBox1.SelectedText = "e";
}
颜色能定义当然字体也能定义了!
#6
还可以考虑用
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim PrintFont, HeaderFont, PrintFont_A, PrintFont_B, PrintFont_C As Font ’要用到的字体
Dim Height_H, Width_H As Single '每行高度,宽度
’定义字体的格式
PrintFont = New Font("仿宋_GB2312", 11, FontStyle.Regular)
PrintFont_A = New Font("仿宋_GB2312", 11, FontStyle.Bold)
PrintFont_B = New Font("仿宋_GB2312", 13, FontStyle.Regular)
PrintFont_C = New Font("仿宋_GB2312", 11, FontStyle.Regular)
HeaderFont = New Font("仿宋_GB2312", 22, FontStyle.Bold)
'同时表格的颜色也可以改变
e.Graphics.DrawString("日报表", HeaderFont, Brushes.Black, 360, 40, New StringFormat())
e.Graphics.DrawString("单位:", PrintFont_B, Brushes.Black, 15, 40, New StringFormat())
e.Graphics.DrawString("值班:", PrintFont_B, Brushes.Black, 400, 50, New StringFormat())
e.Graphics.DrawString("填表日期:_________", PrintFont_B, Brushes.Black, 805, 50, New StringFormat())
End Sub
至于你是怎么从ACCESS2003中把数据读过来,我想我就不用说了吧!
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim PrintFont, HeaderFont, PrintFont_A, PrintFont_B, PrintFont_C As Font ’要用到的字体
Dim Height_H, Width_H As Single '每行高度,宽度
’定义字体的格式
PrintFont = New Font("仿宋_GB2312", 11, FontStyle.Regular)
PrintFont_A = New Font("仿宋_GB2312", 11, FontStyle.Bold)
PrintFont_B = New Font("仿宋_GB2312", 13, FontStyle.Regular)
PrintFont_C = New Font("仿宋_GB2312", 11, FontStyle.Regular)
HeaderFont = New Font("仿宋_GB2312", 22, FontStyle.Bold)
'同时表格的颜色也可以改变
e.Graphics.DrawString("日报表", HeaderFont, Brushes.Black, 360, 40, New StringFormat())
e.Graphics.DrawString("单位:", PrintFont_B, Brushes.Black, 15, 40, New StringFormat())
e.Graphics.DrawString("值班:", PrintFont_B, Brushes.Black, 400, 50, New StringFormat())
e.Graphics.DrawString("填表日期:_________", PrintFont_B, Brushes.Black, 805, 50, New StringFormat())
End Sub
至于你是怎么从ACCESS2003中把数据读过来,我想我就不用说了吧!
#7
至于DataGrid中显示日期+时间,可以用DataGridTextBoxColumn(1~N)的FORMAT属性进行设置!
如果你的DataGrid的列可以确定,DataGrid1—》属性—》TableStyle—》点...—》GridColumnStyles—》点...—》点“添加”,对它的属性,进行设置!
如果列不确定,那就有点麻烦!
如果你的DataGrid的列可以确定,DataGrid1—》属性—》TableStyle—》点...—》GridColumnStyles—》点...—》点“添加”,对它的属性,进行设置!
如果列不确定,那就有点麻烦!
#8
可能我的意思没有表达明确,我是想将在Richtextbox1中已经由我设定好的带有各种格式的文本打印出来,而不是每个字自己设定一种格式。