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

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

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

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

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

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

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

Public Class InputManComboBoxResizePolicy
  Inherits ResizePolicy

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

  Public Overrides Sub ResizeLayout(control As Control, infos As ResizeLayoutInfo)
    Try
      Dim comboBox As GcComboBox = TryCast(control, GcComboBox)
      If comboBox IsNot Nothing AndAlso comboBox.ListColumns IsNot Nothing Then
        ' change all columns' width.
        For Each column As ListColumn In comboBox.ListColumns
          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 InputManComboBoxResizePolicy : ResizePolicy
{
  public override Type TargetType
  {
    get { return typeof(GcComboBox); }
  }

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