やってみる

アウトプットすべく己を導くためのブログ。その試行錯誤すらたれ流す。

Eto.Forms.TextControlを継承できなかった

 これでTextAreaの右クリックメニューを消せるかと思ったのだが、そもそも継承できなかった。

成果物

f:id:ytyaru:20181221201814p:plain

対象環境

前回まで

 TextAreaで右クリックするとコンテキストメニューが自動で出る。これを削除したいが、できなかった。TextAreaを継承しても上書きできなかった。

今回

 TextAreaでなくその親であるTextControlを継承してみたらどうなるか試してみた。結果、そもそも継承できなかった。

using System;
using Eto.Forms;
using Eto.Drawing;

namespace ExtendTextControl
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            Title = "Extend TextControl";
            ClientSize = new Size(400, 350);
            //TextControl textcontrol = new TextControl(); // abstract class
            TextControl2 textcontrol2 = new TextControl2();
            DynamicLayout layout = new DynamicLayout();
            //layout.Add(textcontrol);
            layout.Add(textcontrol2);
            Content = layout;
        }
    }
}
using System;
using Eto.Forms;

namespace ExtendTextControl
{
    public class TextControl2 : TextControl
    {
        public TextControl2() : base()
        {
        }
    }
}

 ターミナルを起動し、実行ファイルを実行すると以下のエラー。

Unhandled Exception:
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: Type for 'ExtendTextControl.TextControl2' could not be found in this platform

 TextAreaTextControlを参照し、真似をして以下のように変更した。

using System;
using Eto;
using Eto.Forms;
using Eto.IO;

namespace ExtendTextControl
{
    [Handler(typeof(TextControl2.IHandler))]
    public class TextControl2 : TextControl
    {
        new IHandler Handler { get { return (IHandler)base.Handler; } }
        static TextControl2() {}
    }
}

 実行すると同様のエラー。