zoukankan      html  css  js  c++  java
  • c# asp.net 鼠标改变控件坐标位置,更改控件坐标,注册表保存读取,打印,查找局域网内打印机等等收集

    界面虽然被我弄的很难看,但功能还可以 

    里边注册表的路径自己设置一下,或者加一个创建注册表的语句,不然会报错 

    前台: 

    Html代码  收藏代码
    1. <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="FPSZ.aspx.cs" Inherits="_Default" %>  
    2.   
    3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    4.   
    5. <script language="JavaScript" type="text/javascript" src="js/Move.js"></script>  
    6.   
    7. <script language="JavaScript" type="text/javascript" src="js/preview.js"></script>  
    8.   
    9. <html xmlns="http://www.w3.org/1999/xhtml" >  
    10. <head runat="server">  
    11.     <title>无标题页</title>  
    12. </head>  
    13. <body>  
    14.     <form id="form1" runat="server">  
    15.       
    16.       
    17.       
    18.   
    19. <!--startprint-->  
    20.   
    21. <div>  
    22.   <div>  
    23.     <table width = "100%">  
    24.       <tr>  
    25.         <td>  
    26.         <table width = "100%">  
    27.           <tr>  
    28.             <td>  
    29.             <asp:Panel ID = "pnlFPSZ" BorderWidth = "1" Width = "100%" runat = "server">  
    30.             <table width = "100%">  
    31.               <tr>  
    32.                 <td>  
    33.                 <table width = "100%">  
    34.                   <tr>  
    35.                     <td style="height: 96px">  
    36.                     <table width = "100%">  
    37.                       <tr>  
    38.                         <td>  
    39.                         <asp:Label ID = "lblTKRQ" Text = "黑色头发:" runat = "server" Font-Underline = "true"></asp:Label>  
    40.                         </td>  
    41.                         <td>  
    42.                         <asp:Label ID = "lblTKRQText" Text = "黑色头发" runat = "server" name="label" BackColor="silver" Style="left: 335px; position: absolute;top: 179px" onclick="getID('lblTKRQText')" Width="50"></asp:Label>  
    43.                         <asp:HiddenField ID="lblTKRQText_hdl_Top" runat="server" Value=""  />  
    44.                         <asp:HiddenField ID="lblTKRQText_hdl_Left" runat="server" Value="" />  
    45.                           
    46.                         </td>  
    47.                       </tr>  
    48.                     </table>  
    49.                     </td>  
    50.                     <td style="height: 96px">  
    51.                     <table width = "100%">  
    52.                       <tr>  
    53.                         <td>  
    54.                         <asp:Label ID = "lblMC" Text = "紫色头发" runat = "server" name="label" BackColor="silver" Style="left: 500px; position: absolute;top: 179px" onclick="getID('lblMC')" Width="50"></asp:Label>  
    55.                         <asp:HiddenField ID="lblMC_hdl_Top" runat="server" Value=""  />  
    56.                         <asp:HiddenField ID="lblMC_hdl_Left" runat="server" Value="" />  
    57.                           
    58.                         </td>  
    59.                       </tr>  
    60.                     </table>  
    61.                     </td>  
    62.                   </tr>  
    63.                   <tr>  
    64.                     <td colspan = "1" style="height: 340px">  
    65.                     <table width = "100%" border = "3">  
    66.                       <tr>  
    67.                         <td style=" 155px">  
    68.                         <asp:Label ID = "lblJKDW_XM" Text = "黑色头发紫色头发" runat = "server" Font-Underline = "true"></asp:Label>  
    69.                         </td>  
    70.                         <td style="height: 41px">  
    71.                         <asp:Label ID = "lblJKDW_XMText" Text = "黑紫色头发" runat = "server" name="label" BackColor="silver" Style="left: 450px; position: absolute;top: 272px" onclick="getID('lblJKDW_XMText')" Width="37"></asp:Label>  
    72.                         <asp:HiddenField ID="lblJKDW_XMText_hdl_Top" runat="server" Value=""  />  
    73.                         <asp:HiddenField ID="lblJKDW_XMText_hdl_Left" runat="server" Value="" />  
    74.                           
    75.                         </td>  
    76.                         <td style="height: 41px">  
    77.                         <table width = "100%" border = "3">  
    78.                           <tr>  
    79.                             <td>  
    80.                             <asp:Label ID = "lblJKFS" Text = "北京市" runat = "server" Font-Underline = "true"></asp:Label>  
    81.                             </td>  
    82.                             <td>  
    83.                             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
    84.                             &nbsp;&nbsp;  
    85.                             <asp:Label ID = "lblJKFSText" Text = "北京市" runat = "server" Font-Underline="True" name="label" BackColor="silver" Style="left: 850px; position: absolute;top: 274px" onclick="getID('lblJKFSText')" Width="27"></asp:Label>  
    86.                             <asp:HiddenField ID="lblJKFSText_hdl_Top" runat="server" Value=""  />  
    87.                         <asp:HiddenField ID="lblJKFSText_hdl_Left" runat="server" Value="" />  
    88.                               
    89.                             </td>  
    90.                           </tr>  
    91.                         </table>  
    92.                         </td>  
    93.                       </tr>  
    94.                     </table>  
    95.                     </td>  
    96.                   </tr>  
    97.                 </table>  
    98.                 </td>  
    99.               </tr>  
    100.             </table>  
    101.             </asp:Panel>  
    102.             </td>  
    103.           </tr>  
    104.         </table>  
    105.         </td>  
    106.       </tr>  
    107.     </table>  
    108.   </div>  
    109.   <br />  
    110.   <div>  
    111.     <table width = "100%">  
    112.       <tr>  
    113.         <td style=" 104px">  
    114.         <asp:Label ID = "lblDQDYJ" Text = "当前打印机" runat = "server"></asp:Label></td>  
    115.         <td style=" 175px">  
    116.         <asp:DropDownList ID = "ddlDYJ" runat = "server" Width="169px"></asp:DropDownList>  
    117.         </td>  
    118.         <td>  
    119.         <input id="ibnSY" runat="server" type="button" value="上移" onclick="moveTop()" />  
    120.         </td>  
    121.         <td>  
    122.         <input id="ibnXY" runat="server" type="button" value="下移" onclick="moveUnder()" />  
    123.         </td>  
    124.         <td>  
    125.         <input id="ibnZY" runat="server" type="button" value="左移" onclick="moveLeft()" />  
    126.         </td>  
    127.         <td>  
    128.         <input id="ibnYY" runat="server" type="button" value="右移" onclick="moveRight()" />  
    129.         </td>  
    130.       </tr>  
    131.       <tr>  
    132.         <td colspan = "2">  
    133.         </td>  
    134.         <td>  
    135.         <asp:Button ID = "ibnBC" Text = "保存" runat = "server" Visible=true OnClick="ibnBC_Click" />  
    136.         </td>  
    137.         <td>  
    138.         <asp:Button ID = "ibnDY" Text = "普通打印" runat = "server" OnClick="ibnDY_Click" />  
    139.         </td>  
    140.         <td colspan = "2">  
    141.             &nbsp;</td>  
    142.       </tr>  
    143.     &nbsp;</table>  
    144.   </div>  
    145. </div>  
    146.   
    147. <!--endprint-->  
    148. <input type="button" name="print" value="预览并打印" onclick="preview()">  
    149.       
    150.       
    151.     </form>  
    152. </body>  
    153. </html>  



    后台: 

    C#代码  收藏代码
    1. using System;  
    2. using System.Data;  
    3. using System.Configuration;  
    4. using System.Web;  
    5. using System.Web.Security;  
    6. using System.Web.UI;  
    7. using System.Web.UI.WebControls;  
    8. using System.Web.UI.WebControls.WebParts;  
    9. using System.Web.UI.HtmlControls;  
    10.   
    11.   
    12. using System.Collections;  
    13.   
    14. public partial class _Default : System.Web.UI.Page   
    15. {  
    16.     Helper app_Helper = new Helper();  
    17.   
    18.     ArrayList al_DZ = new ArrayList();  
    19.   
    20.     string str_BL = "";  
    21.   
    22.     Hashtable htbl = new Hashtable();  
    23.   
    24.     Hashtable htbl_Read = new Hashtable();  
    25.   
    26.     QuickTest qt = new QuickTest();  
    27.   
    28.     protected void Page_Load(object sender, EventArgs e)  
    29.     {  
    30.         if (!IsPostBack)  
    31.         {  
    32.             GetControls(this);  
    33.   
    34.             string[] print = qt.EnumeratePrintersWin();  
    35.   
    36.             ddlDYJ.Items.Insert(0, "--请选择打印机--"); //这个是设置插入静态的数据  
    37.   
    38.             for (int i = 0; i < print.Length; i++)  
    39.             {  
    40.                 ddlDYJ.Items.Insert(i + 1, print[i]); //这个是设置插入静态的数据  
    41.             }  
    42.         }  
    43.     }  
    44.  
    45.     #region 提取注册表中节点为BS_EMSYJKDSZ下所有值,赋给Label控件样式  
    46.   
    47.     private void GetControls(Control c)  
    48.     {  
    49.         if (c is Label)  
    50.         {  
    51.             htbl_Read = app_Helper.get_regist_value("BS_FPSZ");//查找BS_FPSZ节点下的所有值  
    52.   
    53.             foreach (DictionaryEntry die in htbl_Read)  
    54.             {  
    55.                 string writeKey = die.Key.ToString();  
    56.   
    57.                 Hashtable writeStr = (Hashtable)die.Value;  
    58.   
    59.                 string top_In = "";  
    60.                 string left_In = "";  
    61.   
    62.                 foreach (DictionaryEntry die_In in writeStr)  
    63.                 {  
    64.                     string writeKey_In = die_In.Key.ToString();  
    65.   
    66.                     string writeStr_In = die_In.Value.ToString();  
    67.   
    68.                     if (writeKey_In.Equals("Top"))  
    69.                     {  
    70.                         top_In = writeStr_In;  
    71.                     }  
    72.                     if (writeKey_In.Equals("Left"))  
    73.                     {  
    74.                         left_In = writeStr_In;  
    75.                     }  
    76.                     if (!top_In.Equals("") && !left_In.Equals(""))  
    77.                     {  
    78.                         if (c.ID.Equals(writeKey))  
    79.                         {  
    80.                             ((Label)c).Style["Style"] = "position: absolute;top:" + top_In + ";left:" + left_In + "";  
    81.                         }  
    82.                     }  
    83.                 }  
    84.             }  
    85.         }  
    86.         if (c.HasControls())  
    87.         {  
    88.             foreach (Control con in c.Controls)  
    89.             {  
    90.                 GetControls(con);  
    91.             }  
    92.         }  
    93.     }  
    94.  
    95.     #endregion 提取注册表中节点为BS_EMSYJKDSZ下所有值,赋给Label控件样式  
    96.  
    97.     #region 打印  
    98.   
    99.     protected void ibnDY_Click(object sender, EventArgs e)  
    100.     {  
    101.         ibnDY.Attributes.Add("OnClick", "window.print()");  
    102.     }  
    103.  
    104.     #endregion 打印  
    105.  
    106.     #region 保存  
    107.   
    108.     protected void ibnBC_Click(object sender, EventArgs e)  
    109.     {  
    110.         al_DZ.Add("BS_FPSZ");//添加到ArrayList  
    111.   
    112.   
    113.         string lblTKRQText_Left = "";//保存横坐标  
    114.         string lblTKRQText_Top = "";//保存纵坐标  
    115.   
    116.         if (lblTKRQText_hdl_Left.Value.Equals(""))//隐藏控件的值是否为空  
    117.         {  
    118.             lblTKRQText_Left = lblTKRQText.Style["left"];//把页面的横坐标值赋给变量  
    119.         }  
    120.         else  
    121.         {  
    122.             lblTKRQText_Left = lblTKRQText_hdl_Left.Value;//把改变后的横坐标值赋给变量  
    123.         }  
    124.         if (lblTKRQText_hdl_Top.Value.Equals(""))//隐藏控件的值是否为空  
    125.         {  
    126.             lblTKRQText_Top = lblTKRQText.Style["top"];//把页面的纵坐标赋值赋给变量  
    127.         }  
    128.         else  
    129.         {  
    130.             lblTKRQText_Top = lblTKRQText_hdl_Top.Value;//把改变后的纵坐标赋值赋给变量  
    131.         }  
    132.   
    133.         str_BL = "lblTKRQText";//填开日期  
    134.         htbl.Add("FontBold", "false");  
    135.         htbl.Add("FontName", "宋体");  
    136.         htbl.Add("FontSize", "9");  
    137.         htbl.Add("Left", lblTKRQText_Left);  
    138.         htbl.Add("Top", lblTKRQText_Top);  
    139.         app_Helper.registWrite(al_DZ, str_BL, htbl);//把"zldzjc下所有的递增子节点","子节点下的并列所有子节点","指定节点下的所有的键值"添加进注册表里  
    140.   
    141.         //-----------------------------------------------------------------------  
    142.   
    143.         string lblMC_Left = "";//保存横坐标  
    144.         string lblMC_Top = "";//保存纵坐标  
    145.   
    146.         if (lblMC_hdl_Left.Value.Equals(""))//隐藏控件的值是否为空  
    147.         {  
    148.             lblMC_Left = lblMC.Style["left"];//把页面的横坐标值赋给变量  
    149.         }  
    150.         else  
    151.         {  
    152.             lblMC_Left = lblMC_hdl_Left.Value;//把改变后的横坐标值赋给变量  
    153.         }  
    154.         if (lblMC_hdl_Top.Value.Equals(""))//隐藏控件的值是否为空  
    155.         {  
    156.             lblMC_Top = lblMC.Style["top"];//把页面的纵坐标赋值赋给变量  
    157.         }  
    158.         else  
    159.         {  
    160.             lblMC_Top = lblMC_hdl_Top.Value;//把改变后的纵坐标赋值赋给变量  
    161.         }  
    162.   
    163.         str_BL = "lblMC";//交警支队  
    164.         htbl.Clear();  
    165.         htbl.Add("FontBold", "false");  
    166.         htbl.Add("FontName", "宋体");  
    167.         htbl.Add("FontSize", "9");  
    168.         htbl.Add("Left", lblMC_Left);  
    169.         htbl.Add("Top", lblMC_Top);  
    170.         app_Helper.registWrite(al_DZ, str_BL, htbl);//把"zldzjc下所有的递增子节点","子节点下的并列所有子节点","指定节点下的所有的键值"添加进注册表里  
    171.   
    172.         //-----------------------------------------------------------------------  
    173.   
    174.         string lblJKDW_XMText_Left = "";//保存横坐标  
    175.         string lblJKDW_XMText_Top = "";//保存纵坐标  
    176.   
    177.         if (lblJKDW_XMText_hdl_Left.Value.Equals(""))//隐藏控件的值是否为空  
    178.         {  
    179.             lblJKDW_XMText_Left = lblJKDW_XMText.Style["left"];//把页面的横坐标值赋给变量  
    180.         }  
    181.         else  
    182.         {  
    183.             lblJKDW_XMText_Left = lblJKDW_XMText_hdl_Left.Value;//把改变后的横坐标值赋给变量  
    184.         }  
    185.         if (lblJKDW_XMText_hdl_Top.Value.Equals(""))//隐藏控件的值是否为空  
    186.         {  
    187.             lblJKDW_XMText_Top = lblJKDW_XMText.Style["top"];//把页面的纵坐标赋值赋给变量  
    188.         }  
    189.         else  
    190.         {  
    191.             lblJKDW_XMText_Top = lblJKDW_XMText_hdl_Top.Value;//把改变后的纵坐标赋值赋给变量  
    192.         }  
    193.   
    194.         str_BL = "lblJKDW_XMText";//肇事者  
    195.         htbl.Clear();  
    196.         htbl.Add("FontBold", "false");  
    197.         htbl.Add("FontName", "宋体");  
    198.         htbl.Add("FontSize", "9");  
    199.         htbl.Add("Left", lblJKDW_XMText_Left);  
    200.         htbl.Add("Top", lblJKDW_XMText_Top);  
    201.         app_Helper.registWrite(al_DZ, str_BL, htbl);//把"zldzjc下所有的递增子节点","子节点下的并列所有子节点","指定节点下的所有的键值"添加进注册表里  
    202.   
    203.         //-----------------------------------------------------------------------  
    204.   
    205.         string lblJKFSText_Left = "";//保存横坐标  
    206.         string lblJKFSText_Top = "";//保存纵坐标  
    207.   
    208.         if (lblJKFSText_hdl_Left.Value.Equals(""))//隐藏控件的值是否为空  
    209.         {  
    210.             lblJKFSText_Left = lblJKFSText.Style["left"];//把页面的横坐标值赋给变量  
    211.         }  
    212.         else  
    213.         {  
    214.             lblJKFSText_Left = lblJKFSText_hdl_Left.Value;//把改变后的横坐标值赋给变量  
    215.         }  
    216.         if (lblJKFSText_hdl_Top.Value.Equals(""))//隐藏控件的值是否为空  
    217.         {  
    218.             lblJKFSText_Top = lblJKFSText.Style["top"];//把页面的纵坐标赋值赋给变量  
    219.         }  
    220.         else  
    221.         {  
    222.             lblJKFSText_Top = lblJKFSText_hdl_Top.Value;//把改变后的纵坐标赋值赋给变量  
    223.         }  
    224.   
    225.         str_BL = "lblJKFSText";//现金  
    226.         htbl.Clear();  
    227.         htbl.Add("FontBold", "false");  
    228.         htbl.Add("FontName", "宋体");  
    229.         htbl.Add("FontSize", "9");  
    230.         htbl.Add("Left", lblJKFSText_Left);  
    231.         htbl.Add("Top", lblJKFSText_Top);  
    232.         app_Helper.registWrite(al_DZ, str_BL, htbl);//把"zldzjc下所有的递增子节点","子节点下的并列所有子节点","指定节点下的所有的键值"添加进注册表里  
    233.   
    234.         //-----------------------------------------------------------------------  
    235.   
    236.           
    237.   
    238.         GetControls(this);//读取注册表里值赋给页面显示  
    239.     }  
    240.  
    241.     #endregion 保存  
    242.   
    243. }  



    Helper.cs 

    C#代码  收藏代码
    1. using System;  
    2. using System.Data;  
    3. using System.Configuration;  
    4. using System.Web;  
    5. using System.Web.Security;  
    6. using System.Web.UI;  
    7. using System.Web.UI.WebControls;  
    8. using System.Web.UI.WebControls.WebParts;  
    9. using System.Web.UI.HtmlControls;  
    10.   
    11.   
    12. using System.Text.RegularExpressions;  
    13. using System.Collections;  
    14. using System.Web.Configuration;  
    15. using Microsoft.Win32;  
    16. using System.IO;  
    17. using System.Drawing;  
    18.   
    19. using System.Runtime.InteropServices;  
    20. using System.Drawing.Imaging;  
    21.   
    22. /// <summary>  
    23. /// Helper 的摘要说明  
    24. /// </summary>  
    25. public class Helper  
    26. {  
    27.     public Helper()  
    28.     {  
    29.         //  
    30.         // TODO: 在此处添加构造函数逻辑  
    31.         //  
    32.     }  
    33.  
    34.     #region 注册表  
    35.   
    36.     /// <summary>  
    37.     /// 查找指定文件夹下的所有文件夹内的所有值  
    38.     /// </summary>  
    39.     /// <param name="readKey"></param>  
    40.     /// <returns></returns>  
    41.     public Hashtable get_regist_value(string readKey)  
    42.     {  
    43.         Hashtable registHtbl = new Hashtable();  
    44.   
    45.         RegistryKey hkml = Registry.Users;  
    46.         //RegistryKey softwares = hkml.OpenSubKey("S-1-5-21-1220945662-1343024091-1652362547-1017", true);  
    47.         //RegistryKey softwaress = softwares.OpenSubKey("Software", true);  
    48.         //RegistryKey aimdir = softwaress.OpenSubKey("VB and VBA Program Settings", true);  
    49.   
    50.         RegistryKey aimdir = hkml.OpenSubKey("S-1-5-21-1177238915-527237240-1801674531-1013\Asp Net Settings", true);  
    51.         RegistryKey aimdirs = aimdir.OpenSubKey("zldzjc", true);  
    52.         RegistryKey aimdirss = aimdirs.CreateSubKey(readKey);  
    53.   
    54.         if (aimdirss.SubKeyCount != 0)  
    55.         {  
    56.             foreach (string subKeyName in aimdirss.GetSubKeyNames())  
    57.             {  
    58.                 Hashtable registSubHtbl = new Hashtable();  
    59.   
    60.                 RegistryKey aimdirsss = aimdirss.CreateSubKey(subKeyName);  
    61.   
    62.                 foreach (string subValueName in aimdirsss.GetValueNames())  
    63.                 {  
    64.                     string aaa = aimdirsss.GetValue(subValueName).ToString();  
    65.   
    66.                     registSubHtbl.Add(subValueName, aaa);  
    67.   
    68.   
    69.                 }  
    70.   
    71.                 registHtbl.Add(subKeyName, registSubHtbl);  
    72.   
    73.   
    74.             }  
    75.         }  
    76.   
    77.         hkml.Close();  
    78.         //softwares.Close();  
    79.         aimdirs.Close();  
    80.         aimdirss.Close();  
    81.   
    82.         return registHtbl;  
    83.     }  
    84.   
    85.     /// <summary>  
    86.     /// 写入注册表中指定的内容  
    87.     /// </summary>  
    88.     /// <param name="al_subKey">zldzjc下所有的递增子节点</param>  
    89.     /// <param name="al_subKeySub">子节点下的并列所有子节点</param>  
    90.     /// <param name="htbl">指定节点下的所有的键值</param>  
    91.     public void registWrite(ArrayList al_subKeyed, string al_subKeying, Hashtable htbl)  
    92.     {  
    93.         RegistryKey hkml = Registry.CurrentUser;  
    94.         //RegistryKey softwares = hkml.CreateSubKey("S-1-5-21-1220945662-1343024091-1652362547-1003");  
    95.         //RegistryKey software = hkml.OpenSubKey("SOFTWARE");  
    96.         //RegistryKey aimdir = software.OpenSubKey("Asp Net Settings");  
    97.         RegistryKey aimdir = hkml.OpenSubKey("S-1-5-21-1177238915-527237240-1801674531-1013\Asp Net Settings", true);  
    98.         RegistryKey aimdirs = aimdir.OpenSubKey("zldzjc", true);  
    99.   
    100.         for (int i = 0; i < al_subKeyed.Count; i++)  
    101.             aimdirs = aimdirs.CreateSubKey(al_subKeyed[i].ToString());  
    102.   
    103.   
    104.         RegistryKey open = aimdirs.CreateSubKey(al_subKeying);  
    105.   
    106.         foreach (DictionaryEntry die in htbl)  
    107.         {  
    108.             string writeKey = die.Key.ToString();  
    109.             string writeStr = die.Value.ToString();  
    110.   
    111.             open.SetValue(writeKey, writeStr);  
    112.         }  
    113.   
    114.   
    115.   
    116.         hkml.Close();  
    117.         //softwares.Close();  
    118.         //software.Close();  
    119.         aimdir.Close();  
    120.         aimdirs.Close();  
    121.     }  
    122.  
    123.     #endregion 注册表  
    124.   
    125. }  



    QuickTest.cs 

    C#代码  收藏代码
    1. using System;  
    2. using System.Data;  
    3. using System.Configuration;  
    4. using System.Web;  
    5. using System.Web.Security;  
    6. using System.Web.UI;  
    7. using System.Web.UI.WebControls;  
    8. using System.Web.UI.WebControls.WebParts;  
    9. using System.Web.UI.HtmlControls;  
    10.   
    11. using System.Collections;  
    12.   
    13. using System.Runtime.InteropServices;  
    14.   
    15. using System.Diagnostics;  
    16.   
    17. using System.Drawing.Printing;  
    18.   
    19. /// <summary>  
    20. /// QuickTest 的摘要说明  
    21. /// </summary>  
    22. public class QuickTest  
    23. {  
    24.     [DllImport("winspool.drv", CharSet = CharSet.Auto)]  
    25.   
    26.     static extern bool EnumPrinters(int flags, string name, int level, IntPtr pPrinterEnum,  
    27.   
    28.     int cbBuf, out int pcbNeeded, out int pcReturned);  
    29.   
    30.     private const int PRINTER_ENUM_NETWORK = 0x00000040;  
    31.   
    32.     private const int PRINTER_ENUM_LOCAL = 0x00000002;  
    33.   
    34.     private const int PRINTER_ENUM_REMOTE = 0x00000010;  
    35.   
    36.     [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]  
    37.   
    38.     struct PRINTER_INFO_1  
    39.     {  
    40.   
    41.         int flags;  
    42.   
    43.         [MarshalAs(UnmanagedType.LPTStr)]  
    44.   
    45.         public string pDescription;  
    46.   
    47.         [MarshalAs(UnmanagedType.LPTStr)]  
    48.   
    49.         public string pName;  
    50.   
    51.         [MarshalAs(UnmanagedType.LPTStr)]  
    52.   
    53.         public string pComment;  
    54.   
    55.     }  
    56.   
    57.     public string[] EnumeratePrintersWin()  
    58.     {  
    59.         string[] print_All = null;  
    60.   
    61.         bool Success;  
    62.   
    63.         int cbRequired;  
    64.   
    65.         int nEntries;  
    66.   
    67.         IntPtr outb = IntPtr.Zero;  
    68.   
    69.         Success = EnumPrinters(PRINTER_ENUM_NETWORK | PRINTER_ENUM_LOCAL | PRINTER_ENUM_REMOTE, null, 1, outb, 0, out cbRequired, out nEntries);  
    70.   
    71.         outb = Marshal.AllocHGlobal(cbRequired);  
    72.   
    73.         Success = EnumPrinters(PRINTER_ENUM_NETWORK | PRINTER_ENUM_LOCAL | PRINTER_ENUM_REMOTE, null, 1, outb, cbRequired, out cbRequired, out nEntries);  
    74.   
    75.         PRINTER_INFO_1[] portsArray = new PRINTER_INFO_1[cbRequired];  
    76.   
    77.         IntPtr current = outb;  
    78.   
    79.         try  
    80.         {  
    81.             if (nEntries != 0)  
    82.             {  
    83.                 print_All = new string[nEntries];  
    84.             }  
    85.             else  
    86.             {  
    87.                 print_All = new string[1];  
    88.   
    89.                 print_All[0] = "null";  
    90.   
    91.                 return print_All;  
    92.             }  
    93.   
    94.   
    95.             for (int i = 0; i < nEntries; i++)  
    96.             {  
    97.                 portsArray[i] = (PRINTER_INFO_1)Marshal.PtrToStructure(current,  
    98.   
    99.                 typeof(PRINTER_INFO_1));  
    100.   
    101.                 current = (IntPtr)((int)current + Marshal.SizeOf(typeof(PRINTER_INFO_1)));  
    102.   
    103.                 //Console.WriteLine(i + ":  " + portsArray[i].pName + " " + portsArray[i].pDescription + " " + portsArray[i].pComment + " ");  
    104.   
    105.                 print_All[i] = i + ":  " + portsArray[i].pName + " " + portsArray[i].pDescription + " " + portsArray[i].pComment + " ";  
    106.   
    107.   
    108.             }  
    109.   
    110.         }  
    111.   
    112.         catch (Exception exp)  
    113.         {  
    114.   
    115.             Console.WriteLine(exp.StackTrace);  
    116.   
    117.         }  
    118.   
    119.         Marshal.FreeHGlobal(outb);  
    120.   
    121.         return print_All;  
    122.     }  
    123.   
    124.     public QuickTest()  
    125.     {  
    126.   
    127.     }  
    128.   
    129.     public static void Main()  
    130.     {  
    131.   
    132.         QuickTest qt = new QuickTest();  
    133.   
    134.         qt.EnumeratePrintersWin();  
    135.   
    136.         Console.ReadLine();  
    137.     }  
    138.   
    139.   
    140. }  



    js/Move.js 

    Js代码  收藏代码
    1. // JScript 文件  
    2.   
    3.   
    4.   
    5.     var labelID = "";  
    6.     var hdlID = "";  
    7.   
    8.     function moveTop()  
    9.     {  
    10.        var a=document.getElementById(labelID).style.top;  
    11.        var Top=a.substring(0,a.indexOf("px"));  
    12.        document.getElementById(labelID).style.top= parseInt(Top)-10;// 向上  
    13.          
    14.        document.getElementById(labelID+"_hdl_Top").value=document.getElementById(labelID).style.top;    
    15.     }  
    16.     function moveUnder()  
    17.     {  
    18.        var aa=document.getElementById(labelID).style.top;  
    19.        var Topp=aa.substring(0,aa.indexOf("px"));  
    20.        document.getElementById(labelID).style.top= parseInt(Topp)+10;// 向下  
    21.          
    22.        document.getElementById(labelID+"_hdl_Top").value=document.getElementById(labelID).style.top;    
    23.     }  
    24.     function moveLeft()  
    25.     {  
    26.        var b=document.getElementById(labelID).style.left;  
    27.        var Left=b.substring(0,b.indexOf("px"));  
    28.        document.getElementById(labelID).style.left= parseInt(Left)-10;// 向左  
    29.          
    30.        document.getElementById(labelID+"_hdl_Left").value=document.getElementById(labelID).style.left;          
    31.     }  
    32.     function moveRight()  
    33.     {  
    34.        var bb=document.getElementById(labelID).style.left;  
    35.        var Leftt=bb.substring(0,bb.indexOf("px"));  
    36.        document.getElementById(labelID).style.left= parseInt(Leftt)+10;// 向右边  
    37.          
    38.        document.getElementById(labelID+"_hdl_Left").value=document.getElementById(labelID).style.left;     
    39.     }  
    40.     function getID(labelIDCS)  
    41.     {  
    42.        //labelID = "ctl00_ContentPlaceHolder1_"+labelIDCS;  
    43.   
    44. labelID = labelIDCS;  
    45.   
    46.        var arrAll=document.all;  
    47.   
    48.        for(i=0;i <arrAll.length;i++)  
    49.        {  
    50.            if(arrAll[i].name == 'label')  
    51.            {  
    52.               document.getElementById(arrAll[i].id).style.color = "black";  
    53.            }  
    54.        }  
    55.        document.getElementById(labelID).style.color = "red";  
    56.     }  
    57.     function font_Update()  
    58.     {  
    59.        var arrAll=document.all;  
    60.   
    61.        for(i=0;i <arrAll.length;i++)  
    62.        {  
    63.            if(arrAll[i].name == 'label')  
    64.            {  
    65.               document.getElementById(arrAll[i].id).style.fontFamily="Times New Roman";   
    66.            }  
    67.        }  
    68.     }  



    js/preview.js 

    Js代码  收藏代码
      1. // JScript 文件  
      2.   
      3.   
      4.   
      5.    <!--  
      6.     function preview()  
      7.     {  
      8.         bdhtml=window.document.body.innerHTML;  
      9.          
      10.         sprnstr="<!--startprint-->";  
      11.         eprnstr="<!--endprint-->";  
      12.         prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);  
      13.           
      14.          alert("prnhtml:"+prnhtml);  
      15.           
      16.         prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));  
      17.         window.document.body.innerHTML=prnhtml;  
      18.         window.print();  
      19.     }   
      20.     -->  
  • 相关阅读:
    迷宫最短路径问题的dfs,bfs实现
    高效率的排序算法2--归并排序
    高效率的排序算法1--快速排序
    POJ No.2386 Lake Counting
    部分和问题 --dfs
    dfs的一个小实现(啊哈算法的例题)
    HDU 5710 Digit Sum
    【视频播放器】在macOS上使用IINA
    视音频格式基础知识&视频压缩
    影视作品(电影,电视剧,PV,MAD,AMV)的制作程序
  • 原文地址:https://www.cnblogs.com/ranzige/p/3824754.html
Copyright © 2011-2022 走看看