Per Erik Strandberg /cv /kurser /blog

I've used tool tips (see English Wikipedia on tooltips: [1]) many times, but never written a minimal test for it - so here is one :) See also Csharp Override Tool Tip Test, Csharp Data Grid View And Tool Tip Test and Csharp Custom Tool Tip.

The important part is a System.Windows.Forms.ToolTip and configuring it on a specific component with this.tt.SetToolTip(this.btnExit, "Press to exit.");

By adding this.tt.IsBalloon = true; the style of the tool tip is more like a ballon.

Two screenshots here:
http://www.pererikstrandberg.se/blog/tooltip-ballon.png http://www.pererikstrandberg.se/blog/tooltip-not-ballon.png

The source code modified into one big file from Microsoft Visual Studio

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ToolTipTester
{
    public class Csharp Tool Tip Test: Form
    {
        public ToolTipTester()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (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.components = new System.ComponentModel.Container();
            this.tt = new System.Windows.Forms.ToolTip(this.components);
            this.btnExit = new System.Windows.Forms.Button();
            this.SuspendLayout();
            //
            // tt
            //
            this.tt.IsBalloon = false;
            //
            // btnExit
            //
            this.btnExit.Location = new System.Drawing.Point(50, 50);
            this.btnExit.Name = "btnExit";
            this.btnExit.TabIndex = 0;
            this.btnExit.Text = "Exit";
            this.tt.SetToolTip(this.btnExit, "Press to exit.");
            this.btnExit.UseVisualStyleBackColor = true;
            this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
            //
            // ToolTipTester
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(200, 100);
            this.Controls.Add(this.btnExit);
            this.Name = "ToolTipTester";
            this.Text = "ToolTipTester";
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.ToolTip tt;
        private System.Windows.Forms.Button btnExit;
    }

    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new ToolTipTester());
        }
    }

}

Download here [2]


This page belongs to Kategori Programmering.