Top / .NET備忘録 / 06.ContextMenu / 07.VBContextMenuStrip その(4)

OnOpening をオーバーライドして、表示を切り替えます。

        protected override void OnOpening(System.ComponentModel.CancelEventArgs e)
        {
            // インスタンスを退避する 
            m_Owner = (IVBContextMenuTarget)this.SourceControl;
 
            // IME 関連の表示切り替え
 
            bool imeVisible = m_Owner.ImeMode != ImeMode.Disable;
            m_ItemIMEVar.Visible = imeVisible;
            
            m_ItemIMEOpenClose.Visible = imeVisible;
            if (m_Owner.ImeOpenStatus)
                m_ItemIMEOpenClose.Text = "IME を閉じる(&L)";
            else
                m_ItemIMEOpenClose.Text = "IME を開く(&O)";
 
            // 再変換をサポートしない IME では表示しない
            m_ItemIMEReconvert.Visible = imeVisible && IsSupportIME(IGP_SETCOMPSTR, SCS_CAP_SETRECONVERTSTRING);
 
            if (m_Owner.ReadOnly)
            {
                // 読み取り専用のとき、Copy, SelectAll 以外を不可にする
 
                m_ItemUndo.Enabled = false;
                m_ItemCut.Enabled = false;
                m_ItemCopy.Enabled = (m_Owner.SelectionLength > 0);
                m_ItemPaste.Enabled = false;
                m_ItemDelete.Enabled = false;
                m_ItemSelectAll.Enabled = (m_Owner.SelectionLength < m_Owner.Text.Length);
                m_ItemIMEOpenClose.Enabled = false;
                m_ItemIMEReconvert.Enabled = false;
            }
            else
            {
                // 通常モード
 
                m_ItemUndo.Enabled = m_Owner.CanUndo;
                m_ItemCut.Enabled = (m_Owner.SelectionLength > 0);
                m_ItemCopy.Enabled = (m_Owner.SelectionLength > 0);
 
                IDataObject data = Clipboard.GetDataObject();
                if (data != null && data.GetDataPresent(DataFormats.Text))
                    m_ItemPaste.Enabled = true;
                else
                    m_ItemPaste.Enabled = false;
 
                m_ItemDelete.Enabled = (m_Owner.SelectionLength > 0);
                m_ItemSelectAll.Enabled = (m_Owner.SelectionLength < m_Owner.Text.Length);
                m_ItemIMEOpenClose.Enabled = true;
                m_ItemIMEReconvert.Enabled = (m_Owner.SelectionLength > 0);
            }
            base.OnOpening(e);
        }



トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   最終更新のRSS
Last-modified: 2013-03-16 (土) 03:25:28 (1683d)