Asp.net modify the Registry (when the page is printed, the header, footer, margin, background color and image)

Source: Internet
Author: User

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>
/// Read the Registry
/// </Summary>
/// <Returns> </returns>
Protected int ReadReg ()
{
// Read the Registry
RegistryKey regRead;
// Read the subkey in the HKEY_CURRENT_USER primary key
RegRead = Registry. CurrentUser. OpenSubKey ("Software \ Microsoft \ Internet Explorer \ PageSetup", true );
If (regRead = null) // if the child key does not exist
{
Response. Write ("PageSetup: null </br> ");
Return 0;
}
Else
{
Response. Write ("PageSetup: OK </br> ");

Object obj = regRead. GetValue ("header") = null? "Null": regRead. GetValue ("header"); // read the value
Response. Write ("header:" + obj. ToString () + "</br> ");

Obj = regRead. GetValue ("footer") = null? "Null": regRead. GetValue ("footer"); // read the value
Response. Write ("footer:" + obj. ToString () + "</br> ");

Obj = regRead. GetValue ("margin_left") = null? "Null": regRead. GetValue ("margin_left"); // read the value
Response. Write ("margin_left:" + obj. ToString () + "</br> ");

Obj = regRead. GetValue ("margin_right") = null? "Null": regRead. GetValue ("margin_right"); // read the value
Response. Write ("margin_right:" + obj. ToString () + "</br> ");

Obj = regRead. GetValue ("margin_top") = null? "Null": regRead. GetValue ("margin_top"); // read the value
Response. Write ("margin_top:" + obj. ToString () + "</br> ");

Obj = regRead. GetValue ("margin_bottom") = null? "Null": regRead. GetValue ("margin_bottom"); // read the value
Response. Write ("margin_bottom:" + obj. ToString () + "</br> ");

Obj = regRead. GetValue ("Print_Background") = null? "Null": regRead. GetValue ("Print_Background"); // read the value
Response. Write ("Print_Background:" + obj. ToString () + "</br> ");

Response. Write ("</br> ");
}
RegRead. Close ();
Return 1;
}

/// <Summary>
/// Write the Registry
/// </Summary>
Protected int WriteReg ()
{
// Write the Registry
RegistryKey regWrite;
// Write the subkey to the primary key of HKEY_CURRENT_USER
// If the sub-key already exists, the system will automatically overwrite it
RegWrite = Registry. CurrentUser. CreateSubKey ("Software \ Microsoft \ Internet Explorer \ PageSetup ");
// Add data items to the Test subkey
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 ");
// Close this object
RegWrite. Close ();

Return 1;

}
}
 
The above result is restored to the default value. You can also change it to 0.

Eat to live, but do not live to eat.
 

 

From Zhang Yin's blog

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.