GrapeCity.Win.MultiRow.v80 アセンブリ > GrapeCity.Win.MultiRow 名前空間 : NamedCellStyle クラス |
CellStyleNameプロパティの値は、オーナーTemplateのTemplate.NamedCellStylesプロパティ、またはオーナーGcMultiRowのGcMultiRow.NamedCellStylesプロパティを参照します。
多数のセルで使用されるスタイルに対してNamedCellStyleを使用すると、メモリが節約され、セルスタイルの管理が容易になります。
NamedCellStyleを使用することで、セルのCell.Styleプロパティを変更せずにスキンシステムを実現できます(代わりにMultiRowコントロールまたはテンプレートのNamedCellStylesプロパティを変更します)。
using System; using System.Windows.Forms; using System.Drawing; using System.Drawing.Drawing2D; namespace GrapeCity.Win.MultiRow.SampleCode { class NamedCellStyleDemo : Form { private GcMultiRow gcMultiRow1 = new GcMultiRow(); private FlowLayoutPanel panel = new FlowLayoutPanel(); public NamedCellStyleDemo() { this.Text = "NamedCellStyle Demo"; this.Size = new Size(1000, 750); // Initial flow layout panel and add to form. this.panel.Dock = DockStyle.Left; this.panel.Size = new Size(200, 200); this.panel.FlowDirection = FlowDirection.TopDown; this.panel.WrapContents = false; this.panel.Padding = new Padding(5); this.panel.AutoSize = true; this.Controls.Add(panel); this.gcMultiRow1.Dock = DockStyle.Left; this.gcMultiRow1.Width = 800; this.Controls.Add(this.gcMultiRow1); this.Load += new EventHandler(Form1_Load); InitButton(); this.StartPosition = FormStartPosition.CenterScreen; } private void Form1_Load(object sender, EventArgs e) { Template template1 = Template.CreateGridTemplate(20, 50, 21); for (int i = 0; i < template1.Row.Cells.Count - 1; i++) { if (i % 2 == 0) { //The even columns use the "AlternatingColumnsDefaultCellStyle" template1.Row.Cells[i].Style = new NamedCellStyle("AlternatingColumnsDefaultCellStyle"); } else { //The odd columns use the "ColumnsDefaultCellStyle" template1.Row.Cells[i].Style = new NamedCellStyle("ColumnsDefaultCellStyle"); } } gcMultiRow1.Template = template1; gcMultiRow1.RowCount = 20; } #region Button Event Handlers void setFirstNamedCellStyle_Click(object sender, EventArgs e) { CellStyle alternatingColumnsDefaultCellStyle = new CellStyle(); alternatingColumnsDefaultCellStyle.BackColor = Color.FromArgb(150, 160, 159); alternatingColumnsDefaultCellStyle.ForeColor = Color.White; alternatingColumnsDefaultCellStyle.NullValue = "Text"; //Change the "AlternatingColumnsDefaultCellStyle" this.gcMultiRow1.NamedCellStyles["AlternatingColumnsDefaultCellStyle"] = alternatingColumnsDefaultCellStyle; CellStyle columnsDefaultCellStyle = new CellStyle(); columnsDefaultCellStyle.BackColor = Color.FromArgb(226, 228, 228); columnsDefaultCellStyle.ForeColor = Color.Black; columnsDefaultCellStyle.NullValue = "Text"; //Change the "ColumnsDefaultCellStyle" this.gcMultiRow1.NamedCellStyles["ColumnsDefaultCellStyle"] = columnsDefaultCellStyle; //You can load one predefined NamedCellStyleDictionary from one file. //this.gcMultiRow1.NamedCellStyles.Load(@"C:\temp\NamedCellStyles.xml"); //You can save the NamedCellStyleDictionary to one file. //this.gcMultiRow1.NamedCellStyles.Save(@"C:\temp\NamedCellStyles.xml"); } void setSecondNamedCellStyle_Click(object sender, EventArgs e) { CellStyle alternatingColumnsDefaultCellStyle = new CellStyle(); alternatingColumnsDefaultCellStyle.BackColor = Color.Orange; alternatingColumnsDefaultCellStyle.ForeColor = Color.Black; alternatingColumnsDefaultCellStyle.NullValue = "Text"; //Change the "AlternatingColumnsDefaultCellStyle" this.gcMultiRow1.NamedCellStyles["AlternatingColumnsDefaultCellStyle"] = alternatingColumnsDefaultCellStyle; CellStyle columnsDefaultCellStyle = new CellStyle(); columnsDefaultCellStyle.GradientColors = new Color[] { Color.Orange, Color.Lime }; columnsDefaultCellStyle.GradientDirection = GradientDirection.Center; columnsDefaultCellStyle.GradientStyle = GradientStyle.Vertical; //columnsDefaultCellStyle.BackColor = Color.FromArgb(230, 255, 230); //columnsDefaultCellStyle.ForeColor = Color.Red ; columnsDefaultCellStyle.NullValue = "Text"; this.gcMultiRow1.NamedCellStyles["ColumnsDefaultCellStyle"] = columnsDefaultCellStyle; //You can load one predefined NamedCellStyleDictionary from one file. //this.gcMultiRow1.NamedCellStyles.Load(@"C:\temp\NamedCellStyles.xml"); //You can save the NamedCellStyleDictionary to one file. //this.gcMultiRow1.NamedCellStyles.Save(@"C:\temp\NamedCellStyles.xml"); } void setThirdNamedCellStyle_Click(object sender, EventArgs e) { CellStyle alternatingColumnsDefaultCellStyle = new CellStyle(); alternatingColumnsDefaultCellStyle.BackColor = Color.White; alternatingColumnsDefaultCellStyle.NullValue = "Text"; //Change the "AlternatingColumnsDefaultCellStyle" this.gcMultiRow1.NamedCellStyles["AlternatingColumnsDefaultCellStyle"] = alternatingColumnsDefaultCellStyle; CellStyle columnsDefaultCellStyle = new CellStyle(); columnsDefaultCellStyle.PatternColor = Color.DarkSlateGray; columnsDefaultCellStyle.PatternStyle = MultiRowHatchStyle.HorizontalBrick; //Change the "ColumnsDefaultCellStyle" this.gcMultiRow1.NamedCellStyles["ColumnsDefaultCellStyle"] = columnsDefaultCellStyle; //You can load one predefined NamedCellStyleDictionary from one file. //this.gcMultiRow1.NamedCellStyles.Load(@"C:\temp\NamedCellStyles.xml"); //You can save the NamedCellStyleDictionary to one file. //this.gcMultiRow1.NamedCellStyles.Save(@"C:\temp\NamedCellStyles.xml"); } void SetBorderToAlternatingColumns(object sender, EventArgs e) { CellStyle borderCellStyle = new CellStyle(); borderCellStyle.Border = new RoundedBorder(LineStyle.Thin, Color.Gray, 0.5f); CellStyle colorStyle = new CellStyle(); colorStyle.BackColor = Color.Yellow; //The combinedCellStyle1 will merge borderCellStyle and AlternatingColumnsDefaultCellStyle. CombinedCellStyle combinedCellStyle1 = new CombinedCellStyle(); combinedCellStyle1.Items.AddRange(new CellStyle[] { borderCellStyle, colorStyle }); this.gcMultiRow1.NamedCellStyles["AlternatingColumnsDefaultCellStyle"] = combinedCellStyle1; } #endregion #region Initialize Buttons private void InitButton() { AddButton(setFirstStyle, "The first NamedCellStyle", new EventHandler(setFirstNamedCellStyle_Click)); AddButton(setSecondStyle, "The second NamedCellStyle", new EventHandler(setSecondNamedCellStyle_Click)); AddButton(setThirdStyle, "The third NamedCellStyle", new EventHandler(setThirdNamedCellStyle_Click)); AddButton(setBorder, "Set the border to odd Columns", new EventHandler(SetBorderToAlternatingColumns)); } private void AddButton(Button button, string text, EventHandler eventHandler) { this.panel.Controls.Add(button); button.Text = text; button.AutoSize = true; button.Click += eventHandler; } Button setFirstStyle = new Button(); Button setSecondStyle = new Button(); Button setThirdStyle = new Button(); Button setBorder = new Button(); #endregion [STAThreadAttribute()] public static void Main() { Application.EnableVisualStyles(); Application.Run(new NamedCellStyleDemo()); } } }
Imports System Imports System.Windows.Forms Imports System.Drawing Imports System.Drawing.Drawing2D Imports GrapeCity.Win.MultiRow Class NamedCellStyleDemo Inherits Form Private gcMultiRow1 As New GcMultiRow() Private panel As New FlowLayoutPanel() Public Sub New() Me.Text = "NamedCellStyle Demo" Me.Size = New Size(1000, 750) ' Initial flow layout panel and add to form. Me.panel.Dock = DockStyle.Left Me.panel.Size = New Size(200, 200) Me.panel.FlowDirection = FlowDirection.TopDown Me.panel.WrapContents = False Me.panel.Padding = New Padding(5) Me.panel.AutoSize = True Me.Controls.Add(panel) Me.gcMultiRow1.Dock = DockStyle.Left Me.gcMultiRow1.Width = 800 Me.Controls.Add(Me.gcMultiRow1) InitButton() Me.StartPosition = FormStartPosition.CenterScreen End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load Dim template1 As Template = Template.CreateGridTemplate(20, 50, 21) For i As Integer = 0 To template1.Row.Cells.Count - 2 If i Mod 2 = 0 Then 'The even columns use the "AlternatingColumnsDefaultCellStyle" template1.Row.Cells(i).Style = New NamedCellStyle("AlternatingColumnsDefaultCellStyle") Else 'The odd columns use the "ColumnsDefaultCellStyle" template1.Row.Cells(i).Style = New NamedCellStyle("ColumnsDefaultCellStyle") End If Next gcMultiRow1.Template = template1 gcMultiRow1.RowCount = 20 End Sub #Region "Button Event Handlers" Private Sub setFirstNamedCellStyle_Click(ByVal sender As Object, ByVal e As EventArgs) Handles setFirstStyle.Click Dim alternatingColumnsDefaultCellStyle As New CellStyle() alternatingColumnsDefaultCellStyle.BackColor = Color.FromArgb(150, 160, 159) alternatingColumnsDefaultCellStyle.ForeColor = Color.White alternatingColumnsDefaultCellStyle.NullValue = "Text" 'Change the "AlternatingColumnsDefaultCellStyle" Me.gcMultiRow1.NamedCellStyles("AlternatingColumnsDefaultCellStyle") = alternatingColumnsDefaultCellStyle Dim columnsDefaultCellStyle As New CellStyle() columnsDefaultCellStyle.BackColor = Color.FromArgb(226, 228, 228) columnsDefaultCellStyle.ForeColor = Color.Black columnsDefaultCellStyle.NullValue = "Text" 'Change the "ColumnsDefaultCellStyle" Me.gcMultiRow1.NamedCellStyles("ColumnsDefaultCellStyle") = columnsDefaultCellStyle 'You can load one predefined NamedCellStyleDictionary from one file. 'this.gcMultiRow1.NamedCellStyles.Load(@"C:\temp\NamedCellStyles.xml"); 'You can save the NamedCellStyleDictionary to one file. 'this.gcMultiRow1.NamedCellStyles.Save(@"C:\temp\NamedCellStyles.xml"); End Sub Private Sub setSecondNamedCellStyle_Click(ByVal sender As Object, ByVal e As EventArgs) Handles setSecondStyle.Click Dim alternatingColumnsDefaultCellStyle As New CellStyle() alternatingColumnsDefaultCellStyle.BackColor = Color.Orange alternatingColumnsDefaultCellStyle.ForeColor = Color.Black alternatingColumnsDefaultCellStyle.NullValue = "Text" 'Change the "AlternatingColumnsDefaultCellStyle" Me.gcMultiRow1.NamedCellStyles("AlternatingColumnsDefaultCellStyle") = alternatingColumnsDefaultCellStyle Dim columnsDefaultCellStyle As New CellStyle() columnsDefaultCellStyle.GradientColors = New Color() {Color.Orange, Color.Lime} columnsDefaultCellStyle.GradientDirection = GradientDirection.Center columnsDefaultCellStyle.GradientStyle = GradientStyle.Vertical 'columnsDefaultCellStyle.BackColor = Color.FromArgb(230, 255, 230); 'columnsDefaultCellStyle.ForeColor = Color.Red ; columnsDefaultCellStyle.NullValue = "Text" Me.gcMultiRow1.NamedCellStyles("ColumnsDefaultCellStyle") = columnsDefaultCellStyle 'You can load one predefined NamedCellStyleDictionary from one file. 'this.gcMultiRow1.NamedCellStyles.Load(@"C:\temp\NamedCellStyles.xml"); 'You can save the NamedCellStyleDictionary to one file. 'this.gcMultiRow1.NamedCellStyles.Save(@"C:\temp\NamedCellStyles.xml"); End Sub Private Sub setThirdNamedCellStyle_Click(ByVal sender As Object, ByVal e As EventArgs) Handles setThirdStyle.Click Dim alternatingColumnsDefaultCellStyle As New CellStyle() alternatingColumnsDefaultCellStyle.BackColor = Color.White alternatingColumnsDefaultCellStyle.NullValue = "Text" 'Change the "AlternatingColumnsDefaultCellStyle" Me.gcMultiRow1.NamedCellStyles("AlternatingColumnsDefaultCellStyle") = alternatingColumnsDefaultCellStyle Dim columnsDefaultCellStyle As New CellStyle() columnsDefaultCellStyle.PatternColor = Color.DarkSlateGray columnsDefaultCellStyle.PatternStyle = MultiRowHatchStyle.HorizontalBrick 'Change the "ColumnsDefaultCellStyle" Me.gcMultiRow1.NamedCellStyles("ColumnsDefaultCellStyle") = columnsDefaultCellStyle 'You can load one predefined NamedCellStyleDictionary from one file. 'this.gcMultiRow1.NamedCellStyles.Load(@"C:\temp\NamedCellStyles.xml"); 'You can save the NamedCellStyleDictionary to one file. 'this.gcMultiRow1.NamedCellStyles.Save(@"C:\temp\NamedCellStyles.xml"); End Sub Private Sub SetBorderToAlternatingColumns(ByVal sender As Object, ByVal e As EventArgs) Handles setBorder.Click Dim borderCellStyle As New CellStyle() borderCellStyle.Border = New RoundedBorder(LineStyle.Thin, Color.Gray, 0.5F) Dim colorStyle As New CellStyle() colorStyle.BackColor = Color.Yellow 'The combinedCellStyle1 will merge borderCellStyle and AlternatingColumnsDefaultCellStyle. Dim combinedCellStyle1 As New CombinedCellStyle() combinedCellStyle1.Items.AddRange(New CellStyle() {borderCellStyle, colorStyle}) Me.gcMultiRow1.NamedCellStyles("AlternatingColumnsDefaultCellStyle") = combinedCellStyle1 End Sub #End Region #Region "Initialize Buttons" Private Sub InitButton() AddButton(setFirstStyle, "The first NamedCellStyle") AddButton(setSecondStyle, "The second NamedCellStyle") AddButton(setThirdStyle, "The third NamedCellStyle") AddButton(setBorder, "Set the border to odd Columns") End Sub Private Sub AddButton(ByVal button As Button, ByVal text As String) Me.panel.Controls.Add(button) button.Text = text button.AutoSize = True End Sub Friend WithEvents setFirstStyle As New Button() Friend WithEvents setSecondStyle As New Button() Friend WithEvents setThirdStyle As New Button() Friend WithEvents setBorder As New Button() #End Region <STAThreadAttribute()> _ Public Shared Sub Main() Application.EnableVisualStyles() Application.Run(New NamedCellStyleDemo()) End Sub End Class
System.Object
GrapeCity.Win.MultiRow.CellStyle
GrapeCity.Win.MultiRow.NamedCellStyle