Make your own console

zhaozj2021-02-16  57

A few days ago, someone asked: How to set a sub-window as the "console" of the main window, that is, to perform some systematic operations above it. For example: the component of the function, the call of sub function. If this makes it, then it has an intuitiveness. Ok, don't talk nonsense, enter the topic :)

We use a method: add a sub-window, and set the sub-window to the bottom, add a stretchable picture box on the sub-window. When the sub-window is activated, it is set to the bottom layer. Also, the user is not allowed to close it, it can be. Specific method: Load a sub-window (Form1) and override the onactivated event of the child window: protected override void onactivated (Eventargs E) {sendtoback ();} =============== ==== On the sub-window, add the Picturebox you want to load an empty window in the main window: form mdichile = null; write the master window MDICHACTIVEATE Event: Private Void Mainform_MdichildActActActActActActActActAth (Object Sender, System.EventArgs E) {Form Form = this.activemdichild; if (form! = null) {if (form! = null) {mdichile.activate ();}} else {mdichile = form;}} else {form1.activate ();}} ================== This is ok. :-)

Here is its source code: source code FORM1 (main window): use system; use system.drawing; use system.collections; useing system.componentmodel; use system.windows.form; using system.data;

Namespace Demo {///

/// Form1 summary description. ///

Public class form1: system.windows.Forms.form {/// // Required designer variable. /// private System.ComponentModel.Container components = null; private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.MenuItem menuItem1; private System.Windows.Forms.MenuItem menuItem2; private Form form = null; private Form3 form3 = new form3 ();

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 (Disposing);} #Region Windows Form Designer Generated code // /

/// Designer supports the required method - Do not use the code editor to modify the // / this method. ///

private void InitializeComponent () {this.mainMenu1 = new System.Windows.Forms.MainMenu (); this.menuItem1 = new System.Windows.Forms.MenuItem (); this.menuItem2 = new System.Windows.Forms.MenuItem () ; // // mainmenu1 // this.mainMenu1.Menuitems.addrange (new system.windows.forms.Menuitem [] {this.Menuitem1}); /// Menuitem1 // this.Menuitem1.index = 0; this. Menuitem1.Menuitems.addrange (new system.windows.forms.Menuitem [] {this.Menuitem2}); this.Menuitem1.text = "123"; /// Menuitem2 // this.Menuitem2.index = 0; this. Menuitem2.text = "123"; this.Menuitem2.click = new system.EventHandler (this.Menuitem2_click); // // form1 // this.autoscalebasesize = new system.drawing.size (6, 14); this. Clientsize = new system.drawing.size (508, 302); this.ismdicontainer = true; this.Menu = this.mainMenu1; this.name = "form1"; this.text = "form1"; this.mdichildactivate = new System.eventhandler THIS.FORM1_MDICHILDACTIVATE); this.Load = new system.eventhandler (this.form1_load);

} #Endregion

///

/// The main entry point for the application. ///

[Stathread] static void main () {application.run (new form1 ());}

Private Void Menuitem2_Click (Object sender, system.eventargs e) {form2 form = new form2 (); form.mdiparent = this; form.show ();}

private void Form1_MdiChildActivate (object sender, System.EventArgs e) {Form theform = this.ActiveMdiChild; if (theform = null!) {if (theform is Form3) {if (form = null!) {this.form.Activate () }}} Else {form = theform;}} else {form3.activate ();}} private void form1_load (Object sender, system.eventargs e) {form3.mdiparent = this; form3.Show ();}}} = ============================2450; using system.collections; using system.componentmodel; using system.windows.form;

Namespace Demo {///

/// Form2's summary description. ///

Public class form2: system.windows.Forms.form {/// // Required designer variable. ///Prate system.componentmodel.container components = null;

Public Form2 () {// // Windows Form Designer Support for // InitializationComponent ();

// // 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 (Disposing);

#Region Windows Form Designer Generated Code ///

/// Designer supports the required method - Do not use the code editor to modify the // / this method. ///

Private void initializecomponent () {this.components = new system.componentmodel.container (); this.size = new system.drawing.size (300, 300); this.text = "form2";} #ENDREGON}} ==== =========================

Form3 (underlying window):

Using system; using system.collections; using system.componentmodel; using system.windows.form;

Summary description of Namespace Demo {////// Form3. ///

Public class form3: system.windows.forms.form {private system.windows.Forms.Button button1; private system.windows.Forms.Button Button2; //// The designer variable is required. ///Prate system.componentmodel.container components = null;

Public Form3 () {// // Windows Form Designer Support for // InitializationComponent ();

// // 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 (Disposing);

#Region Windows Form Designer Generated Code ///

/// Designer supports the required method - Do not use the code editor to modify the // / this method. ///

Private void initializeComponent () {this.button1 = new system.windows.Forms.Button (); this.button2 = new system.windows.Forms.Button (); this.suspendlayout (); // // button1 // THIS .Button1.Location = new system.drawing.point (12, 32); this.button1.name = "button1"; 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 (16, 72); this.button2.name = "button2"; this.button2 .Tabindex = 2; this.Button2.text = "button2"; this.button2.click = new system.eventhandler (this.button2_click); // // form3 // this.autoscalebasesize = new system.drawing.size 6, 14); this.ClientSize = new system.drawing.size (292, 266); this.controls.add (this.button2); this.controls.add (this.button1); this.name = "form3" This.text = "form3"; this.ResumeLayout (false);} #ENDREGION protected override void onactivated (Event Args e) {sendtoback ();

Private void button1_click (object sender, system.eventargs e) {messagebox.show ("click Test One!");

Private void button2_click (object sender, system.eventargs e) {messagebox.show ("click Test 2!");}}} It is generally these. :)

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

New Post(0)