Csharp/C Sharp/GUI Windows Form/Tooltips — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 15:31, 26 мая 2010
Содержание
Add icon to Tooltip
using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form
{
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.ToolTip toolTip1;
private System.Windows.Forms.ToolTip toolTip2;
private System.Windows.Forms.PictureBox pictureBox2;
public Form1() {
InitializeComponent();
}
private void InitializeComponent()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.toolTip1 = new System.Windows.Forms.ToolTip(new System.ruponentModel.Container());
this.toolTip2 = new System.Windows.Forms.ToolTip(new System.ruponentModel.Container());
this.pictureBox2 = new System.Windows.Forms.PictureBox();
((System.ruponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ruponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox1.Location = new System.Drawing.Point(12, 24);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(100, 50);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.toolTip1.SetToolTip(this.pictureBox1, "This is a tooltip.");
//
// toolTip1
//
this.toolTip1.ToolTipIcon = System.Windows.Forms.ToolTipIcon.Info;
this.toolTip1.ToolTipTitle = "Titled ToolTip";
//
// pictureBox2
//
this.pictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox2.Location = new System.Drawing.Point(148, 24);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(100, 50);
this.pictureBox2.TabIndex = 1;
this.pictureBox2.TabStop = false;
this.toolTip2.SetToolTip(this.pictureBox2, "This is a tooltip.");
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(279, 107);
this.Controls.Add(this.pictureBox2);
this.Controls.Add(this.pictureBox1);
this.Name = "Form1";
this.Text = "ToolTip Test";
((System.ruponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ruponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
this.ResumeLayout(false);
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}
Add Tooltips for Label
using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form
{
private System.Windows.Forms.Label firstLabel;
private System.Windows.Forms.Label secondLabel;
private System.Windows.Forms.ToolTip labelsToolTip;
public Form1() {
InitializeComponent();
}
private void InitializeComponent()
{
this.firstLabel = new System.Windows.Forms.Label();
this.secondLabel = new System.Windows.Forms.Label();
this.labelsToolTip = new System.Windows.Forms.ToolTip(new System.ruponentModel.Container());
this.SuspendLayout();
//
// firstLabel
//
this.firstLabel.AutoSize = true;
this.firstLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.firstLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.firstLabel.Location = new System.Drawing.Point(12, 20);
this.firstLabel.Name = "firstLabel";
this.firstLabel.Size = new System.Drawing.Size(92, 18);
this.firstLabel.TabIndex = 0;
this.firstLabel.Text = "This is a label.";
this.labelsToolTip.SetToolTip(this.firstLabel, "First Label");
//
// secondLabel
//
this.secondLabel.AutoSize = true;
this.secondLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.secondLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.secondLabel.Location = new System.Drawing.Point(12, 69);
this.secondLabel.Name = "secondLabel";
this.secondLabel.Size = new System.Drawing.Size(133, 18);
this.secondLabel.TabIndex = 1;
this.secondLabel.Tag = "";
this.secondLabel.Text = "This is another Label.";
this.labelsToolTip.SetToolTip(this.secondLabel, "Second Label");
//
// ToolTipExampleForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(252, 124);
this.Controls.Add(this.secondLabel);
this.Controls.Add(this.firstLabel);
this.Name = "ToolTipExampleForm";
this.Text = "ToolTip Demonstration";
this.ResumeLayout(false);
this.PerformLayout();
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}
Add Tooltip to a component
using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form
{
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.ToolTip toolTip1;
private System.Windows.Forms.ToolTip toolTip2;
private System.Windows.Forms.PictureBox pictureBox2;
public Form1() {
InitializeComponent();
}
private void InitializeComponent()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.toolTip1 = new System.Windows.Forms.ToolTip(new System.ruponentModel.Container());
this.toolTip2 = new System.Windows.Forms.ToolTip(new System.ruponentModel.Container());
this.pictureBox2 = new System.Windows.Forms.PictureBox();
((System.ruponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ruponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox1.Location = new System.Drawing.Point(12, 24);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(100, 50);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.toolTip1.SetToolTip(this.pictureBox1, "This is a tooltip.");
//
// toolTip1
//
this.toolTip1.ToolTipIcon = System.Windows.Forms.ToolTipIcon.Info;
this.toolTip1.ToolTipTitle = "Titled ToolTip";
//
// pictureBox2
//
this.pictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox2.Location = new System.Drawing.Point(148, 24);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(100, 50);
this.pictureBox2.TabIndex = 1;
this.pictureBox2.TabStop = false;
this.toolTip2.SetToolTip(this.pictureBox2, "This is a tooltip.");
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(279, 107);
this.Controls.Add(this.pictureBox2);
this.Controls.Add(this.pictureBox1);
this.Name = "Form1";
this.Text = "ToolTip Test";
((System.ruponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ruponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
this.ResumeLayout(false);
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}
Tooltips Demo
/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury,
Zach Greenvoss, Shripad Kulkarni, Neil Whitlow
Publisher: Peer Information
ISBN: 1861007663
*/
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
namespace Tooltips
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Tooltips : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnTooltips;
private System.Windows.Forms.TextBox txtTooltip;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ruponentModel.Container components = null;
public Tooltips()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
ToolTip forButton = new ToolTip();
forButton.SetToolTip(btnTooltips, "You are now over the button!!");
forButton.SetToolTip(txtTooltip, "You are now over the textbox!!");
forButton.AutomaticDelay = 2000;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnTooltips = new System.Windows.Forms.Button();
this.txtTooltip = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// btnTooltips
//
this.btnTooltips.Location = new System.Drawing.Point(0, 152);
this.btnTooltips.Name = "btnTooltips";
this.btnTooltips.Size = new System.Drawing.Size(288, 104);
this.btnTooltips.TabIndex = 0;
this.btnTooltips.Text = "Press Me";
//
// txtTooltip
//
this.txtTooltip.Location = new System.Drawing.Point(0, 8);
this.txtTooltip.Multiline = true;
this.txtTooltip.Name = "txtTooltip";
this.txtTooltip.Size = new System.Drawing.Size(288, 136);
this.txtTooltip.TabIndex = 1;
this.txtTooltip.Text = "";
//
// Tooltips
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.txtTooltip,
this.btnTooltips});
this.Name = "Tooltips";
this.Text = "Tooltips";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Tooltips());
}
}
}
Tooltips for Button
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class Tooltips : System.Windows.Forms.Form {
private System.Windows.Forms.Button btnTooltips;
private System.Windows.Forms.TextBox txtTooltip;
public Tooltips() {
ToolTip forButton = new ToolTip();
forButton.SetToolTip(btnTooltips, "You are now over the button!!");
forButton.SetToolTip(txtTooltip, "You are now over the textbox!!");
forButton.AutomaticDelay = 2000;
this.btnTooltips = new System.Windows.Forms.Button();
this.txtTooltip = new System.Windows.Forms.TextBox();
this.SuspendLayout();
this.btnTooltips.Location = new System.Drawing.Point(0, 152);
this.btnTooltips.Size = new System.Drawing.Size(288, 104);
this.btnTooltips.Text = "Press Me";
this.txtTooltip.Location = new System.Drawing.Point(0, 8);
this.txtTooltip.Multiline = true;
this.txtTooltip.Size = new System.Drawing.Size(288, 136);
this.txtTooltip.Text = "";
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.txtTooltip,
this.btnTooltips});
this.ResumeLayout(false);
}
[STAThread]
static void Main() {
Application.Run(new Tooltips());
}
}