鼠标光标触摸时如何更改标签关闭标记“X”颜色?

时间:2016-03-13 15:16:04

标签: c# winforms

我有一个包含多个页面的TabControl。每个页面在选项卡上都有一个关闭标记“X”。我希望当鼠标光标触摸(区域内)“X”时,“X”颜色变为白色,以便提醒我们该区域内的光标。代码如下:

private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
    {
        //This code will render a "x" mark at the end of the Tab caption. 
        e.Graphics.DrawString("X", e.Font, Brushes.Red, e.Bounds.Right - 20, e.Bounds.Top + 4);
        e.Graphics.DrawString(this.tabControl1.TabPages[e.Index].Text, e.Font, Brushes.Black, e.Bounds.Left + 24, e.Bounds.Top + 4);
        e.Graphics.DrawImage(Properties.Resources.Div1, new Point(e.Bounds.Left, e.Bounds.Top + 2));
        e.DrawFocusRectangle();
    }

    private void tabControl1_MouseMove(object sender, MouseEventArgs e)
    {
        Rectangle r = tabControl1.GetTabRect(tabControl1.SelectedIndex);
        //Getting the position of the "x" mark.
        Rectangle closeButton = new Rectangle(r.Right - 20, r.Top + 4, 20, 10);
        if (closeButton.Contains(e.Location))
        {
            //how to write here to change tab caption color or close mark "X" color
        }
    }

0 个答案:

没有答案
相关问题