|
Query |
Solution |
|
How can i set style of PushButton to metro, set backcolor of PushButton |
In order to change the background color of PushButton, you can use the GridMetroColors in SetMetroStyle method. Please refer to the below code example,
Code example
GridMetroColors colors = new GridMetroColors();
colors.PushButtonColor.NormalBackColor = Color.FromArgb(22,165,220);
colors.PushButtonColor.HoverBackColor = Color.FromArgb(26, 198, 255);
colors.PushButtonColor.PushedBackColor = Color.FromArgb(120, 191, 217);
this.gridGroupingControl1.SetMetroStyle(colors);
|
|
Change style of pushbutton(TextColor, FontStyle,etc) |
Suggestion1
In order to change the style of push button, you can use the GridTableCellAppearance.AnyRecordFieldCell property. Please refer to the below code example,
Code example
this.gridGroupingControl1.TableDescriptor.Columns["ColumnName"].Appearance.AnyRecordFieldCell.TextColor = Color.White;
this.gridGroupingControl1.TableDescriptor.Columns["ColumnName"].Appearance.AnyRecordFieldCell.HorizontalAlignment = GridHorizontalAlignment.Center;
this.gridGroupingControl1.TableDescriptor.Columns["ColumnName"].Appearance.AnyRecordFieldCell.VerticalAlignment = GridVerticalAlignment.Middle;
Suggestion2
You can also use the QueryCellStyleInfo event to change the style of PushButton column. Please refer to the below code example,
Code example
this.gridGroupingControl1.QueryCellStyleInfo += GridGroupingControl1_QueryCellStyleInfo;
private void GridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
if (e.TableCellIdentity == null || e.TableCellIdentity.Column == null)
return;
if(e.TableCellIdentity.Column.Name == " ColumnName")
{
e.Style.Description = "Click";
e.Style.TextColor = Color.White;
e.Style.HorizontalAlignment = GridHorizontalAlignment.Center;
e.Style.VerticalAlignment = GridVerticalAlignment.Middle;
}
} |
|
this.gridGroupingControl1.QueryCellStyleInfo += GridGroupingControl1_QueryCellStyleInfo;
private void GridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
if (e.TableCellIdentity == null || e.TableCellIdentity.Column == null)
return;
if(e.TableCellIdentity.Column.Name == "PushButton")
{
if (e.TableCellIdentity.RowIndex == 5)
e.Style.Enabled = false;
e.Style.Description = "Click";
}
} |
|
this.gridGroupingControl1.TableControl.DrawCellButton += TableControl_DrawCellButton;
private void TableControl_DrawCellButton(object sender, GridDrawCellButtonEventArgs e)
{
if (this.gridGroupingControl1.GridVisualStyles == GridVisualStyles.Metro && !e.Style.Enabled && e.Style.CellType.Equals(GridCellTypeName.PushButton))
{
Rectangle rect = e.Button.Bounds;
Rectangle faceRect = Rectangle.FromLTRB(rect.Left + 1, rect.Top + 1, rect.Right - 2, rect.Bottom - 2);
StringFormat format = new StringFormat();
format.Alignment = GridUtil.ConvertToStringAlignment(e.Style.HorizontalAlignment);
format.LineAlignment = GridUtil.ConvertToStringAlignment(e.Style.VerticalAlignment);
format.HotkeyPrefix = e.Style.HotkeyPrefix;
format.Trimming = e.Style.Trimming;
if (!e.Style.WrapText)
{
format.FormatFlags = StringFormatFlags.NoWrap;
}
//To draw the disabled back color
e.Graphics.FillRectangle(new SolidBrush(ColorTranslator.FromHtml("#d5d5d5")), rect);
//To draw the text with disabled forecolor
e.Graphics.DrawString(e.Style.Description, e.Style.GdipFont, new SolidBrush(ColorTranslator.FromHtml("#9e9e9e")), faceRect, format);
e.Cancel = true;
}
} |
|
private void TableControl_DrawCellButton(object sender, GridDrawCellButtonEventArgs e)
{
if (this.gridGroupingControl1.GridVisualStyles == GridVisualStyles.Metro && e.Style.CellType.Equals(GridCellTypeName.PushButton))
{
GridTableCellStyleInfo style = e.Style as GridTableCellStyleInfo;
if (style != null && style.TableCellIdentity.Column != null && style.TableCellIdentity.Column.Name == "PushButton")
{
var value = style.CellValue;
}
//Your customization
e.Cancel = true;
}
} |