How can I draw a system focus rectangle using gdi, C#? I'm mainly interested in the glass effect focus rectangle found in the common listview control on Windows 7. Thanks in advance.
Asked
Active
Viewed 1,425 times
0
-
1Do you need an exact effect? any screen shot to show what you want? – King King Jul 09 '13 at 16:34
-
Not exact I was hopping that there is some system function that will provide me system specific focus recangle . Like in this question 'http://stackoverflow.com/questions/5086682/windows-7-native-look-for-net-listview' – user629926 Jul 09 '13 at 16:36
-
http://msdn.microsoft.com/en-us/library/ms162274.aspx – Hans Passant Jul 09 '13 at 17:46
-
Thanks I found this based on that http://stackoverflow.com/questions/3014816/visualstylerenderer-and-themes-winforms – user629926 Jul 09 '13 at 18:04
1 Answers
0
I use a Panel
to treat as a ListViewItem
and drawing on this panel to demonstrate what should be done, it looks almost like the focused entry in a ListView used in Windows 7.
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);
}
And here is the screen shot to compare the both entries:

King King
- 61,710
- 16
- 105
- 130