문제

가 winform 는 tabcontrols 있는 3 개의 층이 깊다.나 동적으로 착색 탭 아래 클래스입니다.가 때로 색상이 포함된 tabcontrol 그것은 피치합니다.

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

나는 뭔가를 해야 할 다른 사람들을 위해?면 나는 주석으로 포함된 형태로 전화하 tabRenderer 다음을 받지 않습니다 이런 오류가 있습니다.나지 않 폐기 내 TabRenderer 개체 제대로?

그것은 어쩌면 완전히 다른 무언가?The way I am embeding 탭 컨트롤?

의 예 내 프로그램에는 현재 다음과 같은 여기-->


(출처: ggpht.com)
DevFiles

당신이 볼 수 있는 3 층의 탭을 제어합니다.이 두 번 발생 프로그램에서 모두 발생 언급된 오류가 있습니다.6 호출 tabRenderer 서 총 5 탭을 제어합니다.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);
    }
도움이 되었습니까?

해결책

좋아,내가 대답하되 나 자신의 질문입니다.(좀)

내가 믿고 무슨 일이 일어나고 있었던 것으로 내용을 로 시작하는 발사 떨어져 각각의 양식 로드()이벤트에 화재의 임베디드 양식 로드()이벤트 및니다.가를 던 내 전화 TabRenderer 에서드 이벤트가 내가 이해하지 못하는 일이 일어나고 있었다.좋아하는 호출을 PaintTabs()함수 및 다음을 기다리는 첫 번째를 완료하기 전에 호출을 다음(내가 생각하는가?).

어느 쪽이든 그것을 발생시키지 않습니다 어떤 오류가 있습니다.지금은 그것과 같이에서 최고 수준 TabControl:

        public void PaintTabs()
    {
        new psTabRenderer(tclWWCModuleHost, Color.LightSteelBlue, Color.Khaki, Color.Black, Color.Black);
        FrmWwcMemberHost.PaintTabs();
        FrmWwcMcpHost.PaintTabs();
        FrmCaseNotes.PaintTabs();
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top