Windows mobile 如何在WindowsMobile6中使用c在datagrid中放置复选框?
如何在WindowsMobile6中使用c在datagrid中放置复选框 数据集dsAgent=table; DataTable=dsAgent.Tables[0]Windows mobile 如何在WindowsMobile6中使用c在datagrid中放置复选框?,windows-mobile,c#-3.0,Windows Mobile,C# 3.0,如何在WindowsMobile6中使用c在datagrid中放置复选框 数据集dsAgent=table; DataTable=dsAgent.Tables[0] DataGridTableStyle tableStyle = new DataGridTableStyle(); tableStyle.MappingName = dataTable.TableName; GridColumnStylesCollectio
DataGridTableStyle tableStyle = new DataGridTableStyle();
tableStyle.MappingName = dataTable.TableName;
GridColumnStylesCollection columnStyles = tableStyle.GridColumnStyles;
DataGridTextBoxColumn columnStyle = new DataGridTextBoxColumn();
columnStyle.MappingName = "FirstName";
columnStyle.HeaderText = "Name";
columnStyle.Width = 80;
columnStyles.Add(columnStyle);
//columnStyle = new DataGridTextBoxColumn();
//columnStyle.MappingName = "EmailAddress";
//columnStyle.HeaderText = "EmailID";
//columnStyle.Width = 150;
//columnStyles.Add(columnStyle);
columnStyle = new DataGridTextBoxColumn();
columnStyle.MappingName = "WorkPhone";
columnStyle.HeaderText = "PhoneNo";
columnStyle.Width = 150;
columnStyles.Add(columnStyle);
GridTableStylesCollection tableStyles = DataGrid.TableStyles;
tableStyles.Add(tableStyle);
DataGrid.PreferredRowHeight = 16;
DataGrid.RowHeadersVisible = false;
DataGrid.DataSource = dataTable;
以下是Eric Hartwell的旧博客中的一些代码:
为了获得更好的复选框UI外观,而不是大十字架
private void DrawCheckBox(Graphics g, Rectangle bounds, CheckState state)
{
int size;
int boxTop;
size = bounds.Size.Height < bounds.Size.Width ? bounds.Size.Height : bounds.Size.Width;
size = size > ((int)g.DpiX / 7) ? ((int)g.DpiX / 7) : size;
boxTop = bounds.Y + (bounds.Height - size) / 2;
size = 12; // 13, so I made it 12
boxTop = boxTop - 1;
using (Pen p = new Pen(this.Owner.ForeColor))
{
g.DrawRectangle(p, bounds.X, boxTop, size, size);
}
if (state != CheckState.Unchecked)
{
using (Pen p = new Pen(state == CheckState.Indeterminate ? SystemColors.GrayText : SystemColors.ControlText))
{
p.Width = 2;
int offset = 2;
int edgeOffset = 2;
g.DrawLine(p, bounds.X + offset, boxTop + offset + 2, bounds.X + (size / 2) - edgeOffset, boxTop + (size / 2) + edgeOffset);
g.DrawLine(p, bounds.X + (size / 2) - edgeOffset, boxTop + (size / 2) + edgeOffset, bounds.X + size - offset, boxTop + offset);
}
}
}
有什么困难?这正好说明你在追求什么。如果有一些部分令人困惑或不清楚,请让我们知道,我们可以尝试帮助澄清。发布你已经尝试过的代码上面的内容与复选框无关,也许我们可以帮助你。
private void DrawCheckBox(Graphics g, Rectangle bounds, CheckState state)
{
int size;
int boxTop;
size = bounds.Size.Height < bounds.Size.Width ? bounds.Size.Height : bounds.Size.Width;
size = size > ((int)g.DpiX / 7) ? ((int)g.DpiX / 7) : size;
boxTop = bounds.Y + (bounds.Height - size) / 2;
size = 12; // 13, so I made it 12
boxTop = boxTop - 1;
using (Pen p = new Pen(this.Owner.ForeColor))
{
g.DrawRectangle(p, bounds.X, boxTop, size, size);
}
if (state != CheckState.Unchecked)
{
using (Pen p = new Pen(state == CheckState.Indeterminate ? SystemColors.GrayText : SystemColors.ControlText))
{
p.Width = 2;
int offset = 2;
int edgeOffset = 2;
g.DrawLine(p, bounds.X + offset, boxTop + offset + 2, bounds.X + (size / 2) - edgeOffset, boxTop + (size / 2) + edgeOffset);
g.DrawLine(p, bounds.X + (size / 2) - edgeOffset, boxTop + (size / 2) + edgeOffset, bounds.X + size - offset, boxTop + offset);
}
}
}