C # SOAPFORMATTER Serialization: Read the image to the XML file, and reduce the display in PictureBox as needed

xiaoxiao2021-03-06  108

using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization.Formatters. SOAP; use system.ipe; using system.text;

Summary description of Namespace WindowsApplication9 {///

/// Form1. /// public class Form1: System.Windows.Forms.Form {private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.TextBox textBox2; public System.Windows.Forms.OpenFileDialog ofd; private int pbHeight; private System.Windows.Forms.PictureBox pb; /// /// design variables required. /// private system.componentmodel.container components = null;

Public Form1 () {// // Windows Form Designer Support for // InitializeComponent ();

// // Todo: Add any constructor code after INITIALIZEComponent call //}

///

/// Clean all the resources being used. /// Protected Override Void Dispose (Bool Disposing) {if (disponents! = Null) {components.dispose ();}} Base.Dispose

#REGION Windows Form Designer The code ///

/// designer supports the required method - do not use the code editor to modify the // / this method.

/// private void InitializeComponent () {System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader (); System.Resources.ResourceManager resources = new System.Resources.ResourceManager (typeof (Form1)); this .textBox1 = new System.Windows.Forms.TextBox (); this.button1 = new System.Windows.Forms.Button (); this.button2 = new System.Windows.Forms.Button (); this.textBox2 = new System .Windows.forms.textbox (); this.ofd = new system.windows.forms.openfiledialog (); this.pb = new system.windows.Forms.PictureBox (); this.suspendlayout (); // // textbox1 // this.textBox1.imemode = system.windows.forms.imemode.disable; this.textbox1.location = new system.drawing.point (8, 8); this.TextBox1.name = "textbox1"; this.TextBox1. Size = new System.Drawing.Size (200, 21); this.textBox1.TabIndex = 0; this.textBox1.Text = ""; this.textBox1.KeyPress = new System.Windows.Forms.KeyPressEventHandler (this.uuuu ); // // button1 // this.button1.location = new system.drawing.point (416, 0); this.button1.name = "button1"; this.button1.size = new system.drawing.size (80, 32) This.button1.tabindex = 1; this.button1.text = "button1"; this.button1.click = new system.eventhandler (this.button1_click); // // button2 // this.button2.Location = New System.drawing.point (120, 0); this.button2.name = "button2"; this.button2.size = new system.drawing.size (88, 32); this.button2.tabindex = 2; this.button2 .Text = "Button2"; this.button2.click =

New system.eventhandler (this.button2_click); /////////////////////////////////ww.drawing.point (216, 8); this.TextBox2.name = "textbox2"; this.TextBox2.size = new system.drawing.size (200, 21); this.textbox2.tabindex = 3; this.textBox2.text = "textbox2"; // // OFD // this.Ofd.defaultExt = ((string) (ConfigurationAppSetting .GetValue ("BMP", TypeOf (String))))))))))))))))))))))))))))))); this.Ofd.FileName = ("OFD.FILENAME", TYPEOF (String))))))))))))))))))))))))))))))))))))))) True; this.ofd.title = "Hello"; this.ofd.fileok = new system.componentmodel.canceleventhandler (this.openfiledialog1_fileok; // // pb // this.pb.image = ((System.drawing) .Image) ("pb.image"))); this.pb.location = new system.drawing.point (8, 40); this.pb.name = "pb"; this.pb.size = new system.drawing.size (580, 435); this.pb.sizemode = system.windows.forms.pictureboxsizemode.stretchimage; this.pb.tabindex = 4; this.pb.tabstop = f Alse; // // form1 // this.autoscalebasesize = new system.drawing.size (6, 14); this.clientsize = new system.drawing.size (528, 273); this.Controls.add (this.TextBox2 This.controls.add (this.button2); this.controls.add (this.button1); this.Controls.add (this.TextBox1); this.controls.add (this.pb); this.name = "Form1"; this.Showintaskbar = false; this.text = "form1"; this.TransparencyKey = system.drawing.color.fromargb ((System.byte) ((system.byte) (128) ((System.byte) (255)))); this.Load = new system.EventHandler (this.form1_load);

this.ResumeLayout (false);} #ENDREGION

///

/// The primary entry point of the application. /// [stathread] static void main () {Application.run (new form1 ());}

Private void uuuu (object sender, system.windows e) {textbox a = (system.windows.forms.textbox) Sender; // messagebox.show (a.text);

IF (a.text.length> = 5) E.handled = true;

private void Form1_Load (object sender, System.EventArgs e) {this.Width = 700; this.Height = 520; this.textBox1.Left = 10; this.textBox1.Top = 10; this.textBox2.Left = textBox1.Width TEXTBOX1.LEFT 10; this.button1.Left = this.textBox2.Lid this.textbox2.width; this.button2.LHIS.BUTTON1.TOP = this.textBox2.top = this .TextBox1.top; this.button1.top = this.textbox2.top; this.button2.top = this.button1.top; this.pb.top = this.textBox1.top this.TextBox1.Height 10; this .pb.height = this.Height-this.pb.top-20; this.pb.Left = 10; this.pb.width = this.width / 2-10-this.pb.left; Pb.SizeMode = PictureBoxSizeMode .Autosize; this.opacity = 1; PBHEIGHT = Pb.height; //this.pb.

Private void OpenFiledialog1_fileok (Object Sender, System.comPonentmodel.canceleventArgs E) {}

private void button2_Click (object sender, System.EventArgs e) {Stream stream = new FileStream ( "E: //Image.xml", FileMode.Open, FileAccess.Read, FileShare.Read); SoapFormatter f = new SoapFormatter (); Image bb = (image) f.deSerialize (stream); pb.image = bb;}

转载请注明原文地址:https://www.9cbs.com/read-103594.html

New Post(0)