作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有什么办法可以改变BackColor
面板或类似控件的边框?
当我将鼠标悬停在用户控件上时,我试图“突出显示”用户控件。
最佳答案
这是一个简单的类,它用边框突出显示表单上的控件:
public class Highlighter : Control
{
public void SetTarget(Control c)
{
Rectangle r = c.Bounds;
r.Inflate(3, 3);
Bounds = r;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.FillRectangle(Brushes.Red, e.ClipRectangle);
}
}
private void Form1_Load(object sender, EventArgs e)
{
foreach (Control c in Controls)
{
c.MouseEnter += mouseEnter;
c.MouseLeave += mouseLeave;
}
}
private void mouseEnter(object sender, EventArgs e)
{
_highlighter.SetTarget(sender as Control);
_highlighter.Visible = true;
}
private void mouseLeave(object sender, EventArgs e)
{
_highlighter.Visible = false;
}
public Form1()
{
InitializeComponent();
_highlighter = new Highlighter();
Controls.Add(_highlighter);
}
关于winforms - Windows 窗体面板边界的背景色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/767944/
我是一名优秀的程序员,十分优秀!