• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

asp.net修改注册表(页面打印时页眉、页脚、页边距、背景颜色和图像) - 张银 ...

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Win32;

public partial class PrintSetDefault : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (ReadReg() == 1)
        {
            if (WriteReg() == 1)
            {
                ReadReg();
                Response.Write("Game over!");
            }
        }
    }



    /// <summary>
    /// 读注册表
    /// </summary>
    /// <returns></returns>
    protected int ReadReg()
    {
       //读注册表
        RegistryKey regRead;
       //读取HKEY_CURRENT_USER主键里的子键
        regRead = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\PageSetup", true);
       if (regRead == null) //如果该子键不存在
        {
            Response.Write("PageSetup:null</br>");
            return 0;
        }
        else
        {
            Response.Write("PageSetup:OK</br>");

            object obj = regRead.GetValue("header") == null ? "null" : regRead.GetValue("header"); //读取值
            Response.Write("header:" + obj.ToString() + "</br>");

            obj = regRead.GetValue("footer") == null ? "null" : regRead.GetValue("footer"); //读取值
            Response.Write("footer:" + obj.ToString() + "</br>");

            obj = regRead.GetValue("margin_left") == null ? "null" : regRead.GetValue("margin_left"); //读取值
            Response.Write("margin_left:" + obj.ToString() + "</br>");

            obj = regRead.GetValue("margin_right") == null ? "null" : regRead.GetValue("margin_right"); //读取值
            Response.Write("margin_right:" + obj.ToString() + "</br>");

            obj = regRead.GetValue("margin_top") == null ? "null" : regRead.GetValue("margin_top"); //读取值
            Response.Write("margin_top:" + obj.ToString() + "</br>");

            obj = regRead.GetValue("margin_bottom") == null ? "null" : regRead.GetValue("margin_bottom"); //读取值
            Response.Write("margin_bottom:" + obj.ToString() + "</br>");

            obj = regRead.GetValue("Print_Background") == null ? "null" : regRead.GetValue("Print_Background"); //读取值
            Response.Write("Print_Background:" + obj.ToString() + "</br>");

            Response.Write("</br>");
        }
        regRead.Close();
        return 1;
    }

    /// <summary>
    /// 写注册表
    /// </summary>
    protected int WriteReg()
    {
        //写注册表
         RegistryKey regWrite;
        //往HKEY_CURRENT_USER主键里的写子键
         //如果子键已经存在系统会自动覆盖它
         regWrite = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Internet Explorer\\PageSetup");
        //往Test子键里添数据项
         regWrite.SetValue("header", "&w&bPage &p of &P");
        regWrite.SetValue("footer", "&u&b&d");
        regWrite.SetValue("margin_left", 0.750000);
        regWrite.SetValue("margin_right", 0.750000);
        regWrite.SetValue("margin_top", 0.750000);
        regWrite.SetValue("margin_bottom", 0.750000);
        regWrite.SetValue("Print_Background", "no");
        //关闭该对象
         regWrite.Close();

        return 1;

    }
}

以上结果是恢复成默认值。也可以改为0。 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap