リサイズコンポーネントでGcListBoxのリサイズ時に発生する問題を回避するリサイズポリシー

文書番号 : 35398     文書種別 : 使用方法     登録日 : 2013/02/28     最終更新日 : 2013/02/28
文書を印刷する
対象製品
PlusPak for Windows Forms 7.0J
詳細
リサイズコンポーネント(GcResize)を使用して、InputManのGcListBoxコントロールをリサイズする場合、下記の問題が発生します。

  • リストの列幅がコントロールに合わせてサイズ変更されない

本現象は、以下のコードを使用してユーザー定義のリサイズポリシーを追加することで対応できます。
なお、本現象はリサイズパネル(GcResizePanel)でも発生しますが、同じ方法で対応できます。

ユーザー定義のリサイズポリシーの使い方については、製品ヘルプの以下の内容をご参照ください。

PowerTools PlusPak for Windows Forms 7.0J
 - PlusPak の使い方
  - レイアウト
   - GcResize コンポーネント
    - リサイズポリシー

[Visual Basic]
Imports GrapeCity.Win.Components
Imports GrapeCity.Win.Editors

Public Class InputManListBoxResizePolicy
  Inherits ResizePolicy

  Public Overrides ReadOnly Property TargetType() As Type
    Get
      Return GetType(GcListBox)
    End Get
  End Property

  Public Overrides Sub ResizeLayout(control As Control, infos As ResizeLayoutInfo)
    Try
      Dim listBox As GcListBox = TryCast(control, GcListBox)
      If listBox IsNot Nothing AndAlso listBox.Columns IsNot Nothing Then
        ' change all columns' width.
        For Each column As ListColumn In listBox.Columns
          Dim oldWidth As Integer = column.Width
          column.Width = infos.ScaleX(oldWidth)
        Next
      End If
    Catch
    End Try
    MyBase.ResizeLayout(control, infos)
  End Sub
End Class


[C#]
using GrapeCity.Win.Components;
using GrapeCity.Win.Editors;

public class InputManListBoxResizePolicy : ResizePolicy
{
  public override Type TargetType
  {
    get { return typeof(GcListBox); }
  }

  public override void ResizeLayout(Control control, ResizeLayoutInfo infos)
  {
    try
    {
      GcListBox listBox = control as GcListBox;
      if (listBox != null && listBox.Columns != null)
      {
        // change all columns' width.
        foreach (ListColumn column in listBox.Columns)
        {
          int oldWidth = column.Width;
          column.Width = infos.ScaleX(oldWidth);
        }
      }
    }
    catch
    {
    }
    base.ResizeLayout(control, infos);
  }
}
関連情報