アプリ版:「スタンプのみでお礼する」機能のリリースについて

こんにちは。
C#+.NetFramework環境です。

PropertyGridを使っているのですが、縦方向のグリッド線の位置をプログラムから変更する方法はあるのでしょうか?

A 回答 (1件)

 こんばんは。


 PropertyGridの幅を調整するという事だと思いますが、MoveSplitter()メソッドで出来るそうです。
 http://social.msdn.microsoft.com/Forums/ja-JP/ne …

 ただし、このMoveSplitter()メソッドが、非公開メソッドである為、無理矢理呼び出す為に、リフレクションを使用するのだそうです。
 URLの内容が、C++/CLIですので、C#で書いて試して見ましたが、位置が変わります。以下参考程度に。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.propertyGrid1.SelectedObject = this;
}

private void Form1_Load(object sender, EventArgs e)
{
this.SetDividerWidth(this.propertyGrid1, 80);
}

private void SetDividerWidth(PropertyGrid grid, int width)
{
Type type = grid.GetType();
System.Reflection.FieldInfo info = type.GetField("gridView", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (info == null) return;

Object gridView = info.GetValue(grid);
if (gridView == null) return;

Type gridType = gridView.GetType();
System.Reflection.MethodInfo mInfo = gridType.GetMethod("MoveSplitterTo" , System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if(mInfo == null)return;

Object[] paramArray = new Object[]{width};
mInfo.Invoke(gridView, paramArray);
}
}
}

この回答への補足

こんにちは、ソースまで書いていただき、ありがとうございます。
非公開メンバというところが悩ましいところですね・・・。

補足日時:2009/12/14 16:26
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!