【问题标题】:Draw system focus rectangle c#绘制系统焦点矩形c#
【发布时间】:2013-07-07 08:59:44
【问题描述】:

如何使用 gdi、C# 绘制系统焦点矩形?我主要对 Windows 7 上常见的 listview 控件中的玻璃效果焦点矩形感兴趣。提前致谢。

【问题讨论】:

标签: c# .net winforms user-controls gdi


【解决方案1】:

我使用Panel 将其视为ListViewItem 并在此面板上绘图以演示应该做什么,它看起来几乎就像Windows 7 中使用的ListView 中的焦点条目。

private void panel1_Paint(object sender, PaintEventArgs e)
    {            
        using (System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(panel1.ClientRectangle, Color.FromArgb(100, 204, 222,246), Color.FromArgb(190,220,255) , 90))
        {
            e.Graphics.FillRectangle(brush,new Rectangle(2,2,panel1.ClientSize.Width - 4, panel1.ClientSize.Height - 4));
        }
        ControlPaint.DrawBorder(e.Graphics, panel1.ClientRectangle, Color.FromArgb(133, 164, 202), ButtonBorderStyle.Solid);
        ControlPaint.DrawBorder(e.Graphics, new Rectangle(1,1, panel1.ClientSize.Width - 2, panel1.ClientSize.Height - 2), 
            Color.FromArgb(100,220,240,255), 1, ButtonBorderStyle.Solid,
            Color.White, 1, ButtonBorderStyle.Solid,
            Color.FromArgb(100,220,240,255), 1, ButtonBorderStyle.Solid,
            Color.FromArgb(100,204,222,250), 1, ButtonBorderStyle.Solid);
        StringFormat sf = new StringFormat() { LineAlignment = StringAlignment.Center };
        e.Graphics.DrawString("I love .NET", panel1.Font, Brushes.Black, panel1.ClientRectangle, sf);
    } 

这是比较两个条目的屏幕截图:

【讨论】:

    猜你喜欢
    • 2014-05-04
    • 2013-12-31
    • 1970-01-01
    • 2014-07-10
    • 1970-01-01
    • 1970-01-01
    • 2019-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多