Click here to Skip to main content
16,011,680 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I donno why i am unable to put my query properly. :( :((

Here is my concern : In a windows application,, For a data grid , I need rounded corners.

* I want the grid to have rounded corners , not the cells .

For instance if it is in rectangular shape , all the 4 corners of the data grid should be in rounded shape.
Posted
Updated 14-Jun-10 4:20am
v3
Comments
Johnny J. 14-Jun-10 7:43am    
I think you need to clarify. You say it should be a windows application, but at the same time you mention ASP.NET in the tag and CSS in the question, which means that it is a web application. So which is right?
rikpin 14-Jun-10 8:15am    
Hi Jhohnny...

What i meant was windows application in the Visual studio. Even i was confused regarding this but lets cut out the CSS part. All I want is Rounded Corner in a grid.
I could easily do it in a Form. But i need for a grid .
rikpin 14-Jun-10 10:21am    
I have reframed my question again . I hope Henry you would look into it . Any more queries do let me know.
Thank you

This should be fairly easy, depending on quite how round you want the corners.

All you have to do is create a GraphicsPath in whatever shape that you want and set the Region property of the control to be that GraphicsPath.

There is an example of the principle here[^] and if you follow the link at the bottom to example 8.4 you will find one that does it for a Control subclass.

You will also need a RoundedRectangle drawing class but I suggest that you google for that as there are so many of them out there, pick one you like.
 
Share this answer
 
Thanks a lot Henry but i need info in detail. I somehow had difficulty in understading.

Below is the technique for implementation wrt forms

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;


namespace RndCorner
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn( 0, 0,Width-10, Height-10, 20, 20));

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        [DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]

        private static extern IntPtr CreateRoundRectRgn(
            int nLeftRect, // x-coordinate of upper-left corner
            int nTopRect, // y-coordinate of upper-left corner
            int nRightRect, // x-coordinate of lower-right corner
            int nBottomRect, // y-coordinate of lower-right corner
            int nWidthEllipse, // height of ellipse
            int nHeightEllipse // width of ellipse
            );
    }
}



* Same way is there any way for grid
 
Share this answer
 
Almost exactly the same should work.

C#
namespace RndCornerGrid
{
    public partial class MyCustomDataGridView : DataGridView
    {
        public MyCustomDataGridView()
            : base()
        {
            Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn( 0, 0,Width-10, Height-10, 20, 20));
        }

        [DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
        private static extern IntPtr CreateRoundRectRgn(
            int nLeftRect, // x-coordinate of upper-left corner
            int nTopRect, // y-coordinate of upper-left corner
            int nRightRect, // x-coordinate of lower-right corner
            int nBottomRect, // y-coordinate of lower-right corner
            int nWidthEllipse, // height of ellipse
            int nHeightEllipse // width of ellipse
            );
    }
}


Then add an instance of MyCustomDataGridView (or whatever you decide to call it) to your form in the normal way.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900