1. Form and interface design-form Animation

Source: Internet
Author: User

You can add some animation effects on the form to add some fun for the operator.

Scroll subtitles in the 031 form

The effect of rolling subtitles is actually to change the text position. The best way to display a string of text on the form is to use the Label control. You can change the position of the Label control to the position of the text. If the position of the Label control is constantly moving horizontally, the text will scroll. You can change the horizontal position of the Label control by changing the value of the Left attribute of the Label control. Use the Timer control to control the time of text movement.

Create a project. The default form is Form1. Add the Label control on the form to display the message. Add the Button control to control the movement of the message and the Timer control to control the scroll speed.

Namespace _ 031_MoveWindows {public partial class Form1: Form {public Form1 () {InitializeComponent ();} private void button#click (object sender, EventArgs e) {timer1.Enabled = true; // start rolling} private void button2_Click (object sender, EventArgs e) {timer1.Enabled = false; // stop rolling} private void button3_Click (object sender, EventArgs e) {this. close ();} private void timereffectick (object sender, EventArgs e) {label1.Left-= 2; // set the distance between the left edge of label1 and the left edge of the container's workspace. if (label1.Right <0) {label1.Left = this. width; // set the distance between the left edge of labal1 and the left edge of the container's workspace to the Width of the form }}}}

032 animation display form

Windows provides an API function, AnimateWindow, which can be used to animation the form.

: The namespace System. RunTime. InteropServices must be referenced when calling Windows API functions.

Create a project. The default form is Form1. Add the PictureBox control to the form and set the Image attribute of the PictureBox control.

Namespace _ 032_FalshWindows {public partial class Form1: Form {public const Int32 AW_HOR_POSITIVE = 0x00000001; public const Int32 AW_HOR_NEGATIVE = 0x00000002; public const Int32 AW_VER_POSITIVE = 0x00000004; public const Int32 AW_VER_NEGATIVE = 0x00000008; public const Int32 AW_CENTER = 0x00000010; public const Int32 AW_HIDE = 0x00010000; public const Int32 AW_ACTIVATE = 0x00020000; public const Int32 AW_SLIDE = 0x00040000; public const Int32 AW_BLEND = 0x00080000; public Form1 () {InitializeComponent (); // initialize the animation window (this. handle, 300, AW_SLIDE + AW_VER_NEGATIVE); // start form animation} [DllImportAttribute ("user32.dll")] private static extern bool AnimateWindow (IntPtr hwnd, int dwTime, int dwFlags ); private void form=formclosed (object sender, FormClosedEventArgs e) {AnimateWindow (this. handle, 300, AW_SLIDE + AW_VER_NEGATIVE + AW_HIDE); // end form animation }}}

033 create a flickering form

Windows provides an API function FlashWindow, which can flash the form. This function can only make the form flash. If the window is non-stop flashing, you need to use a Timer control to call this function to make the form flash every other time.

Create a project. The default form is Form1. Add the PictureBox control to display the form, set the Image attribute of the PictureBox control, and add the Button control and Timer control to start and stop flashing.

Namespace _ 033_ShanShuoWindows {public partial class Form1: Form {public Form1 () {InitializeComponent ();} private void button#click (object sender, EventArgs e) {timer1.Enabled = true; // start timer1 timer} private void button2_Click (object sender, EventArgs e) {timer1.Enabled = false; // disable timer1 timer} [System. runtime. interopServices. dllImportAttribute ("user32.dll")] public static extern bool FlashWindow (IntPtr handle, bool bInvert); private void timer1_Tick (object sender, EventArgs e) {FlashWindow (this. handle, true); // start the form blinking function }}}

034 implement the taskbar Notification Window

The time events of the Timer component are used to determine the status of the form. In the display process, the ShowWindow function provided by Windows is used.

1. Create a project. The default form is TaskMessageWindow. Add a Window form and name it MainForm.

2. Add two Button controls, three Label controls, one TextBox Control and one RichTextBox Control to the TaskMessageWindow form, and set the StartPosition attribute of the form to CenterScreen.

3. add two Label controls, three Timer controls, one PictureBox control, one ImageList control, and one policyicon control to the MainForm. Modify the Interval attribute of the Timer1 component to 1000, the Interval attribute of the Timer2 component is 400.

Reference: Winform switch or reset the tray icon

// TaskMessageWindow Form code namespace _ 034_TaskMessageWindow {public partial class TaskMessageWindow: Form {public TaskMessageWindow () {InitializeComponent () ;}# public static string MainFormTitle = ""; // The title of the notification window is public static string MainFormContent = ""; // The text content of the notification window MainForm InformWindow = new MainForm (); // instantiate an object of the MainForm class # endregion private void informButton_Click (object sender, EventArgs e) {MainForm. iconFlickerFlag = true; // set the icon to flash and identify InformWindow. iconFlicker (); // call the blinking icon method} private void closeInform_Click (object sender, EventArgs e) {InformWindow. closeNewWindow (); // close the newly displayed form} private void title_TextChanged (object sender, EventArgs e) {MainFormTitle = title. text; // record the notification title} private void content_TextChanged (object sender, EventArgs e) {MainFormContent = content. text; // record the notification content }}}
// MainForm Form code namespace _ 034_TaskMessageWindow {public partial class MainForm: Form {public MainForm () {InitializeComponent (); // enable the display Prompt window timer displayCounter. start (); // initialize the workspace size System. drawing. rectangle rect = System. windows. forms. screen. getWorkingArea (this); // instantiate an object in the current window this. rect = new System. drawing. rectangle (rect. right-this. width-1, rect. bottom-this. height-1, this. width, this. height ); // Create a work area for the instantiated object} # The variable public static int SW_SHOWNOACTIVATE = 4 declared by region; // This variable determines the form display mode public static int CurrentState; // This variable identifies the current window state public static bool MainFormFlag = true; private System. drawing. rectangle Rect; // defines the region private FormState InfoStyle = FormState where a Rectangle is stored. hide; // defines the variable to Hide public static bool MouseState; // This variable identifies the current mouse state bool IconFlag = true; // identifies the icon to flash public static bool IconFlickerFlag; // use this identifier Avoid the message box # endregion # region declares the API function [DllImportAttribute ("user32.dll")] private static extern Boolean ShowWindow (IntPtr hwnd, Int32 cmdShow) When you click the close button ); // This method is used to Display the form # endregion # region defines the enumerated value protected enum FormState that identifies the form movement status {// Hide the form Hide = 0, // Display the form Display = 1, // hide ing = 3 in the form, // Display Displaying = 4 in the form, }# endregion # region mouse controls image changes private void picturebox#mouseenter (object sender, EventArgs e ){ PictureBox1.Image = imageList1.Images [1]; // sets the image of the PictureBox control when the mouse enters the PictureBox control} private void representation (object sender, EventArgs e) {pictureBox1.Image = imageList1.Images [0] // set the image of the PictureBox control when the mouse leaves the PictureBox control} # endregion # region uses the attribute to identify the current status protected FormState FormNowState {get {return this. infoStyle;} // returns the current state set {this. infoStyle = value;} // set the current status of the form} # endregion # regi Show the form public void ShowNewWindow () {switch (FormNowState) // judge the status of the current form {case FormState. hide: // this. formNowState = FormState. displaying; // set the status of the prompt form to display this. setBounds (Rect. x, Rect. Y + Rect. height, Rect. width, 0); // display the prompt form and place it in the ShowWindow (this. handle, 4); // display the form displayCounter. interval = 100; // set the frequency of time events to Ms one displayCounter. start (); // Start the timer displayCounter break; case FormStat E. display: // displayCounter when the status of the prompt form is displayed. stop (); // Stop the timer displayCounter. interval = 5000; // set the time event frequency to Ms once displayCounter. start (); // Start the timer displayCounter break;} taskBarIcon. icon = Properties. resources. _ 1; // set the tray icon} # endregion # region close the form public void CloseNewWindow () {base. hide (); // Hide the form iconCounter. enabled = false; // set the timer iconCounter to disable taskBarIcon. icon = Properties. resources. _ 2; // Set the tray icon MainForm. iconFlickerFlag = false; // change the IconFlickerFlag value of the static variable} # endregion private void picturebox#click (object sender, EventArgs e) {this. hide (); // Hide the form iconCounter. enabled = false; // set the timer iconCounter to disable CloseNewWindow (); // call the close form method} # The icon in the region taskbar flashes private void iconCounter_Tick (object sender, EventArgs e) {if (IconFlag) // when the value is true {taskBarIcon. icon = Properties. resources. _ 1; // set the tray Control TaskBarIcon IconFlag = false; // modify this value to false} else // when this value is false {taskBarIcon. icon = Properties. resources. _ 2; // set IconFlag = true for the taskBarIcon of the tray control; // modify the value to true} # endregion public void IconFlicker () // custom method used to make the tray icon flash {if (MainForm. iconFlickerFlag! = False) // when the tray flashing icon is true {taskBarIcon. icon = Properties. resources. _ 1; // The tray icon is displayed as the image iconCounter. enabled = true; // enable the Timer titleInform of the tray icon. text = TaskMessageWindow. mainFormTitle; // display the notification title contentInform in titleInform. text = TaskMessageWindow. mainFormContent; // display notification content in cententInform} // display private void taskBarIcon_MouseDoubleClick (object sender, MouseEventArgs e) {iconCounter in the control form. enabled = false; // stop the blinking tray chart Standard timer taskBarIcon. icon = Properties. resources. _ 2; // clear the original image ShowNewWindow () in the tray; // call the display form method} // display the form private void displayCounter_Tick (object sender, EventArgs e) in the lower right corner) {switch (this. formNowState) // judge the status of the current form {case FormState. display: // this. displayCounter. start (); // Start the timer displayCounter this. displayCounter. interval = 100; // set the timer time event Interval if (! MouseState) // {this. formNowState = FormState. hiding; // hide the current form} this. displayCounter. start (); // Start the timer displayCounter break; case FormState. displaying: // if (this. height <= this. rect. height-12) // if the form is not fully displayed {this. setBounds (Rect. x, this. top-12, Rect. width, this. height + 12); // set the boundary of the form} else // {displayCounter when the form is fully displayed. stop (); // Stop the timer displayCounter this. setBounds (Rect. x, Rect. y, Rect. width, Rect. height); // set the border of the current form this. formNowState = FormState. display; // modify the status value of the current form. this. displayCounter. interval = 5000; // set the timer time event Interval this. displayCounter. start (); // Start the timer with a low displayCounter} break; case FormState. hiding: // if (MouseState) when the form is hidden // {this. formNowState = FormState. displaying; // modify the form status to display} else // when the mouse leaves the FORM {if (this. top <= this. rect. bottom-12) // when the form is not completely hidden {this. setBounds (Rect. x, this. top + 12, Rect. width, this. height-12); // set the control boundary} else // when the form is completely hidden {this. hide (); // Hide the current form this. formNowState = FormState. hide; // set the current form status} break;} private void MainForm_MouseEnter (object sender, EventArgs e) {MouseState = true; // set the value of the bool type variable MouseState to true} private void MainForm_MouseLeave (object sender, EventArgs e) {MouseState = false; // set the value of the bool type variable MouseState to false }}}

035 animated Program Interface

Microsoft Animation Control 6.0 (SP4) is mainly used. Therefore, you need to add this component to the toolbox from the toolbox "select item" and then add the component from the toolbox to the form.

: Because the AxAnimation class is used, you must add a reference to the WMPLib namespace.

Create a project. The default form is Form1. Add the Panel Control on the form to display the image, and add the Microsoft Animation Control 6.0 (SP4) component to play the Animation.

using WMPLib;namespace _035_LeadWindows{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void Form1_Load(object sender, EventArgs e)        {            axAnimation1.Open("Electron.avi");            axAnimation2.Open("zybiao.avi");            axAnimation3.Open("gd.avi");        }    }}

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.