1. Form and interface design-set the form size

Source: Internet
Author: User

After opening the software, the user first sees the controls on the form and form. It is very important to set the size of the form and reasonably set the relationship between the form and the control.

041 obtain the desktop size

C # provides a Screen object, which encapsulates Screen-related information. You can obtain the Screen information by reading the related properties of the Screen object. The Screen. PrimaryScreen. WorkingArea attribute is used to obtain the display workspace. The work area is the desktop area of the monitor, excluding the taskbar, dock window, and dock toolbar. Screen. PrimaryScreen. WorkingArea. Width is used to read the desktop Width. Screen. PrimaryScreen. WorkingArea. Height can read the desktop Height.

Create a project. The default form is Form1. Add a Button control for Form1 to get the desktop size. Add two TextBox controls to output the obtained desktop size.

Namespace _ 041_0000size {public partial class Form1: Form {public Form1 () {InitializeComponent ();} private void button#click (object sender, EventArgs e) {textBox1.Text = Screen. primaryScreen. workingArea. width. toString (); // display the desktop width textBox2.Text = Screen. primaryScreen. workingArea. height. toString (); // display the desktop height }}}

042 move button between forms

A visible control contains a Parent attribute, which indicates the Parent object of the control. Generally, this attribute is set to a form, which can be used to control the form.

Create a project. The default form is Form1, add a Button control for Form1, and then add a form. The default form Name attribute is Form2.

Namespace _ 042_MoveButton {public partial class Form1: Form {Form2 f; public Form1 () {InitializeComponent ();} private void Form1_Load (object sender, EventArgs e) {f = new Form2 (); // instantiate a Form2 object f. show (); // display Form2 form} private void button#click (object sender, EventArgs e) {if (button1.Parent = this) // when the parent container of the control button1 is form Form1 {f. controls. add (this. button1); this. button1.Text = "back to original";} else // when the parent container of the control button1 is form Form2 {this. controls. add (button1); this. button1.Text = "starting to move ";}}}

043 implement Office Assistant

To achieve the Office assistant effect, you must use a third-party control provided by Microsoft. Click "select items" in the toolbox, select the Microsoft Agent Control component from the COM component tab in the pop-up dialog box, add it to the toolbox, and add it to the form.

Create a project. The default form is Form1. Add a ListBox control for Form1 to allow users to select actions of characters.

Namespace _ 043_OfficeAssistant {public partial class Form1: Form {public partial class Form1: Form {IAgentCtlCharacterEx ICCE; // defines the IAgentCtlCharacterEx class Object IAgentCtlRequest rn; // define the IAgentCtlRequest object string [] ws = new string [10] {"Acknowledge", "LookDown", "Sad", "Alert", "LookDownBlink ", "Search", "Announce", "LookUp", "Think", "Blink"}; // defines a string array public Form1 () {InitializeComponent ();} private void Form1_Load (object sender, EventArgs e) {for (int I = 0; I <10; I ++) // looping {listBox1.Items. add (ws [I]); // Add the content in the string array to the control listBox1} Rn = axAgent1.Characters. load ("merlin", "merlin. acs "); // load the specified file ICCE = axAgent1.Characters. character ("merlin"); // set the ICCE to simulate the expression of the Office assistant. show (0); // display the facial expression of the simulated Office assistant} private void listBox1_SelectedIndexChanged (object sender, EventArgs e) {ICCE. stopAll (""); // stop the ICCE of all simulated Office assistants. play (ws [listBox1.SelectedIndex]); // scare the selected expression in the listBox1 control }}}

 

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.