Silverlight: the form adjustment, maximization, minimization, and closure buttons of the Silverlight desktop program

Source: Internet
Author: User

Overview

ApplicationMember
Encapsulate Silverlight applicationsProgram.

Application. CurrentAttribute
Obtain the Application Object of the current application.

Window. dragresizeMethod
In a trusted application, start dragging the mouse to move the edge or corner of the specified window.
You can use this method to drag the edge and corner of a window when hiding the border.

Window. dragmoveMethod
In a trusted application, start dragging the mouse to move the window.
You can use this method to drag the edge and corner of a window when hiding the title bar of a window.

Window. CloseMethod
Close the application window unless the closing event is canceled.
Use this method to provide an alternative window "close" button. This is especially useful in trusted applications when hiding the window title bar and border.

Window. windowstateAttribute
Gets or sets a value that indicates whether the window is in the maximization, minimization, or normal state.
Use this property to provide the optional window "minimize" and "maximize" buttons. This is especially useful in trusted applications when hiding the window title bar and border.

WindowstateEnumeration
Defines constants that indicate the status of the application window outside the browser.

Normal The application window is in normal state, and the size of the screen space occupied by it depends on its window. Height and window. width values.
MinimizedThe application window is minimized to the taskbar.
MaximizedThe application window is maximized, occupying the entire Workspace of the screen.

Effect

XAMLCode

< Grid X: Name = "Layoutroot"
Background = "Orange" >
<! -- You can freely drag the title -->
< Grid X: Name = "Titlebar"
Background = "Blue"
Height = "30"
Verticalalignment = "TOP" />

freely stretch a form -->
grid X: name = "resizearea"
background =" blue "
height =" 30 "
width =" 30 "
verticalalignment =" bottom "
horizontalalignment =" right " />

< Stackpanel Orientation = "Horizontal"
Horizontalalignment = "Right"
Verticalalignment = "TOP"
Margin = "8" >
<! -- Minimization button -->
< Button X: Name = "Minimizebutton"
Width = "15"
Height = "15" />
<! -- Maximize button -->
< Button X: Name = "Maximizebutton"
Width = "15"
Height = "15" />
<! -- Close button -->
< Button X: Name = "Closebutton"
Width = "15"
Height = "15" />
</ Stackpanel >
</ Grid >

CS code

Public Mainpage ()
{
Initializecomponent ();
// Maximize button click event
Maximizebutton. Click + = New Routedeventhandler (maximizebutton_click );
// Minimize button click event
Minimizebutton. Click + = New Routedeventhandler (minimizebutton_click );
// Close button click event
Closebutton. Click + = New Routedeventhandler (closebutton_click );

//Press the left mouse button on the title bar
Titlebar. mouseleftbuttondown+ = NewMousebuttoneventhandler (titlebar_mouseleftbuttondown );
//Adjust the range and press the left mouse button
Resizearea. mouseleftbuttondown+ = NewMousebuttoneventhandler (resizearea_mouseleftbuttondown );

}

void resizearea_mouseleftbuttondown ( Object sender, mousebuttoneventargs e)
{< br> /// application member
// encapsulation s Ilverlight application.
// application. current attributes
// get the application object of the current application.

// window. dragresize method
/// In a trusted application, start dragging the mouse to move the edge or corner of the specified window.
// you can use this method to drag the edge and corner of a window when hiding the border.
application. current. mainwindow. dragresize (windowresizeedge. bottomright);
}

void titlebar_mouseleftbuttondown ( Object sender, mousebuttoneventargs e)
{< br> /// window. dragmove method
/// in In a trusted application, start dragging the mouse to move the window.
// you can use this method to drag the edge and corner of a window when hiding the title bar of a window.
application. current. mainwindow. dragmove ();
}

void closebutton_click ( Object sender, routedeventargs e)
{< br> /// window. close method
// close unless the closing event is canceled Application Window.
// use this method to provide an alternative window" close "button. This is especially useful in trusted applications when hiding the window title bar and border.
application. current. mainwindow. close ();
}

VoidMinimizebutton_click (ObjectSender, routedeventargs E)
{
//Window. windowstate Properties
//Gets or sets a value that indicates whether the window is in the maximization, minimization, or normal state.
//Use this property to provide the optional window "minimize" and "maximize" buttons. This is especially useful in trusted applications when hiding the window title bar and border.

//Windowstate Enumeration
//Defines constants that indicate the status of the application window outside the browser.

// the normal application window is in the normal state, and the size of the screen space occupied by it depends on its window. height and window. width value.
// the mini-mized application window is minimized to the taskbar.
// the maximized application window is maximized, occupying the entire Workspace of the screen.
application. current. mainwindow. windowstate = windowstate. minimized;
}

VoidMaximizebutton_click (ObjectSender, routedeventargs E)
{
Application. Current. mainwindow. windowstate=
Application. Current. mainwindow. windowstate=
Windowstate. maximized?Windowstate. Normal: windowstate. maximized;
}
}

Success !!!

author: memories of lost youth
Source: http://www.cnblogs.com/lukun/
the copyright of this article is shared by the author and the blog. You are welcome to reprint it, but you must keep this statement without the consent of the author, the Article page clearly shows the original connection. If there is any problem, you can use http://www.cnblogs.com/lukun/ contact me, thank you very much.

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.