سؤال

لدي تطبيق WinForm يحتوي على TabControls التي هي 3 طبقات عميقة. أنا تلوين علامات التبويب ديناميكيا مع الطبقة التالية. عندما يذهب إلى لون tabcontrol المدمج فإنه ينظر إلى حد ما.

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

هل أحتاج إلى القيام بشيء مختلف بالنسبة لأولئك؟ إذا قمت بإجراء مكالمات النماذج المضمنة إلى Tabroenderer، فلن أحصل على هذه الأخطاء. أنا لست التخلص من كائن تبادلدر الخاص بي بشكل صحيح؟

هل ربما ربما شيء آخر تماما؟ الطريقة التي أضمها عناصر التحكم في علامة التبويب؟

مثال على ما يبدو عليه برنامجي حاليا هو هنا ->


(مصدر: ggpht.com.)
من devfiles.

كما ترون أن هناك 3 طبقات من عناصر التحكم في علامة التبويب. يحدث هذا مرتين في البرنامج ويسبب كلاهما الخطأ المذكور. هناك 6 مكالمات إلى Tabroenderer في المجموع نظرا لأن هناك عناصر تحكم 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);
    }
هل كانت مفيدة؟

المحلول

حسنا، أجبت على سؤالي الخاص. (كيندا)

أعتقد أن ما حدث كان أنه حيث يتم تحميل تطبيقي، فإنه يبدأ بإطلاق حدوث إخراج كل نماذج الحمل () الذي يقوم بدوره حرائق من حدث تحميل النماذج المضمنة () وهلم جرا. لقد ألقيت مكالمتي إلى Tabroenderer في حدث التحميل وشيء لا أفهمه كان يحدث. لقد قمت بسحب تلك الدعوة إلى وظيفة Paintabs () ثم انتظر أول من ينتهي قبل أن تستدعي التالي (أعتقد؟).

وفي كلتا الحالتين لم تعد تنشئ أي أخطاء. أنا الآن اتصل به كما هو الحال من المستوى الأعلى 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