Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add tooltips to programmatically created controls

Tags:

c#

tooltip

I have a bunch of buttons created on a winforms c# app. I have created them using the following code

int s = 0;//28 buttons
        ButtonNameArray barray = new ButtonNameArray();
        frontPanelButtons fpb = new frontPanelButtons();
        int xLoc = fpb.xLoc(fpb);
        int yLoc = fpb.yLoc(fpb);
        for (int i = 0; i < 7; i++)
        {
            for (int j = 0; j < 4; j++)
            {
                Button btn = new Button();
                btn.Name = barray.getName(btn.Name, s);
                btn.Text = barray.getText(btn.Text, s);
                btn.Width = fpb.btnWide(fpb);
                btn.Height = fpb.btnHigh(fpb);
                btn.Location = new System.Drawing.Point(xLoc, yLoc);
                Controls.Add(btn);
                xLoc += 100;
                s++;
            }
            yLoc += 31;
            xLoc = fpb.xLoc(fpb);
        }

And I would like to add a unique tooltip to each button but can't figure out how to do it. Could anyone please supply help/the answer? Many thanks.

like image 891
user995689 Avatar asked Oct 14 '11 15:10

user995689


People also ask

What is ToolTip control?

A tooltip control can be either active or inactive. When it is active, the tooltip text appears when the mouse pointer is on a tool. When it is inactive, the tooltip text does not appear, even if the pointer is on a tool. The TTM_ACTIVATE message activates and deactivates a tooltip control.


1 Answers

//...
ToolTip ttip = new ToolTip();
for (int i = 0; i < 7; i++) {
    for (int j = 0; j < 4; j++) {
        Button btn = new Button();
        // ...
        ttip.SetToolTip(btn, "Some text on my tooltip.");
    }
}
//...
like image 164
Otiel Avatar answered Nov 11 '22 13:11

Otiel