1, Example Introduction
This article uses the ToolTip control's draw event redraw to modify the font and color of the cue box. Create a WinForm project to add a button control and a ToolTip control on a form.
2. Implementation code
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Drawing;6 usingSystem.Linq;7 usingSystem.Text;8 usingSystem.Windows.Forms;9 Ten namespaceKaifafanli One { A Public Partial classForm8:form - { - PublicFORM8 () the { - InitializeComponent (); - } - + Private voidForm8_load (Objectsender, EventArgs e) - { +Tooltip1.ownerdraw =true;//indicates whether the hint text for the prompt control is drawn by the system or by the code you provide ATooltip1.showalways =true;//Total display prompt information atTooltip1.settooltip (button1,"hint Text");//Set Prompt Text - - - } - - Private voidTooltip1_draw (Objectsender, Drawtooltipeventargs e) in { - toE.graphics.fillellipse (Systembrushes.activecaption,e.bounds);//Customizing Backgrounds +E.drawborder ();//Draw Standard Boundaries - //encapsulating text Layout information the using(StringFormat sf=NewStringFormat ()) * { $sf. Alignment = Stringalignment.center;//Set Font vertical alignmentPanax Notoginsengsf. LineAlignment = Stringalignment.center;//Horizontal Alignment - using(Font f=NewFont ("Official Script", the)) the { +E.graphics.drawstring (E.TOOLTIPTEXT,F,SYSTEMBRUSHES.ACTIVECAPTIONTEXT,E.BOUNDS,SF);//Draw Text A } the + } - $ } $ } -}
View Code
3, Control Introduction
The ToolTip component of a Windows Form displays the corresponding text when the user points to the control. ToolTips can be associated with any control, the default prompt box font and color is not modifiable, to implement the font and color to modify the cue box, you need to write code implementation, the method and properties are as follows:
Tooltip.settooltip () method.
This method associates the ToolTip text with the specified control. The syntax format is as follows:
public void SetToolTip (Control control,string caption);
The meaning of the parameters is as follows:
Control: The controls that you want to associate the ToolTip text with.
Caption: Prompt text content
Modify the font and color of the cue box