0

3層の深さのタブコントロールを持つwinformアプリがあります。以下のクラスでタブを動的に色付けしています。埋め込まれたタブコントロールに色を付けると、フィット感が増します。

A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.Windows.Forms.dll

それらのために何か違うことをする必要がありますか?tabRenderer への埋め込みフォームの呼び出しをコメントアウトすると、これらのエラーは発生しません。TabRenderer オブジェクトを適切に破棄していませんか?

それはおそらくまったく別のものですか?タブコントロールを埋め込む方法は?

私のプログラムが現在どのように見えるかの例はここにあります -->


(ソース: ggpht.com )
DevFilesより

ご覧のとおり、タブ コントロールには 3 つのレイヤーがあります。これはプログラムで 2 回発生し、両方とも前述のエラーが発生します。5 つのタブ コントロールがあるため、合計 6 回の tabRenderer の呼び出しがあります。1 つのトップ レベル、3 つのセカンド レベル、および 2 つのサード レベル。

タブ コントロールの色付けに使用されているコード:

public class psTabRenderer
{
    private TabControl _tabControl;
    private Color _fillColor;
    private Color _selectedFillColor;
    private Color _textColor;
    private Color _selectedTextColor;

    public psTabRenderer(TabControl tabControl, Color fillColor, Color selectedFillColor, Color textColor, Color selectedTextColor)
    {
        _tabControl = tabControl;
        _fillColor = fillColor;
        _selectedFillColor = selectedFillColor;
        _textColor = textColor;
        _selectedTextColor = selectedTextColor;

        _tabControl.DrawMode = TabDrawMode.OwnerDrawFixed;
        _tabControl.DrawItem += TabControlDrawItem;
    }

    private void TabControlDrawItem(object sender, DrawItemEventArgs e)
    {
        TabPage currentTab = _tabControl.TabPages[e.Index];
        Rectangle itemRect = _tabControl.GetTabRect(e.Index);
        var fillBrush = new SolidBrush(_fillColor);
        var textBrush = new SolidBrush(_textColor);
        var sf = new StringFormat
        {
            Alignment = StringAlignment.Center,
            LineAlignment = StringAlignment.Center
        };

        //If we are currently painting the Selected TabItem we'll
        //change the brush colors and inflate the rectangle.
        if (Convert.ToBoolean(e.State & DrawItemState.Selected))
        {
            fillBrush.Color = _selectedFillColor;
            textBrush.Color = _selectedTextColor;
            itemRect.Inflate(2, 2);
        }

        //Set up rotation for left and right aligned tabs
        if (_tabControl.Alignment == TabAlignment.Left || _tabControl.Alignment == TabAlignment.Right)
        {
            float rotateAngle = 90;
            if (_tabControl.Alignment == TabAlignment.Left)
                rotateAngle = 270;
            var cp = new PointF(itemRect.Left + (itemRect.Width / 2), itemRect.Top + (itemRect.Height / 2));
            e.Graphics.TranslateTransform(cp.X, cp.Y);
            e.Graphics.RotateTransform(rotateAngle);
            itemRect = new Rectangle(-(itemRect.Height / 2), -(itemRect.Width / 2), itemRect.Height, itemRect.Width);
        }

        //Next we'll paint the TabItem with our Fill Brush
        e.Graphics.FillRectangle(fillBrush, itemRect);

        //Now draw the text.
        e.Graphics.DrawString(currentTab.Text, e.Font, textBrush, (RectangleF)itemRect, sf);

        //Reset any Graphics rotation
        e.Graphics.ResetTransform();

        //Finally, we should Dispose of our brushes.
        fillBrush.Dispose();
        textBrush.Dispose();
    }
}

そして、これは私がそれを呼ぶ方法です:

        private void frmMCPEmployment_Load(object sender, EventArgs e)
    {
        FormPaint();
    }

    public void FormPaint()
    {
        // ToDo: This call to the Tab Renderer is throwing a Win32 "Error Creating Window Handle" 
        new psTabRenderer(tclEmployment, Color.LightSteelBlue, Color.Khaki, Color.Black, Color.Black);
    }
4

1 に答える 1

0

わかりました、私は自分の質問に答えました。

アプリがロードされると、各 Forms Load() イベントが発生し始め、それが埋め込まれた Forms Load() イベントなどを発生させることが起こっていたと思います。ロード イベントで TabRenderer への呼び出しをスローしましたが、理解できないことが起こっていました。私はその呼び出しを PaintTabs() 関数に引き出し、最初の呼び出しが終了するのを待ってから、次の呼び出しを呼び出します(と思いますか?)。

いずれにしても、エラーは発生しなくなりました。TOP LEVEL TabControl から次のように呼び出します。

        public void PaintTabs()
    {
        new psTabRenderer(tclWWCModuleHost, Color.LightSteelBlue, Color.Khaki, Color.Black, Color.Black);
        FrmWwcMemberHost.PaintTabs();
        FrmWwcMcpHost.PaintTabs();
        FrmCaseNotes.PaintTabs();
    }
于 2009-05-21T20:22:22.810 に答える