using System;
using System.Drawing;
using System.Windows.Forms;
namespace GrapeCity.Win.MultiRow.SampleCode
{
public class ResizeDemo : Form
{
private GcMultiRow gcMultiRow1 = new GcMultiRow();
private FlowLayoutPanel panel = new FlowLayoutPanel();
private Label label = new Label();
public ResizeDemo()
{
this.Text = "Resize Demo";
this.Size = new Size(600, 350);
// Initial flow layout panel and add to form.
this.panel.Dock = DockStyle.Left;
this.panel.Size = new Size(250, 200);
this.panel.FlowDirection = FlowDirection.TopDown;
this.panel.WrapContents = false;
this.panel.Padding = new Padding(5);
this.Controls.Add(panel);
// Add MultiRow to form
this.gcMultiRow1.Dock = DockStyle.Left;
this.gcMultiRow1.Width = 350;
this.gcMultiRow1.CellResizeCompleted += new EventHandler<CellEventArgs>(gcMultiRow1_CellResizeCompleted);
this.Controls.Add(this.gcMultiRow1);
this.label.Height = 30;
this.label.Dock = DockStyle.Bottom;
this.label.BackColor = SystemColors.Info;
this.label.Text = "You can resize the Cell at the right or bottom edge.";
this.Controls.Add(label);
gcMultiRow1.Template = Template.CreateGridTemplate(3);
gcMultiRow1.RowCount = 5;
FillValue();
this.Load += new EventHandler(Form1_Load);
InitButton();
}
void FillValue()
{
// Fill values.
for (int rowIndex = 0; rowIndex < gcMultiRow1.RowCount; rowIndex++)
{
for (int cellIndex = 0; cellIndex < 3; cellIndex++)
{
gcMultiRow1[rowIndex, cellIndex].Value = "RowIndex: " + rowIndex.ToString() + " CellIndex: " + cellIndex.ToString();
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
// Use AllowUserToResize property can disable/enable MultiRow control's UIResize.
this.gcMultiRow1.AllowUserToResize = true;
// Show resize tip when UI resize.
this.gcMultiRow1.ShowResizeTip = ResizeMode.Both;
// Customize resize tip.
this.gcMultiRow1.ResizeTipTextNeeded += new EventHandler<ResizeTipTextNeededEventArgs>(gcMultiRow1_ResizeTipTextNeeded);
}
void gcMultiRow1_ResizeTipTextNeeded(object sender, ResizeTipTextNeededEventArgs e)
{
// Customize 1nd column's resize tip and 1nd rows resize tip.
if (e.CellIndex == 0 || e.RowIndex == 0)
{
string direction = "height";
if (e.Direction == Orientation.Horizontal)
{
direction = "width";
}
e.ResizeTipText = "Cell " + direction + " resize from " + e.OldValue + " to " + e.NewValue;
}
}
void gcMultiRow1_CellResizeCompleted(object sender, CellEventArgs e)
{
this.label.Text = "CellResizeCompleted:" + " CellScope=" + e.Scope +
" SectionIndex=" + e.SectionIndex + " CellIndex=" + e.CellIndex + " CellName=" + e.CellName;
}
#region Button Event Handlers
void changeFristColumnWidth_Click(object sender, EventArgs e)
{
Cell cell = this.gcMultiRow1.ColumnHeaders[0][0];
// Cell's width decrease by 5 pixel.
cell.HorizontalResize(-5);
}
void changeFristRowWidth_Click(object sender, EventArgs e)
{
Cell cell = this.gcMultiRow1.Rows[0][0];
// Cell's height decrease by 5 pixel.
cell.VerticalResize(-5);
}
void autoFitAllColumns_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.gcMultiRow1.ColumnHeaders[0].Cells.Count; i++)
{
Cell cell = this.gcMultiRow1.ColumnHeaders[0][i];
// Auto change cell's width to fit cells contents.
cell.PerformHorizontalAutoFit();
}
}
void autoFitAllRows_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.gcMultiRow1.RowCount; i++)
{
Cell cell = this.gcMultiRow1.Rows[i][0];
// Auto change cell's height to fit cells contents.
cell.PerformVerticalAutoFit();
}
}
void makeFirstCellResizable_Click(object sender, EventArgs e)
{
Cell cell = this.gcMultiRow1.Rows[0][0];
// Make cell resizable in two directions.
// You can make any cell can (or can not) resize by change this property's value.
cell.ResizeMode = ResizeMode.Both;
}
void setFirstCellMaxSizeAndMinSize_Click(object sender, EventArgs e)
{
Cell cell = this.gcMultiRow1.Template.Row[0];
cell.MaximumSize = new Size(125, 0);
cell.MinimumSize = new Size(60, 0);
gcMultiRow1.Template = gcMultiRow1.Template;
FillValue();
}
#endregion
#region Initialize Buttons
private void InitButton()
{
AddButton(changeFristColumnWidth, "Change 1st Column Width", new EventHandler(changeFristColumnWidth_Click));
AddButton(changeFristRowWidth, "Change 1st Row Width", new EventHandler(changeFristRowWidth_Click));
AddButton(autoFitAllColumns, "Auto fit all columns width", new EventHandler(autoFitAllColumns_Click));
AddButton(autoFitAllRows, "Auto fit all rows height", new EventHandler(autoFitAllRows_Click));
AddButton(makeFirstCellResizable, "Make 1st cell in 1st row resizable", new EventHandler(makeFirstCellResizable_Click));
AddButton(makeFirstCellMaxSizeAndMinSize, "Set 1st cell's MaxSize and MinSize", new EventHandler(setFirstCellMaxSizeAndMinSize_Click));
}
private void AddButton(Button button, string text, EventHandler eventHandler)
{
this.panel.Controls.Add(button);
button.Text = text;
button.AutoSize = true;
button.Click += eventHandler;
}
Button changeFristColumnWidth = new Button();
Button changeFristRowWidth = new Button();
Button autoFitAllColumns = new Button();
Button autoFitAllRows = new Button();
Button makeFirstCellResizable = new Button();
Button makeFirstCellMaxSizeAndMinSize = new Button();
#endregion
[STAThreadAttribute()]
public static void Main()
{
Application.EnableVisualStyles();
Application.Run(new ResizeDemo());
}
}
}
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports GrapeCity.Win.MultiRow
Public Class ResizeDemo
Inherits Form
Friend WithEvents gcMultiRow1 As New GcMultiRow()
Private panel As New FlowLayoutPanel()
Private label As New Label()
Public Sub New()
Me.Text = "Resize Demo"
Me.Size = New Size(600, 350)
' Initial flow layout panel and add to form.
Me.panel.Dock = DockStyle.Left
Me.panel.Size = New Size(250, 200)
Me.panel.FlowDirection = FlowDirection.TopDown
Me.panel.WrapContents = False
Me.panel.Padding = New Padding(5)
Me.Controls.Add(panel)
' Add MultiRow to form
Me.gcMultiRow1.Dock = DockStyle.Left
Me.gcMultiRow1.Width = 350
Me.Controls.Add(Me.gcMultiRow1)
Me.label.Height = 30
Me.label.Dock = DockStyle.Bottom
Me.label.BackColor = SystemColors.Info
Me.label.Text = "You can resize the Cell at the right or bottom edge."
Me.Controls.Add(label)
gcMultiRow1.Template = Template.CreateGridTemplate(3)
gcMultiRow1.RowCount = 5
FillValue()
InitButton()
End Sub
Private Sub FillValue()
' Fill values.
For rowIndex As Integer = 0 To Me.gcMultiRow1.RowCount - 1
For cellIndex As Integer = 0 To 2
gcMultiRow1(rowIndex, cellIndex).Value = "RowIndex: " + rowIndex.ToString() + " CellIndex: " + cellIndex.ToString()
Next
Next
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
' Use AllowUserToResize property can disable/enable MultiRow control's UIResize.
Me.gcMultiRow1.AllowUserToResize = True
' Show resize tip when UI resize.
Me.gcMultiRow1.ShowResizeTip = ResizeMode.Both
End Sub
Private Sub gcMultiRow1_ResizeTipTextNeeded(ByVal sender As Object, ByVal e As ResizeTipTextNeededEventArgs) Handles gcMultiRow1.ResizeTipTextNeeded
' Customize 1nd column's resize tip and 1nd rows resize tip.
If e.CellIndex = 0 OrElse e.RowIndex = 0 Then
Dim direction As String = "height"
If e.Direction = Orientation.Horizontal Then
direction = "width"
End If
e.ResizeTipText = "Cell " + direction + " resize from " + e.OldValue.ToString() + " to " + e.NewValue.ToString()
End If
End Sub
Private Sub gcMultiRow1_CellResizeCompleted(ByVal sender As Object, ByVal e As CellEventArgs) Handles gcMultiRow1.CellResizeCompleted
Me.label.Text = "CellResizeCompleted:" + " CellScope=" + e.Scope.ToString() + " SectionIndex=" + e.SectionIndex.ToString() + " CellIndex=" + e.CellIndex.ToString() + " CellName=" + e.CellName.ToString()
End Sub
#Region "Button Event Handlers"
Private Sub changeFristColumnWidth_Click(ByVal sender As Object, ByVal e As EventArgs) Handles changeFristColumnWidth.Click
Dim cell As Cell = Me.gcMultiRow1.ColumnHeaders(0)(0)
' Cell's width decrease by 5 pixel.
cell.HorizontalResize(-5)
End Sub
Private Sub changeFristRowWidth_Click(ByVal sender As Object, ByVal e As EventArgs) Handles changeFristRowWidth.Click
Dim cell As Cell = Me.gcMultiRow1.Rows(0)(0)
' Cell's height decrease by 5 pixel.
cell.VerticalResize(-5)
End Sub
Private Sub autoFitAllColumns_Click(ByVal sender As Object, ByVal e As EventArgs) Handles autoFitAllColumns.Click
For i As Integer = 0 To Me.gcMultiRow1.ColumnHeaders(0).Cells.Count - 1
Dim cell As Cell = Me.gcMultiRow1.ColumnHeaders(0)(i)
' Auto change cell's width to fit cells contents.
cell.PerformHorizontalAutoFit()
Next
End Sub
Private Sub autoFitAllRows_Click(ByVal sender As Object, ByVal e As EventArgs) Handles autoFitAllRows.Click
For i As Integer = 0 To Me.gcMultiRow1.RowCount - 1
Dim cell As Cell = Me.gcMultiRow1.Rows(i)(0)
' Auto change cell's height to fit cells contents.
cell.PerformVerticalAutoFit()
Next
End Sub
Private Sub makeFirstCellResizable_Click(ByVal sender As Object, ByVal e As EventArgs) Handles makeFirstCellResizable.Click
Dim cell As Cell = Me.gcMultiRow1.Rows(0)(0)
' Make cell resizable in two directions.
' You can make any cell can (or can not) resize by change this property's value.
cell.ResizeMode = ResizeMode.Both
End Sub
Private Sub setFirstCellMaxSizeAndMinSize_Click(ByVal sender As Object, ByVal e As EventArgs) Handles makeFirstCellMaxSizeAndMinSize.Click
Dim cell As Cell = Me.gcMultiRow1.Template.Row(0)
cell.MaximumSize = New Size(125, 0)
cell.MinimumSize = New Size(60, 0)
gcMultiRow1.Template = gcMultiRow1.Template
FillValue()
End Sub
#End Region
#Region "Initialize Buttons"
Private Sub InitButton()
AddButton(changeFristColumnWidth, "Change 1st Column Width")
AddButton(changeFristRowWidth, "Change 1st Row Width")
AddButton(autoFitAllColumns, "Auto fit all columns width")
AddButton(autoFitAllRows, "Auto fit all rows height")
AddButton(makeFirstCellResizable, "Make 1st cell in 1st row resizable")
AddButton(makeFirstCellMaxSizeAndMinSize, "Set 1st cell's MaxSize and MinSize")
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 changeFristColumnWidth As New Button()
Friend WithEvents changeFristRowWidth As New Button()
Friend WithEvents autoFitAllColumns As New Button()
Friend WithEvents autoFitAllRows As New Button()
Friend WithEvents makeFirstCellResizable As New Button()
Friend WithEvents makeFirstCellMaxSizeAndMinSize As New Button()
#End Region
<STAThreadAttribute()> _
Public Shared Sub Main()
Application.EnableVisualStyles()
Application.Run(New ResizeDemo())
End Sub
End Class