Implementing method of screen text hint with WPF

Source: Internet
Author: User
This article describes a WPF application implementation that displays one or more lines of text notifications on the screen.   It does not have a title bar and maximize the minimum button, you can have a translucent background to make the text display more clearly, mouse click after the prompts disappear.

1. Create a new WPF application.
2. Set the window's WindowStyle property to ' None ' to remove the title bar, set the AllowsTransparency property to ' true ' to allow transparency, and the topmost property to ' true ' to make the hint text appear at the top level. The Background property is set to #00000000 to make the window transparent.
3. Set the Background property of the grid. If you display a black text hint, you can use a semitransparent white background. A transparent effect, if produced by the Opacity property, makes the other elements within the container transparent. The simpler approach is to set the transparency by background the first two digits of the property.
4. Add the processing method to the MouseLeave, MouseDown, MouseEnter events for Windows. Adding MouseEnter and MouseLeave events is a way to deepen the background transparency when the mouse is drawn into the hint area, and to reduce the background transparency when the mouse draws the cue area. The MouseDown event's handling method causes the mouse to click the prompt area to cancel the prompt.

Copy Code code as follows:


Code


///<summary>


///Mouse Movement Method


///</summary>


///<param name= "Sender" ></param>


///<param name= "E" ></param>


private void Window_mouseenter (object sender, MouseEventArgs e)


{


Brush Brush = new SolidColorBrush (Color.FromArgb (0x78,0xff,0xff,0xff)); Create a solid color brush


grid.  Background = brush; Applied to Grid


}


///<summary>


///Mouse Removal processing method


///</summary>


///<param name= "Sender" ></param>


///<param name= "E" ></param>


private void Window_mouseleave (object sender, MouseEventArgs e)


{


Brush Brush = new SolidColorBrush (Color.FromArgb (0x52, 0xFF, 0xFF, 0xFF)); Create a solid color brush


grid.  Background = brush; Applied to Grid


}


///<summary>


///mouse Down processing method


///</summary>


///<param name= "Sender" ></param>


///<param name= "E" ></param>


private void Window_mousedown (object sender, MouseButtonEventArgs e)


{


Mainwindow.close (); or use Mainwindow.hide () to hide the window


}


This article applies to the. NET Framework 4

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.