EDN Admin
Well-known member
I try to draw a round rectangle on a panel.
the code for it is following:
<pre lang="x-c# private void DrawRoundRectangle(Graphics g)
{
var width = Convert.ToInt32(WidthUpDown.Value);
var radius = Convert.ToInt32(RadiusUpDown.Value);
var pen = new Pen(Color.Red, width) { Alignment = PenAlignment.Inset };
using (pen)
{
var rect = panel1.ClientRectangle;
rect.Height = rect.Height - (width == 1 ? 1 : width / 2);
rect.Width = rect.Width - (width == 1 ? 1 : width / 2);
var path = new GraphicsPath();
var diameter = radius * 2.0F;
var sizeF = new SizeF(diameter, diameter);
var arc = new RectangleF(rect.Location, sizeF);
path.AddArc(arc, 180, 90);
arc.X = rect.Right - diameter;
path.AddArc(arc, 270, 90);
arc.Y = rect.Bottom - diameter;
path.AddArc(arc, 0, 90);
arc.X = rect.Left;
path.AddArc(arc, 90, 90);
path.CloseFigure();
foreach (var p in path.PathPoints)
{
g.DrawString("o", Font, SystemBrushes.ControlText, p);
}
g.DrawPath(pen, path);
}
}[/code]
<br/>
<div style="color:Black; background-color:White
this works well when the form window is on the first screen(my notebooks main screen)
but when i put the form window on the second screen(a desktop display witch connected to my notebook)
the left part of the round rectangle is not displayed on the panel area.
the more strange is when i make the window smaller and put it on the right bottom of the second screen,
the round rectangle is draw well. but when i put the window on the left top of the second screen,
left part of the round rectangle disappear.
i cant find where is the problem.
is it the bug of DrawPath method?
and the screen shot is following:
http://www.flickr.com/photos/46694300@N00/5511209612/
http://www.flickr.com/photos/46694300@N00/5510610653/
View the full article
the code for it is following:
<pre lang="x-c# private void DrawRoundRectangle(Graphics g)
{
var width = Convert.ToInt32(WidthUpDown.Value);
var radius = Convert.ToInt32(RadiusUpDown.Value);
var pen = new Pen(Color.Red, width) { Alignment = PenAlignment.Inset };
using (pen)
{
var rect = panel1.ClientRectangle;
rect.Height = rect.Height - (width == 1 ? 1 : width / 2);
rect.Width = rect.Width - (width == 1 ? 1 : width / 2);
var path = new GraphicsPath();
var diameter = radius * 2.0F;
var sizeF = new SizeF(diameter, diameter);
var arc = new RectangleF(rect.Location, sizeF);
path.AddArc(arc, 180, 90);
arc.X = rect.Right - diameter;
path.AddArc(arc, 270, 90);
arc.Y = rect.Bottom - diameter;
path.AddArc(arc, 0, 90);
arc.X = rect.Left;
path.AddArc(arc, 90, 90);
path.CloseFigure();
foreach (var p in path.PathPoints)
{
g.DrawString("o", Font, SystemBrushes.ControlText, p);
}
g.DrawPath(pen, path);
}
}[/code]
<br/>
<div style="color:Black; background-color:White
this works well when the form window is on the first screen(my notebooks main screen)
but when i put the form window on the second screen(a desktop display witch connected to my notebook)
the left part of the round rectangle is not displayed on the panel area.
the more strange is when i make the window smaller and put it on the right bottom of the second screen,
the round rectangle is draw well. but when i put the window on the left top of the second screen,
left part of the round rectangle disappear.
i cant find where is the problem.
is it the bug of DrawPath method?
and the screen shot is following:
http://www.flickr.com/photos/46694300@N00/5511209612/
http://www.flickr.com/photos/46694300@N00/5510610653/
View the full article