界面虽然被我弄的很难看,但功能还可以
里边注册表的路径自己设置一下,或者加一个创建注册表的语句,不然会报错
前台:
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="FPSZ.aspx.cs" Inherits="_Default" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <script language="JavaScript" type="text/javascript" src="js/Move.js"></script>
- <script language="JavaScript" type="text/javascript" src="js/preview.js"></script>
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head runat="server">
- <title>无标题页</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <!--startprint-->
- <div>
- <div>
- <table width = "100%">
- <tr>
- <td>
- <table width = "100%">
- <tr>
- <td>
- <asp:Panel ID = "pnlFPSZ" BorderWidth = "1" Width = "100%" runat = "server">
- <table width = "100%">
- <tr>
- <td>
- <table width = "100%">
- <tr>
- <td style="height: 96px">
- <table width = "100%">
- <tr>
- <td>
- <asp:Label ID = "lblTKRQ" Text = "黑色头发:" runat = "server" Font-Underline = "true"></asp:Label>
- </td>
- <td>
- <asp:Label ID = "lblTKRQText" Text = "黑色头发" runat = "server" name="label" BackColor="silver" Style="left: 335px; position: absolute;top: 179px" οnclick="getID('lblTKRQText')" Width="50"></asp:Label>
- <asp:HiddenField ID="lblTKRQText_hdl_Top" runat="server" Value="" />
- <asp:HiddenField ID="lblTKRQText_hdl_Left" runat="server" Value="" />
- </td>
- </tr>
- </table>
- </td>
- <td style="height: 96px">
- <table width = "100%">
- <tr>
- <td>
- <asp:Label ID = "lblMC" Text = "紫色头发" runat = "server" name="label" BackColor="silver" Style="left: 500px; position: absolute;top: 179px" οnclick="getID('lblMC')" Width="50"></asp:Label>
- <asp:HiddenField ID="lblMC_hdl_Top" runat="server" Value="" />
- <asp:HiddenField ID="lblMC_hdl_Left" runat="server" Value="" />
- </td>
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td colspan = "1" style="height: 340px">
- <table width = "100%" border = "3">
- <tr>
- <td style="width: 155px">
- <asp:Label ID = "lblJKDW_XM" Text = "黑色头发紫色头发" runat = "server" Font-Underline = "true"></asp:Label>
- </td>
- <td style="height: 41px">
- <asp:Label ID = "lblJKDW_XMText" Text = "黑紫色头发" runat = "server" name="label" BackColor="silver" Style="left: 450px; position: absolute;top: 272px" οnclick="getID('lblJKDW_XMText')" Width="37"></asp:Label>
- <asp:HiddenField ID="lblJKDW_XMText_hdl_Top" runat="server" Value="" />
- <asp:HiddenField ID="lblJKDW_XMText_hdl_Left" runat="server" Value="" />
- </td>
- <td style="height: 41px">
- <table width = "100%" border = "3">
- <tr>
- <td>
- <asp:Label ID = "lblJKFS" Text = "北京市" runat = "server" Font-Underline = "true"></asp:Label>
- </td>
- <td>
-
-
- <asp:Label ID = "lblJKFSText" Text = "北京市" runat = "server" Font-Underline="True" name="label" BackColor="silver" Style="left: 850px; position: absolute;top: 274px" οnclick="getID('lblJKFSText')" Width="27"></asp:Label>
- <asp:HiddenField ID="lblJKFSText_hdl_Top" runat="server" Value="" />
- <asp:HiddenField ID="lblJKFSText_hdl_Left" runat="server" Value="" />
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </asp:Panel>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </div>
- <br />
- <div>
- <table width = "100%">
- <tr>
- <td style="width: 104px">
- <asp:Label ID = "lblDQDYJ" Text = "当前打印机" runat = "server"></asp:Label></td>
- <td style="width: 175px">
- <asp:DropDownList ID = "ddlDYJ" runat = "server" Width="169px"></asp:DropDownList>
- </td>
- <td>
- <input id="ibnSY" runat="server" type="button" value="上移" οnclick="moveTop()" />
- </td>
- <td>
- <input id="ibnXY" runat="server" type="button" value="下移" οnclick="moveUnder()" />
- </td>
- <td>
- <input id="ibnZY" runat="server" type="button" value="左移" οnclick="moveLeft()" />
- </td>
- <td>
- <input id="ibnYY" runat="server" type="button" value="右移" οnclick="moveRight()" />
- </td>
- </tr>
- <tr>
- <td colspan = "2">
- </td>
- <td>
- <asp:Button ID = "ibnBC" Text = "保存" runat = "server" Visible=true OnClick="ibnBC_Click" />
- </td>
- <td>
- <asp:Button ID = "ibnDY" Text = "普通打印" runat = "server" OnClick="ibnDY_Click" />
- </td>
- <td colspan = "2">
- </td>
- </tr>
- </table>
- </div>
- </div>
- <!--endprint-->
- <input type="button" name="print" value="预览并打印" οnclick="preview()">
- </form>
- </body>
- </html>
后台:
- using System;
- using System.Data;
- using System.Configuration;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Collections;
- public partial class _Default : System.Web.UI.Page
- {
- Helper app_Helper = new Helper();
- ArrayList al_DZ = new ArrayList();
- string str_BL = "";
- Hashtable htbl = new Hashtable();
- Hashtable htbl_Read = new Hashtable();
- QuickTest qt = new QuickTest();
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- GetControls(this);
- string[] print = qt.EnumeratePrintersWin();
- ddlDYJ.Items.Insert(0, "--请选择打印机--"); //这个是设置插入静态的数据
- for (int i = 0; i < print.Length; i++)
- {
- ddlDYJ.Items.Insert(i + 1, print[i]); //这个是设置插入静态的数据
- }
- }
- }
- #region 提取注册表中节点为BS_EMSYJKDSZ下所有值,赋给Label控件样式
- private void GetControls(Control c)
- {
- if (c is Label)
- {
- htbl_Read = app_Helper.get_regist_value("BS_FPSZ");//查找BS_FPSZ节点下的所有值
- foreach (DictionaryEntry die in htbl_Read)
- {
- string writeKey = die.Key.ToString();
- Hashtable writeStr = (Hashtable)die.Value;
- string top_In = "";
- string left_In = "";
- foreach (DictionaryEntry die_In in writeStr)
- {
- string writeKey_In = die_In.Key.ToString();
- string writeStr_In = die_In.Value.ToString();
- if (writeKey_In.Equals("Top"))
- {
- top_In = writeStr_In;
- }
- if (writeKey_In.Equals("Left"))
- {
- left_In = writeStr_In;
- }
- if (!top_In.Equals("") && !left_In.Equals(""))
- {
- if (c.ID.Equals(writeKey))
- {
- ((Label)c).Style["Style"] = "position: absolute;top:" + top_In + ";left:" + left_In + "";
- }
- }
- }
- }
- }
- if (c.HasControls())
- {
- foreach (Control con in c.Controls)
- {
- GetControls(con);
- }
- }
- }
- #endregion 提取注册表中节点为BS_EMSYJKDSZ下所有值,赋给Label控件样式
- #region 打印
- protected void ibnDY_Click(object sender, EventArgs e)
- {
- ibnDY.Attributes.Add("OnClick", "window.print()");
- }
- #endregion 打印
- #region 保存
- protected void ibnBC_Click(object sender, EventArgs e)
- {
- al_DZ.Add("BS_FPSZ");//添加到ArrayList
- string lblTKRQText_Left = "";//保存横坐标
- string lblTKRQText_Top = "";//保存纵坐标
- if (lblTKRQText_hdl_Left.Value.Equals(""))//隐藏控件的值是否为空
- {
- lblTKRQText_Left = lblTKRQText.Style["left"];//把页面的横坐标值赋给变量
- }
- else
- {
- lblTKRQText_Left = lblTKRQText_hdl_Left.Value;//把改变后的横坐标值赋给变量
- }
- if (lblTKRQText_hdl_Top.Value.Equals(""))//隐藏控件的值是否为空
- {
- lblTKRQText_Top = lblTKRQText.Style["top"];//把页面的纵坐标赋值赋给变量
- }
- else
- {
- lblTKRQText_Top = lblTKRQText_hdl_Top.Value;//把改变后的纵坐标赋值赋给变量
- }
- str_BL = "lblTKRQText";//填开日期
- htbl.Add("FontBold", "false");
- htbl.Add("FontName", "宋体");
- htbl.Add("FontSize", "9");
- htbl.Add("Left", lblTKRQText_Left);
- htbl.Add("Top", lblTKRQText_Top);
- app_Helper.registWrite(al_DZ, str_BL, htbl);//把"zldzjc下所有的递增子节点","子节点下的并列所有子节点","指定节点下的所有的键值"添加进注册表里
- //-----------------------------------------------------------------------
- string lblMC_Left = "";//保存横坐标
- string lblMC_Top = "";//保存纵坐标
- if (lblMC_hdl_Left.Value.Equals(""))//隐藏控件的值是否为空
- {
- lblMC_Left = lblMC.Style["left"];//把页面的横坐标值赋给变量
- }
- else
- {
- lblMC_Left = lblMC_hdl_Left.Value;//把改变后的横坐标值赋给变量
- }
- if (lblMC_hdl_Top.Value.Equals(""))//隐藏控件的值是否为空
- {
- lblMC_Top = lblMC.Style["top"];//把页面的纵坐标赋值赋给变量
- }
- else
- {
- lblMC_Top = lblMC_hdl_Top.Value;//把改变后的纵坐标赋值赋给变量
- }
- str_BL = "lblMC";//交警支队
- htbl.Clear();
- htbl.Add("FontBold", "false");
- htbl.Add("FontName", "宋体");
- htbl.Add("FontSize", "9");
- htbl.Add("Left", lblMC_Left);
- htbl.Add("Top", lblMC_Top);
- app_Helper.registWrite(al_DZ, str_BL, htbl);//把"zldzjc下所有的递增子节点","子节点下的并列所有子节点","指定节点下的所有的键值"添加进注册表里
- //-----------------------------------------------------------------------
- string lblJKDW_XMText_Left = "";//保存横坐标
- string lblJKDW_XMText_Top = "";//保存纵坐标
- if (lblJKDW_XMText_hdl_Left.Value.Equals(""))//隐藏控件的值是否为空
- {
- lblJKDW_XMText_Left = lblJKDW_XMText.Style["left"];//把页面的横坐标值赋给变量
- }
- else
- {
- lblJKDW_XMText_Left = lblJKDW_XMText_hdl_Left.Value;//把改变后的横坐标值赋给变量
- }
- if (lblJKDW_XMText_hdl_Top.Value.Equals(""))//隐藏控件的值是否为空
- {
- lblJKDW_XMText_Top = lblJKDW_XMText.Style["top"];//把页面的纵坐标赋值赋给变量
- }
- else
- {
- lblJKDW_XMText_Top = lblJKDW_XMText_hdl_Top.Value;//把改变后的纵坐标赋值赋给变量
- }
- str_BL = "lblJKDW_XMText";//肇事者
- htbl.Clear();
- htbl.Add("FontBold", "false");
- htbl.Add("FontName", "宋体");
- htbl.Add("FontSize", "9");
- htbl.Add("Left", lblJKDW_XMText_Left);
- htbl.Add("Top", lblJKDW_XMText_Top);
- app_Helper.registWrite(al_DZ, str_BL, htbl);//把"zldzjc下所有的递增子节点","子节点下的并列所有子节点","指定节点下的所有的键值"添加进注册表里
- //-----------------------------------------------------------------------
- string lblJKFSText_Left = "";//保存横坐标
- string lblJKFSText_Top = "";//保存纵坐标
- if (lblJKFSText_hdl_Left.Value.Equals(""))//隐藏控件的值是否为空
- {
- lblJKFSText_Left = lblJKFSText.Style["left"];//把页面的横坐标值赋给变量
- }
- else
- {
- lblJKFSText_Left = lblJKFSText_hdl_Left.Value;//把改变后的横坐标值赋给变量
- }
- if (lblJKFSText_hdl_Top.Value.Equals(""))//隐藏控件的值是否为空
- {
- lblJKFSText_Top = lblJKFSText.Style["top"];//把页面的纵坐标赋值赋给变量
- }
- else
- {
- lblJKFSText_Top = lblJKFSText_hdl_Top.Value;//把改变后的纵坐标赋值赋给变量
- }
- str_BL = "lblJKFSText";//现金
- htbl.Clear();
- htbl.Add("FontBold", "false");
- htbl.Add("FontName", "宋体");
- htbl.Add("FontSize", "9");
- htbl.Add("Left", lblJKFSText_Left);
- htbl.Add("Top", lblJKFSText_Top);
- app_Helper.registWrite(al_DZ, str_BL, htbl);//把"zldzjc下所有的递增子节点","子节点下的并列所有子节点","指定节点下的所有的键值"添加进注册表里
- //-----------------------------------------------------------------------
- GetControls(this);//读取注册表里值赋给页面显示
- }
- #endregion 保存
- }
Helper.cs
- using System;
- using System.Data;
- using System.Configuration;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Text.RegularExpressions;
- using System.Collections;
- using System.Web.Configuration;
- using Microsoft.Win32;
- using System.IO;
- using System.Drawing;
- using System.Runtime.InteropServices;
- using System.Drawing.Imaging;
- /// <summary>
- /// Helper 的摘要说明
- /// </summary>
- public class Helper
- {
- public Helper()
- {
- //
- // TODO: 在此处添加构造函数逻辑
- //
- }
- #region 注册表
- /// <summary>
- /// 查找指定文件夹下的所有文件夹内的所有值
- /// </summary>
- /// <param name="readKey"></param>
- /// <returns></returns>
- public Hashtable get_regist_value(string readKey)
- {
- Hashtable registHtbl = new Hashtable();
- RegistryKey hkml = Registry.Users;
- //RegistryKey softwares = hkml.OpenSubKey("S-1-5-21-1220945662-1343024091-1652362547-1017", true);
- //RegistryKey softwaress = softwares.OpenSubKey("Software", true);
- //RegistryKey aimdir = softwaress.OpenSubKey("VB and VBA Program Settings", true);
- RegistryKey aimdir = hkml.OpenSubKey("S-1-5-21-1177238915-527237240-1801674531-1013\\Asp Net Settings", true);
- RegistryKey aimdirs = aimdir.OpenSubKey("zldzjc", true);
- RegistryKey aimdirss = aimdirs.CreateSubKey(readKey);
- if (aimdirss.SubKeyCount != 0)
- {
- foreach (string subKeyName in aimdirss.GetSubKeyNames())
- {
- Hashtable registSubHtbl = new Hashtable();
- RegistryKey aimdirsss = aimdirss.CreateSubKey(subKeyName);
- foreach (string subValueName in aimdirsss.GetValueNames())
- {
- string aaa = aimdirsss.GetValue(subValueName).ToString();
- registSubHtbl.Add(subValueName, aaa);
- }
- registHtbl.Add(subKeyName, registSubHtbl);
- }
- }
- hkml.Close();
- //softwares.Close();
- aimdirs.Close();
- aimdirss.Close();
- return registHtbl;
- }
- /// <summary>
- /// 写入注册表中指定的内容
- /// </summary>
- /// <param name="al_subKey">zldzjc下所有的递增子节点</param>
- /// <param name="al_subKeySub">子节点下的并列所有子节点</param>
- /// <param name="htbl">指定节点下的所有的键值</param>
- public void registWrite(ArrayList al_subKeyed, string al_subKeying, Hashtable htbl)
- {
- RegistryKey hkml = Registry.CurrentUser;
- //RegistryKey softwares = hkml.CreateSubKey("S-1-5-21-1220945662-1343024091-1652362547-1003");
- //RegistryKey software = hkml.OpenSubKey("SOFTWARE");
- //RegistryKey aimdir = software.OpenSubKey("Asp Net Settings");
- RegistryKey aimdir = hkml.OpenSubKey("S-1-5-21-1177238915-527237240-1801674531-1013\\Asp Net Settings", true);
- RegistryKey aimdirs = aimdir.OpenSubKey("zldzjc", true);
- for (int i = 0; i < al_subKeyed.Count; i++)
- aimdirs = aimdirs.CreateSubKey(al_subKeyed[i].ToString());
- RegistryKey open = aimdirs.CreateSubKey(al_subKeying);
- foreach (DictionaryEntry die in htbl)
- {
- string writeKey = die.Key.ToString();
- string writeStr = die.Value.ToString();
- open.SetValue(writeKey, writeStr);
- }
- hkml.Close();
- //softwares.Close();
- //software.Close();
- aimdir.Close();
- aimdirs.Close();
- }
- #endregion 注册表
- }
QuickTest.cs
- using System;
- using System.Data;
- using System.Configuration;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Collections;
- using System.Runtime.InteropServices;
- using System.Diagnostics;
- using System.Drawing.Printing;
- /// <summary>
- /// QuickTest 的摘要说明
- /// </summary>
- public class QuickTest
- {
- [DllImport("winspool.drv", CharSet = CharSet.Auto)]
- static extern bool EnumPrinters(int flags, string name, int level, IntPtr pPrinterEnum,
- int cbBuf, out int pcbNeeded, out int pcReturned);
- private const int PRINTER_ENUM_NETWORK = 0x00000040;
- private const int PRINTER_ENUM_LOCAL = 0x00000002;
- private const int PRINTER_ENUM_REMOTE = 0x00000010;
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
- struct PRINTER_INFO_1
- {
- int flags;
- [MarshalAs(UnmanagedType.LPTStr)]
- public string pDescription;
- [MarshalAs(UnmanagedType.LPTStr)]
- public string pName;
- [MarshalAs(UnmanagedType.LPTStr)]
- public string pComment;
- }
- public string[] EnumeratePrintersWin()
- {
- string[] print_All = null;
- bool Success;
- int cbRequired;
- int nEntries;
- IntPtr outb = IntPtr.Zero;
- Success = EnumPrinters(PRINTER_ENUM_NETWORK | PRINTER_ENUM_LOCAL | PRINTER_ENUM_REMOTE, null, 1, outb, 0, out cbRequired, out nEntries);
- outb = Marshal.AllocHGlobal(cbRequired);
- Success = EnumPrinters(PRINTER_ENUM_NETWORK | PRINTER_ENUM_LOCAL | PRINTER_ENUM_REMOTE, null, 1, outb, cbRequired, out cbRequired, out nEntries);
- PRINTER_INFO_1[] portsArray = new PRINTER_INFO_1[cbRequired];
- IntPtr current = outb;
- try
- {
- if (nEntries != 0)
- {
- print_All = new string[nEntries];
- }
- else
- {
- print_All = new string[1];
- print_All[0] = "null";
- return print_All;
- }
- for (int i = 0; i < nEntries; i++)
- {
- portsArray[i] = (PRINTER_INFO_1)Marshal.PtrToStructure(current,
- typeof(PRINTER_INFO_1));
- current = (IntPtr)((int)current + Marshal.SizeOf(typeof(PRINTER_INFO_1)));
- //Console.WriteLine(i + ": \n" + portsArray[i].pName + "\n" + portsArray[i].pDescription + "\n" + portsArray[i].pComment + "\n");
- print_All[i] = i + ": \n" + portsArray[i].pName + "\n" + portsArray[i].pDescription + "\n" + portsArray[i].pComment + "\n";
- }
- }
- catch (Exception exp)
- {
- Console.WriteLine(exp.StackTrace);
- }
- Marshal.FreeHGlobal(outb);
- return print_All;
- }
- public QuickTest()
- {
- }
- public static void Main()
- {
- QuickTest qt = new QuickTest();
- qt.EnumeratePrintersWin();
- Console.ReadLine();
- }
- }
js/Move.js
- // JScript 文件
- var labelID = "";
- var hdlID = "";
- function moveTop()
- {
- var a=document.getElementById(labelID).style.top;
- var Top=a.substring(0,a.indexOf("px"));
- document.getElementById(labelID).style.top= parseInt(Top)-10;// 向上
- document.getElementById(labelID+"_hdl_Top").value=document.getElementById(labelID).style.top;
- }
- function moveUnder()
- {
- var aa=document.getElementById(labelID).style.top;
- var Topp=aa.substring(0,aa.indexOf("px"));
- document.getElementById(labelID).style.top= parseInt(Topp)+10;// 向下
- document.getElementById(labelID+"_hdl_Top").value=document.getElementById(labelID).style.top;
- }
- function moveLeft()
- {
- var b=document.getElementById(labelID).style.left;
- var Left=b.substring(0,b.indexOf("px"));
- document.getElementById(labelID).style.left= parseInt(Left)-10;// 向左
- document.getElementById(labelID+"_hdl_Left").value=document.getElementById(labelID).style.left;
- }
- function moveRight()
- {
- var bb=document.getElementById(labelID).style.left;
- var Leftt=bb.substring(0,bb.indexOf("px"));
- document.getElementById(labelID).style.left= parseInt(Leftt)+10;// 向右边
- document.getElementById(labelID+"_hdl_Left").value=document.getElementById(labelID).style.left;
- }
- function getID(labelIDCS)
- {
- //labelID = "ctl00_ContentPlaceHolder1_"+labelIDCS;
- labelID = labelIDCS;
- var arrAll=document.all;
- for(i=0;i <arrAll.length;i++)
- {
- if(arrAll[i].name == 'label')
- {
- document.getElementById(arrAll[i].id).style.color = "black";
- }
- }
- document.getElementById(labelID).style.color = "red";
- }
- function font_Update()
- {
- var arrAll=document.all;
- for(i=0;i <arrAll.length;i++)
- {
- if(arrAll[i].name == 'label')
- {
- document.getElementById(arrAll[i].id).style.fontFamily="Times New Roman";
- }
- }
- }
js/preview.js
-
- // JScript 文件
- <!--
- function preview()
- {
- bdhtml=window.document.body.innerHTML;
- sprnstr="<!--startprint-->";
- eprnstr="<!--endprint-->";
- prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
- alert("prnhtml:"+prnhtml);
- prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
- window.document.body.innerHTML=prnhtml;
- window.print();
- }
- -->