数据网格中的圆角(需要尽快提供帮助) [英] Rounded Corners in a data grid (help needed asap)
本文介绍了数据网格中的圆角(需要尽快提供帮助)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道为什么我无法正确输入查询内容. :(:((
这是我关心的问题:在Windows应用程序中,对于数据网格,我需要圆角.
*我希望网格具有圆角,而不是单元格.
例如,如果它是矩形,则数据网格的所有4个角都应为圆形.
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.
推荐答案
这应该相当容易,具体取决于圆你想要的角落.
您所要做的就是以所需的任意形状创建一个GraphicsPath
并将控件的Region
属性设置为该GraphicsPath.
此处有一个示例示例 [
This should be fairly easy, depending on quite how round you want the corners.
All you have to do is create aGraphicsPath
in whatever shape that you want and set theRegion
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 aControl
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.
非常感谢Henry,但我需要信息详细地.我莫名其妙地难以理解.
以下是实现wrt表单的技术
Thanks a lot Henry but i need info in detail. I somehow had difficulty in understading.
Below is the technique for implementation wrt forms
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
几乎完全相同应该起作用.
Almost exactly the same should work.
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
);
}
}
然后以常规方式将MyCustomDataGridView实例(或您决定调用的任何实例)添加到表单中.
Then add an instance of MyCustomDataGridView (or whatever you decide to call it) to your form in the normal way.
这篇关于数据网格中的圆角(需要尽快提供帮助)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文