スマートタグのおかしな振る舞いのその2です。よろしくお願いします。
下のコードにより、Formにもスマートタグを付けることができます。問題は、フォームのサイズ変更やデザイン面のスクロールなどを行うと、スマートタグのハンドル(三角印の小ボタン)が消えてしまうことです。Form1のデザイン面を一旦閉じて、再度それを開くとハンドルも正常に現れます。
.NETのバグかとも思われますが、どなたか回避策をアドバイスいただけたら幸いです。
※ System.Designを参照に追加してください。
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Drawing.Printing;
using System.Collections;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Data;
using System.Diagnostics;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Text;
using System.Runtime.InteropServices;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.Reflection;
using System.Windows.Forms.Design.Behavior;
using System.Diagnostics.CodeAnalysis;
namespace WindowsApplication3
{
public partial class Form1 : MyForm
{
public Form1()
{
InitializeComponent();
}
}
public class MyForm : Form
{
DesignerActionService designerActionService;
IDesignerHost designerHost;
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
SetupSmartTag();
}
void SetupSmartTag()
{
if (Site != null)
{
designerActionService = Site.GetService(typeof(DesignerActionService)) as DesignerActionService;
designerHost = Site.GetService(typeof(IDesignerHost)) as IDesignerHost;
if((designerActionService != null) && (designerHost != null))
{
designerActionService.Add(this, new MyForm_ActionList(designerHost.GetDesigner(this) as ComponentDesigner));
}
}
}
}
public class MyForm_ActionList : DesignerActionList
{
ComponentDesigner designer;
public MyForm_ActionList(ComponentDesigner _designer) : base(_designer.Component)
{
designer = _designer;
}
public void SayHello()
{
MessageBox.Show("ハローワールド!!");
}
public override DesignerActionItemCollection GetSortedActionItems()
{
DesignerActionItemCollection items = new DesignerActionItemCollection();
items.Add(new DesignerActionMethodItem(this, "SayHello", "ハロー","","説明文その1",true));
return items;
}
}
}