Personalized message in Form Design

Source: Internet
Author: User
1. Add an icon to the prompt box

In developmentProgramTo familiarize users with the operation, some prompt boxes are frequently used to display the prompt information. By default, the prompt box contains only the prompt information, which is not monotonous. If an icon is displayed in the prompt box, the program may have a different style. This example allows you to add a graph in the prompt box.

Technical Points
To modify the style of the prompt box, you must first understand the design principle of the prompt box in C. In C #, the prompt box is implemented using the tooltip control. The tooltipicon attribute of the tooltip control can be used to set the image displayed when a prompt is displayed. The following describes this attribute in detail.

The tooltip. tooltipicon attribute is used to obtain or set a value that defines the type of the icon to be displayed next to the tooltip text.

Attribute Value: one of the enumerated values of system. Windows. Forms. tooltipicon.

Implementation Process

(1) create a project. The default form is form1.
(2) Add three label controls in the form1 window to display text.
(3) Add a tooltip control on the form to display the prompt content and style.
(4) Main ProgramCode.
.Private VoidForm1_load (ObjectSender, eventargs E)
{
Tooltip1.settooltip (label1,"Life motto");
Tooltip1.settooltip (label2,"Life motto");
}

Summary:

The following functions can be implemented based on the instance.
1. Customize the prompt box.
2. Create a bubble style prompt box.

Ii. Modify the prompt font and color
 
If you have set the tooltip attribute of the control, when you move the mouse over the control, the relevant text is displayed, but the setting attribute of the prompt font and color is not provided, how can I change the style and font of the prompt text? In this example, you can set the font and color of the prompt text.

Technical Points
The tooltip control is provided in C #. You can specify the associated control and provide prompt text for each control. The tooltiptitle attribute specifies the text in the text prompt box. The following describes the relevant attributes and methods.
(1) settooltip Method

Associate the tooltip text with the specified control. The syntax structure is as follows:

Public void settooltip (Control, string Caption)

Parameters are described as follows:
Control: the control associated with the tooltip text.
Caption: The tooltip text to be displayed when the pointer is above the control.

(2) tooltip. tooltiptitle attributes

Obtain or set the title of the tooltip window. The syntax structure is as follows:

Public String tooltiptitle {Get; set ;}

Property Value: string containing the window title. The title is displayed as a bold line in the window above the standard tooltip control description text. Generally, the title is only used to differentiate controls of different types on the form, or as an introduction to long controls.

Implementation Process

(1) create a project. The default form is form1.
(2) Add a button control on the form1 form to display the prompt text above it; add a tooltip control to design the prompt text.
(3) Main program code.
Set the prompt text and the associated control of the prompt text. The specific code is as follows:
Private Void Form1_load ( Object Sender, eventargs E)
{
This . Tooltip1.ownerdraw = True ;
This . Tooltip1.settooltip ( This . Button1, " Set the font and color of the prompt " );
This . Tooltip1.draw + = New Drawtooltipeventhandler (tooltip1_draw );
}

Set the text prompt style. The Code is as follows:
Void Tooltip1_draw ( Object Sender, drawtooltipeventargs E)
{
// Throw new exception ("the method or operation is not implemented .");
E. drawbackground ();
E. drawborder ();
Using (Stringformat Sf = New Stringformat ())
{
SF. Alignment = stringalignment. Center;
SF. linealignment = stringalignment. Center;
SF. hotkeyprefix = system. Drawing. Text. hotkeyprefix. None;
SF. formatflags = stringformatflags. nowrap;
Using (Font F = New Font ( " " , 12 ))
{
E. Graphics. drawstring (E. tooltiptext, F,
Systembrushes. activecaptiontext, E. bounds, SF );
}
}
}

Summary:

The following functions can be implemented based on the instance.
1. Modify the style of any control prompt text.
2. Add a prompt sound to the prompt.

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.