Danh mục

Đồ hoạ, đa phương tiện ( Mutilmedia) và In ấn Đồ họa phần cuối

Số trang: 10      Loại file: pdf      Dung lượng: 166.81 KB      Lượt xem: 5      Lượt tải: 0    
10.10.2023

Phí tải xuống: 1,000 VND Tải xuống file đầy đủ (10 trang) 0
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

(Bỏ qua phần mã designer.) private void PrintQueueTest_Load(object sender, System.EventArgs e) { cmdRefresh_Click(null, null); } private void cmdRefresh_Click(object sender, System.EventArgs e)
Nội dung trích xuất từ tài liệu:
Đồ hoạ, đa phương tiện ( Mutilmedia) và In ấn Đồ họa phần cuốiusing System;using System.Windows.Forms;using System.Management;using System.Collections;public class PrintQueueTest : System.Windows.Forms.Form { private System.Windows.Forms.ListBox lstJobs; private System.Windows.Forms.Button cmdRefresh; private System.Windows.Forms.TextBox txtJobInfo; private System.Windows.Forms.Button cmdPause; private System.Windows.Forms.Button cmdResume; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; // (Bỏ qua phần mã designer.) private void PrintQueueTest_Load(object sender, System.EventArgs e) { cmdRefresh_Click(null, null); } private void cmdRefresh_Click(object sender, System.EventArgs e) { // Chọn tất cả các tác vụ in đang chờ. string query = SELECT * FROM Win32_PrintJob; ManagementObjectSearcher jobQuery = new ManagementObjectSearcher(query); ManagementObjectCollection jobs = jobQuery.Get(); // Thêm các tác vụ trong hàng đợi vào ListBox. lstJobs.Items.Clear(); txtJobInfo.Text = ; foreach (ManagementObject job in jobs) { lstJobs.Items.Add(job[JobID]); } } // Phương thức này thực hiện truy vấn WMI và trả về // tác vụ WMI cho item hiện đang được chọn trong ListBox.private ManagementObject GetSelectedJob() { try { // Chọn tác vụ in phù hợp. string query = SELECT * FROM Win32_PrintJob + WHERE JobID= + lstJobs.Text + ; ManagementObjectSearcher jobQuery = new ManagementObjectSearcher(query); ManagementObjectCollection jobs = jobQuery.Get(); IEnumerator enumerator = jobs.GetEnumerator(); enumerator.MoveNext(); return (ManagementObject)enumerator.Current; }catch (InvalidOperationException){ // Thuộc tính Current của enumerator không hợp lệ return null; }}private void lstJobs_SelectedIndexChanged(object sender, System.EventArgs e) { ManagementObject job = GetSelectedJob(); if (job == null) { txtJobInfo.Text = ; return; } // Hiển thị thông tin về tác vụ. string jobInfo = Document: + job[Document].ToString(); jobInfo += Environment.NewLine; jobInfo += DriverName: + job[DriverName].ToString(); jobInfo += Environment.NewLine; jobInfo += Status: + job[Status].ToString(); jobInfo += Environment.NewLine; jobInfo += Owner: + job[Owner].ToString(); jobInfo += Environment.NewLine; jobInfo += PagesPrinted: + job[PagesPrinted].ToString(); jobInfo += Environment.NewLine; jobInfo += TotalPages: + job[TotalPages].ToString(); if (job[JobStatus] != null) { txtJobInfo.Text += Environment.NewLine; txtJobInfo.Text += JobStatus: + job[JobStatus].ToString(); } if (job[StartTime] != null) { jobInfo += Environment.NewLine; jobInfo += StartTime: + job[StartTime].ToString(); } txtJobInfo.Text = jobInfo;}private void cmdPause_Click(object sender, System.EventArgs e) { if (lstJobs.SelectedIndex == -1) return; ManagementObject job = GetSelectedJob(); if (job == null) return; // Tạm dừng tác vụ. int returnValue = Int32.Parse( job.InvokeMethod(Pause, null).ToString()); // Hiển thị thông tin về giá trị trả về. if (returnValue == 0) { MessageBox.Show(Successfully paused job.); }else { MessageBox.Show( Unrecognized return value when pausing job.); }} private void cmdResume_Click(object sender, System.EventArgs e) { if (lstJobs.SelectedIndex == -1) return; ManagementObject job = GetSelectedJob(); if (job == null) return; if ((Int32.Parse(job[StatusMask].ToString()) & 1) == 1) { // Phục hồi tác vụ. int returnValue = Int32.Parse( job.InvokeMethod(Resume, null).ToString()); // Hiển thị thông tin về giá trị trả về. if (returnValue == 0) { MessageBox.Show(Successfully resumed job.); }else if (returnValue == 5) { MessageBox.Show(Access denied.); }else { MessageBox.Show( Unrecognized return value when resuming job.); } } }} The image part with relationship ID rId5 was not found in the file. Hình 8.14 Lấy thông tin từ hàng đợi inNhớ rằng các quyền Windows có thể ngăn bạn tạm dừng hoặc gỡ bỏ một tác vụ in do mộtngười dùng khác tạo ra. Thực ra, các quyền này còn có thể ngăn bạn lấy thông tin trạngthái và có thể gây ra ngoại lệ. Các phương thức WMI khác mà bạn có thể sử dụng trong một kịch bản in bao gồm AddPrinterConnection, SetDefaultPrinter, CancelAllJobs, và PrintTestPage, tất cả đều làm việc với lớp Win32_Printer. Để có thêm thông t ...

Tài liệu được xem nhiều: