Display text prompts using WPF

Source: Internet
Author: User

This article describes how a WPF application can display one or more lines of text notifications on the screen. It does not have buttons such as the title bar and the maximization button. It can have a translucent background to make the text display clearer. The prompt disappears after you click the mouse.

1. Create a New WPF Application.

2. set the WindowStyle attribute of Window to "None" to remove the title bar, set the AllowsTransparency attribute to "True" to allow transparency, and set the Topmost attribute to "True" to display the prompt text on the top layer, set the Background attribute to "#00000000" to make the window transparent.

3. Set the Background attribute of the Grid. If a black text prompt is displayed, you can use a translucent white background. If the Opacity attribute produces transparent effects, other elements in the container will also have transparent effects. The simple method is to set the transparency through the first two digits of the Background attribute.

4. Add a processing method for the MouseLeave, MouseDown, and MouseEnter events of the Window. You can add the MouseEnter and MouseLeave events to increase the background transparency when you move the cursor into the prompt area, and reduce the background transparency when you draw the prompt area. The Processing Method of the MouseDown event allows you to click the prompt area and cancel the prompt.

1 /// <summary>

2 // how to move the mouse

3 /// </summary>

4 /// <param name = "sender"> </param>

5 /// <param name = "e"> </param>

6 private void Window_MouseEnter (object

Sender, MouseEventArgs e)

7 {

8 Brush brush = new SolidColorBrush (Color. FromArgb (0x78, 0xFF, 0xFF, 0xFF); // create a solid Color brush

9 grid. Background = brush; // apply to grid

10}

11

12 /// <summary>

13 ///

How to remove mouse

14 /// </summary>

15 /// <param name = "sender"> </param>

16 /// <param name = "e"> </param>

17 private void Window_MouseLeave (object

Sender, MouseEventArgs e)

18 {

19 Brush brush = new SolidColorBrush (Color. FromArgb (0x52, 0xFF, 0xFF, 0xFF); // create a solid Color brush

20 grid. Background = brush; // apply to grid

21}

22

23 /// <summary>

24 ///

How to handle mouse clicks

25 /// </summary>

26 /// <param name = "sender"> </param>

27 /// <param name = "e"> </param>

28 private void Window_MouseDown (object

Sender, MouseButtonEventArgs e)

29 {

30 mainWindow. Close (); // or use mainWindow. Hide () to Hide the window

31}
 

 

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.