Round edge panel
-
I am creating a round edge panel by inheriting from the panel. What I do is create a graphics path with desired shape and in the Paint method I fill the graphics path and draw the graphics path border with desired color. This would look as if the panel has round edges. So far I have not set the region. Bounds of the panel is still the rectangle. But the problem come when I set the region of the panel to the Graphics path region. It would not draw the borders( especially left and bottom) properly, it would not draw the curves properly. Also if I set the background image , the image is not smooth along the borders even though I set smoothing mode to AntiAliasing . Any ideas on why it is behaving this way would be greately appreciated. Here is the code in Paint method protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { Graphics gr = e.Graphics; gr.SmoothingMode = SmoothingMode.AntiAlias; if(_roundedCorners) { // clear background with the parent's backcolor before drawing the round edges if( Parent.GetType() == typeof(RoundEdgePanel)) gr.Clear( ((RoundEdgePanel)Parent).PanelBackColor); else gr.Clear(Parent.BackColor); gr.DrawPath(_borderPen, _roundedEdge); // now fill with actual color gr.FillPath( _graphicsPathBrush,_roundedEdge); // setting the region of the control //this.Region = new Region( _roundedEdge); // this is where the problem comes } else { // set the back color to the color of _graphicsPathBackColor gr.Clear( _graphcsPathBackColor); gr.DrawPath(_borderPen, _squaredEdge); //gr.FillRegion( _graphicsPathBrush, this.Region); } } Thanks, VpMahank.