VB.Net Tutorial/GUI/Tooltips — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 19:40, 26 мая 2010
Add ToolTip to TextBox
<source lang="vbnet">Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class AddToolTipToTextBox
public Shared Sub Main Application.Run(New Form1) End Sub
End class Public Class Form1
Inherits System.Windows.Forms.Form
- Region " Windows Form Designer generated code "
Public Sub New() MyBase.New() "This call is required by the Windows Form Designer. InitializeComponent() "Add any initialization after the InitializeComponent() call End Sub "Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub "Required by the Windows Form Designer Private components As System.ruponentModel.IContainer "NOTE: The following procedure is required by the Windows Form Designer "It can be modified using the Windows Form Designer. "Do not modify it using the code editor. Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip Friend WithEvents TextBox1 As System.Windows.Forms.TextBox <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.ruponents = New System.ruponentModel.Container Me.Label1 = New System.Windows.Forms.Label Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.ruponents) Me.TextBox1 = New System.Windows.Forms.TextBox Me.SuspendLayout() " "TextBox1 " Me.TextBox1.Location = New System.Drawing.Point(96, 120) Me.TextBox1.Name = "TextBox1" Me.TextBox1.TabIndex = 1 Me.TextBox1.Text = "" " "Form1 " Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 273) Me.Controls.Add(Me.TextBox1) Me.Controls.Add(Me.Label1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub
- End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ToolTip1.SetToolTip(TextBox1, "This is a text box.") End Sub
End Class</source>
Add ToolTip to TextBox and ComboBox
<source lang="vbnet">Imports System.Windows.Forms
public class SetToolTipForTextBoxAndComboBox
public Shared Sub Main Application.Run(New Form1) End Sub
End class Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ttHint.SetToolTip(txtFirstName, "first name") ttHint.SetToolTip(txtLastName, "last name") ttHint.SetToolTip(txtStreet, "address street number and name") ttHint.SetToolTip(txtCity, "city") ttHint.SetToolTip(cboState, "state") ttHint.SetToolTip(txtZip, "ZIP code") End Sub
End Class <Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Public Class Form1
Inherits System.Windows.Forms.Form "Form overrides dispose to clean up the component list. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing AndAlso components IsNot Nothing Then components.Dispose() End If MyBase.Dispose(disposing) End Sub "Required by the Windows Form Designer Private components As System.ruponentModel.IContainer "NOTE: The following procedure is required by the Windows Form Designer "It can be modified using the Windows Form Designer. "Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.ruponents = New System.ruponentModel.Container Me.ttHint = New System.Windows.Forms.ToolTip(Me.ruponents) Me.TableLayoutPanel1 = New System.Windows.Forms.TableLayoutPanel Me.Label1 = New System.Windows.Forms.Label Me.Label7 = New System.Windows.Forms.Label Me.Label2 = New System.Windows.Forms.Label Me.txtFirstName = New System.Windows.Forms.TextBox Me.txtLastName = New System.Windows.Forms.TextBox Me.txtStreet = New System.Windows.Forms.TextBox Me.Label3 = New System.Windows.Forms.Label Me.txtCity = New System.Windows.Forms.TextBox Me.txtZip = New System.Windows.Forms.TextBox Me.Label5 = New System.Windows.Forms.Label Me.Label8 = New System.Windows.Forms.Label Me.Label6 = New System.Windows.Forms.Label Me.cboState = New System.Windows.Forms.ruboBox Me.TableLayoutPanel1.SuspendLayout() Me.SuspendLayout() " "TableLayoutPanel1 " Me.TableLayoutPanel1.AutoSize = True Me.TableLayoutPanel1.ColumnCount = 2 Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 80.0!)) Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 136.0!)) Me.TableLayoutPanel1.Controls.Add(Me.Label1, 0, 0) Me.TableLayoutPanel1.Controls.Add(Me.Label7, 0, 1) Me.TableLayoutPanel1.Controls.Add(Me.Label2, 0, 2) Me.TableLayoutPanel1.Controls.Add(Me.txtFirstName, 1, 1) Me.TableLayoutPanel1.Controls.Add(Me.txtLastName, 1, 2) Me.TableLayoutPanel1.Controls.Add(Me.txtStreet, 1, 3) Me.TableLayoutPanel1.Controls.Add(Me.Label3, 0, 3) Me.TableLayoutPanel1.Controls.Add(Me.txtCity, 1, 4) Me.TableLayoutPanel1.Controls.Add(Me.txtZip, 1, 6) Me.TableLayoutPanel1.Controls.Add(Me.Label5, 0, 5) Me.TableLayoutPanel1.Controls.Add(Me.Label8, 0, 4) Me.TableLayoutPanel1.Controls.Add(Me.Label6, 0, 6) Me.TableLayoutPanel1.Controls.Add(Me.cboState, 1, 5) Me.TableLayoutPanel1.Location = New System.Drawing.Point(7, 7) Me.TableLayoutPanel1.Name = "TableLayoutPanel1" Me.TableLayoutPanel1.RowCount = 7 Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle) Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle) Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle) Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle) Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle) Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle) Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle) Me.TableLayoutPanel1.Size = New System.Drawing.Size(272, 182) Me.TableLayoutPanel1.TabIndex = 1 " "Label1 " Me.Label1.Anchor = System.Windows.Forms.AnchorStyles.None Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D Me.TableLayoutPanel1.SetColumnSpan(Me.Label1, 2) Me.Label1.Location = New System.Drawing.Point(36, 0) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(200, 20) Me.Label1.TabIndex = 37 Me.Label1.Text = "Employee" Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter " "Label7 " Me.Label7.Anchor = System.Windows.Forms.AnchorStyles.None Me.Label7.AutoSize = True Me.Label7.Location = New System.Drawing.Point(13, 26) Me.Label7.Name = "Label7" Me.Label7.Size = New System.Drawing.Size(53, 13) Me.Label7.TabIndex = 38 Me.Label7.Text = "First Name" " "Label2 " Me.Label2.Anchor = System.Windows.Forms.AnchorStyles.None Me.Label2.AutoSize = True Me.Label2.Location = New System.Drawing.Point(13, 52) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(54, 13) Me.Label2.TabIndex = 40 Me.Label2.Text = "Last Name" " "txtFirstName " Me.txtFirstName.Anchor = CType((System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.txtFirstName.Location = New System.Drawing.Point(83, 23) Me.txtFirstName.Name = "txtFirstName" Me.txtFirstName.Size = New System.Drawing.Size(186, 20) Me.txtFirstName.TabIndex = 0 Me.ttHint.SetToolTip(Me.txtFirstName, "Enter the customer"s first (given) name.") " "txtLastName " Me.txtLastName.Anchor = CType((System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.txtLastName.Location = New System.Drawing.Point(83, 49) Me.txtLastName.Name = "txtLastName" Me.txtLastName.Size = New System.Drawing.Size(186, 20) Me.txtLastName.TabIndex = 1 Me.ttHint.SetToolTip(Me.txtLastName, "Enter the customer"s last (family) name.") " "txtStreet " Me.txtStreet.Anchor = CType((System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.txtStreet.Location = New System.Drawing.Point(83, 75) Me.txtStreet.Name = "txtStreet" Me.txtStreet.Size = New System.Drawing.Size(186, 20) Me.txtStreet.TabIndex = 2 Me.ttHint.SetToolTip(Me.txtStreet, "Enter the customer"s stree address including apartment, suite, or other informati" & _ "on.") " "Label3 " Me.Label3.Anchor = System.Windows.Forms.AnchorStyles.None Me.Label3.AutoSize = True Me.Label3.Location = New System.Drawing.Point(24, 78) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(31, 13) Me.Label3.TabIndex = 42 Me.Label3.Text = "Street" " "txtCity " Me.txtCity.Anchor = CType((System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.txtCity.Location = New System.Drawing.Point(83, 101) Me.txtCity.Name = "txtCity" Me.txtCity.Size = New System.Drawing.Size(186, 20) Me.txtCity.TabIndex = 3 Me.ttHint.SetToolTip(Me.txtCity, "Enter the customer"s city.") " "txtZip " Me.txtZip.Anchor = System.Windows.Forms.AnchorStyles.Left Me.txtZip.Location = New System.Drawing.Point(83, 156) Me.txtZip.Name = "txtZip" Me.txtZip.Size = New System.Drawing.Size(64, 20) Me.txtZip.TabIndex = 5 Me.ttHint.SetToolTip(Me.txtZip, "Enter the customer"s ZIP code.") " "Label5 " Me.Label5.Anchor = System.Windows.Forms.AnchorStyles.None Me.Label5.AutoSize = True Me.Label5.Location = New System.Drawing.Point(26, 131) Me.Label5.Name = "Label5" Me.Label5.Size = New System.Drawing.Size(28, 13) Me.Label5.TabIndex = 46 Me.Label5.Text = "State" " "Label8 " Me.Label8.Anchor = System.Windows.Forms.AnchorStyles.None Me.Label8.AutoSize = True Me.Label8.Location = New System.Drawing.Point(30, 104) Me.Label8.Name = "Label8" Me.Label8.Size = New System.Drawing.Size(20, 13) Me.Label8.TabIndex = 51 Me.Label8.Text = "City" " "Label6 " Me.Label6.Anchor = System.Windows.Forms.AnchorStyles.None Me.Label6.AutoSize = True Me.Label6.Location = New System.Drawing.Point(31, 160) Me.Label6.Name = "Label6" Me.Label6.Size = New System.Drawing.Size(18, 13) Me.Label6.TabIndex = 52 Me.Label6.Text = "Zip" " "cboState " Me.cboState.Anchor = System.Windows.Forms.AnchorStyles.Left Me.cboState.FormattingEnabled = True Me.cboState.Location = New System.Drawing.Point(83, 127) Me.cboState.Name = "cboState" Me.cboState.Size = New System.Drawing.Size(48, 21) Me.cboState.TabIndex = 54 Me.ttHint.SetToolTip(Me.cboState, "Select the customer"s state.") " "Form1 " Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(287, 197) Me.Controls.Add(Me.TableLayoutPanel1) Me.Name = "Form1" Me.Text = "UseToolTip" Me.TableLayoutPanel1.ResumeLayout(False) Me.TableLayoutPanel1.PerformLayout() Me.ResumeLayout(False) Me.PerformLayout() End Sub Friend WithEvents ttHint As System.Windows.Forms.ToolTip Friend WithEvents TableLayoutPanel1 As System.Windows.Forms.TableLayoutPanel Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents Label7 As System.Windows.Forms.Label Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents txtFirstName As System.Windows.Forms.TextBox Friend WithEvents txtLastName As System.Windows.Forms.TextBox Friend WithEvents txtStreet As System.Windows.Forms.TextBox Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents txtCity As System.Windows.Forms.TextBox Friend WithEvents txtZip As System.Windows.Forms.TextBox Friend WithEvents Label5 As System.Windows.Forms.Label Friend WithEvents Label8 As System.Windows.Forms.Label Friend WithEvents Label6 As System.Windows.Forms.Label Friend WithEvents cboState As System.Windows.Forms.ruboBox
End Class</source>
Set Tooltips for Label
<source lang="vbnet">Imports System.Windows.Forms public class FrmToolTip
public Shared Sub Main Application.Run(New FrmToolTipDemonstration) End Sub
End class <Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _ Partial Class FrmToolTipDemonstration
Inherits System.Windows.Forms.Form "Form overrides dispose to clean up the component list. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) If disposing AndAlso components IsNot Nothing Then components.Dispose() End If MyBase.Dispose(disposing) End Sub "Required by the Windows Form Designer Private components As System.ruponentModel.IContainer "NOTE: The following procedure is required by the Windows Form Designer "It can be modified using the Windows Form Designer. "Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.ruponents = New System.ruponentModel.Container Me.lblSecond = New System.Windows.Forms.Label Me.labelsToolTip = New System.Windows.Forms.ToolTip(Me.ruponents) Me.lblFirst = New System.Windows.Forms.Label Me.SuspendLayout() " "lblSecond " Me.lblSecond.AutoSize = True Me.lblSecond.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle Me.lblSecond.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblSecond.Location = New System.Drawing.Point(12, 73) Me.lblSecond.Name = "lblSecond" Me.lblSecond.Size = New System.Drawing.Size(147, 19) Me.lblSecond.TabIndex = 3 Me.lblSecond.Tag = "" Me.lblSecond.Text = "This is another Label." Me.labelsToolTip.SetToolTip(Me.lblSecond, "Second Label") " "lblFirst " Me.lblFirst.AutoSize = True Me.lblFirst.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle Me.lblFirst.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblFirst.Location = New System.Drawing.Point(12, 24) Me.lblFirst.Name = "lblFirst" Me.lblFirst.Size = New System.Drawing.Size(101, 19) Me.lblFirst.TabIndex = 2 Me.lblFirst.Text = "This is a label." Me.labelsToolTip.SetToolTip(Me.lblFirst, "First Label") " "FrmToolTipDemonstration " Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(252, 124) Me.Controls.Add(Me.lblSecond) Me.Controls.Add(Me.lblFirst) Me.Name = "FrmToolTipDemonstration" Me.Text = "ToolTip Demonstration" Me.ResumeLayout(False) Me.PerformLayout() End Sub Friend WithEvents lblSecond As System.Windows.Forms.Label Friend WithEvents labelsToolTip As System.Windows.Forms.ToolTip Friend WithEvents lblFirst As System.Windows.Forms.Label
End Class</source>