-
C# 打印XPS文档 XPS文件打印
C# 打印选择的XPS文档,打印XPS文件,相关代码如下:
private void button1_Click(object sender, RoutedEventArgs e)
{//打印选择的XPS文档
var MyDlg = new Microsoft.Win32.OpenFileDialog();
MyDlg.InitialDirectory = System.IO.Directory.GetCurrentDirectory();
MyDlg.Filter = "XPS文件(*.xps)|*.xps|所有文件(*.*)|*.*";
if (MyDlg.ShowDialog() == true)
{
string MyFileName = MyDlg.FileName;
var pDialog = new PrintDialog();
pDialog.PageRangeSelection = PageRangeSelection.AllPages;
pDialog.UserPageRangeEnabled = true;
if (pDialog.ShowDialog() == true)
{
var MyDocument = new System.Windows.Xps.Packaging.XpsDocument(MyFileName, System.IO.FileAccess.ReadWrite);
FixedDocumentSequence MyFixedDocumentSequence = MyDocument.GetFixedDocumentSequence();
pDialog.PrintDocument(MyFixedDocumentSequence.DocumentPaginator, "我的XPS打印文档");
}
}
}
- 2022-03-23 09:37:24下载
- 积分:1
-
C# 保存对数据库记录的插入、删除及修改操作结果
C# 保存对数据库记录的插入、删除及修改操作结果,设置控件数据源,对操作的结果以MessageBox.Show在消息框中显示提示信息,执行过程中验证Shippers数据表、验证Phone字段、验证CompanyName字段
- 2022-04-08 04:57:49下载
- 积分:1
-
C# 从RichTextBox 控件中提取文本内容
C# 从RichTextBox 控件中提取文本内容,并设置RichTextBox 控件中的字体大小-附完整源代码,
private void button1_Click(object sender, RoutedEventArgs e)
{//从RichTextBox 控件中提取文本内容
TextRange MyText = new TextRange(this.richTextBox1.Document.ContentStart, this.richTextBox1.Document.ContentEnd);
MessageBox.Show(MyText.Text, "RichTextBox控件中的文本内容",MessageBoxButton.OK);
}
private void button2_Click(object sender, RoutedEventArgs e)
{//设置RichTextBox 控件中的字体大小
TextRange MyText = new TextRange(this.richTextBox1.Document.ContentStart, this.richTextBox1.Document.ContentEnd);
MyText.ApplyPropertyValue(TextElement.FontSizeProperty, 36.00);
MyText.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
- 2022-09-21 17:55:02下载
- 积分:1
-
C# 修复Access数据库的一个范例程序
C# 修复Access数据库的一个范例程序,不过不知道到底能不能修复吧,这个修复过程的编写,可参考以下代码:
//声明临时数据库的名称
string temp = DateTime.Now.Year.ToString();
temp += DateTime.Now.Month.ToString();
temp += DateTime.Now.Day.ToString();
temp += DateTime.Now.Hour.ToString();
temp += DateTime.Now.Minute.ToString();
temp += DateTime.Now.Second.ToString() + ".bak";
temp = strPathMdb.Substring(0, strPathMdb.LastIndexOf("") + 1) + temp;
//定义临时数据库的连接字符串
string temp2 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + temp;
//定义目标数据库的连接字符串
string strPathMdb2 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strPathMdb;
JRO.JetEngineClass jt = new JRO.JetEngineClass();//创建一个JetEngineClass对象
//使用JetEngineClass对象的CompactDatabase方法压缩修复数据库
jt.CompactDatabase(strPathMdb2, temp2);
File.Copy(temp, strPathMdb, true);//拷贝临时数据库到目标数据库(覆盖)
File.Delete(temp);//删除临时数据库
MessageBox.Show("修复完成");
这个程序中使用了三个类库:Interop.ADODB.dll、Interop.ADOX.dll、Interop.JRO.dll。
- 2022-01-26 03:31:51下载
- 积分:1
-
c# 关闭窗口前确认 弹出提示
与大家分享一个C#窗口编程小技巧,在用户关闭窗口前,弹出确认对话框,可有效防止用户误操作,误关闭窗口。本源码中是完整的实例下载 ,有基础的可参考以下的代码,快速实现本功能:
C#弹出关闭窗口的确认对话框,核心代码如下:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult dr = MessageBox.Show("是否关闭窗体", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dr == DialogResult.Yes) //使用if语句判断是否单击“是”按钮
{
e.Cancel = false;//如果单击“是”按钮则关闭窗体
}
else//否则
{
e.Cancel = true;//不执行操作
}
}
当用户单击窗口右上角关闭按钮时,激活函数中的命令,弹出确认框。
- 2022-01-25 15:52:19下载
- 积分:1
-
Visual C# 交叉表查询
这是一个Visual C# 交动态交叉表查询示例程序,动态交叉表(SQLServer 2005)查询例子源码:
private void Frm_Main_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(//创建数据库连接对象
@"Server=WIN-GI7E47AND9RLS;database=db_TomeTwo;Uid=sa;Pwd=");
SqlDataAdapter dap = new SqlDataAdapter(//创建数据适配器对象
"select * from tb_VenditionInfo", con);
DataSet ds = new DataSet();//创建数据集
dap.Fill(ds, "table");//填充数据集
dgv_Message.DataSource =//设置数据源
ds.Tables[0].DefaultView;
}
private void btn_Select_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(//创建数据库连接对象
@"Server=WIN-GI7E47AND9RLS;database=db_TomeTwo;Uid=sa;Pwd=");
SqlDataAdapter dap = new SqlDataAdapter("Corss", con);//创建数据适配器
dap.SelectCommand.CommandType =//设置命令为存储过程
CommandType.StoredProcedure;
DataSet ds = new DataSet();//创建数据集
dap.Fill(ds, "table");//填充数据集
dgv_Message.DataSource =//设置数据源
ds.Tables[0].D
- 2022-12-26 00:25:03下载
- 积分:1
-
C# 启动外部计算器计算数据
C# 启动外部计算器计算数据,private void button1_Click(object sender, EventArgs e)
{//启动计算器计算数据(从当前程序向其他程序发送键击数据)
ProcessStartInfo MyStartInfo = new ProcessStartInfo();
MyStartInfo.FileName = "Calc.exe";
Process MyProcess = new Process();
MyProcess.StartInfo = MyStartInfo;
MyProcess.Start();
System.Threading.Thread.Sleep(100);
IntPtr MyHandle = FindWindow("SciCalc", "计算器");
if (MyHandle == IntPtr.Zero)
{
MessageBox.Show("计算器程序没有运行","信息提示",MessageBoxButtons.OK);
return;
}
SetForegroundWindow(MyHandle);
SendKeys.SendWait("88");
SendKeys.SendWait("*");
SendKeys.SendWait("8");
SendKeys.SendWait("=");
}
- 2023-04-17 08:10:03下载
- 积分:1
-
C# 获取组合查询中两个结果集的交集
Visual C# 获取组合查询中两个结果集的交集,获取学生表和成绩表中学生信息的交集。
- 2022-03-21 14:37:37下载
- 积分:1
-
C# ShowDialogPBar 弹出模式窗口显示进度条
C# 弹出模式窗口显示进度条,本源码以复制文件显示进度条的功能来演示弹出式窗口的创建和设置方法,为了演示方便,代码中还定义了复制文件的函数、返回上一级目录的函数,在弹出窗口的定义和进度条的生成方面,代码比较多,且注释也很丰富,相信会对C#学习者对了解进度条和弹出窗口的用法有一定帮助。
- 2022-06-18 20:09:58下载
- 积分:1
-
C# LoadAsync()异步加载并播放声音的例子
C# 异步加载并播放声音文件的实例,异步加载主要是使用了LoadAsync(),使用IsLoadCompleted判断是否加载完成,加载完成则使用SoundPlayer()播放wav文件。在这个过程中,可能会有异常,因此这里添加了异常处理模块,当然了这是每个C#程序几乎都不可缺少的部分了,详情请下载本源码。
异步加载有很多好处,可节省系统资源,使软件执行速度更快,C#编程者,建议学习这项技巧哦。
- 2023-02-10 15:50:03下载
- 积分:1