Click here to Skip to main content
15,904,823 members
Home / Discussions / C#
   

C#

 
QuestionToolStrip Background Color -- How do I make it the default color? Pin
Susan Crayne16-Jun-10 5:50
Susan Crayne16-Jun-10 5:50 
AnswerRe: ToolStrip Background Color -- How do I make it the default color? Pin
Adam R Harris16-Jun-10 6:40
Adam R Harris16-Jun-10 6:40 
GeneralRe: ToolStrip Background Color -- How do I make it the default color? Pin
Susan Crayne16-Jun-10 7:29
Susan Crayne16-Jun-10 7:29 
GeneralRe: ToolStrip Background Color -- How do I make it the default color? Pin
Adam R Harris16-Jun-10 8:35
Adam R Harris16-Jun-10 8:35 
GeneralRe: ToolStrip Background Color -- How do I make it the default color? Pin
Susan Crayne16-Jun-10 10:37
Susan Crayne16-Jun-10 10:37 
GeneralRe: ToolStrip Background Color -- How do I make it the default color? Pin
Adam R Harris16-Jun-10 12:17
Adam R Harris16-Jun-10 12:17 
GeneralRe: ToolStrip Background Color -- How do I make it the default color? Pin
Susan Crayne17-Jun-10 7:41
Susan Crayne17-Jun-10 7:41 
GeneralRe: ToolStrip Background Color -- How do I make it the default color? Pin
Susan Crayne17-Jun-10 9:56
Susan Crayne17-Jun-10 9:56 
Questionbest way for onlne meeting Pin
Jassim Rahma16-Jun-10 5:10
Jassim Rahma16-Jun-10 5:10 
AnswerRe: best way for onlne meeting Pin
Ravi Bhavnani16-Jun-10 6:09
professionalRavi Bhavnani16-Jun-10 6:09 
AnswerRe: best way for onlne meeting Pin
Luc Pattyn16-Jun-10 6:22
sitebuilderLuc Pattyn16-Jun-10 6:22 
Questionanalog clock Pin
Jassim Rahma16-Jun-10 5:05
Jassim Rahma16-Jun-10 5:05 
AnswerRe: analog clock Pin
Johnny J.16-Jun-10 5:10
professionalJohnny J.16-Jun-10 5:10 
GeneralRe: analog clock Pin
Jassim Rahma16-Jun-10 5:53
Jassim Rahma16-Jun-10 5:53 
GeneralRe: analog clock Pin
Johnny J.16-Jun-10 6:06
professionalJohnny J.16-Jun-10 6:06 
QuestionURGENT HELP PLZ: many erros!!! Pin
Jassim Rahma16-Jun-10 4:06
Jassim Rahma16-Jun-10 4:06 
AnswerRe: URGENT HELP PLZ: many erros!!! Pin
harold aptroot16-Jun-10 4:13
harold aptroot16-Jun-10 4:13 
AnswerRe: URGENT HELP PLZ: many erros!!! Pin
Luc Pattyn16-Jun-10 4:16
sitebuilderLuc Pattyn16-Jun-10 4:16 
AnswerRe: URGENT HELP PLZ: many erros!!! Pin
Abhinav S16-Jun-10 4:20
Abhinav S16-Jun-10 4:20 
QuestionDirectshow problem Pin
TimSWatson16-Jun-10 3:32
TimSWatson16-Jun-10 3:32 
AnswerRe: Directshow problem Pin
TheyCallMeMrJames16-Jun-10 4:37
TheyCallMeMrJames16-Jun-10 4:37 
GeneralRe: Directshow problem Pin
Eduard Keilholz16-Jun-10 4:51
Eduard Keilholz16-Jun-10 4:51 
QuestionOwnerDrawn TabControl behaving differently in Design Mode [modified] [solved] Pin
TheFoZ16-Jun-10 3:11
TheFoZ16-Jun-10 3:11 
Hi All.

I have been developing my own OwnerDrawn TabControl so I can have a close button on the right hand side of the tab. All was going well thanks to some of the articles on CP and now it has stopped working in Design mode. When the control is used in the test form when the app is running, everything works as expected. In design mode I cannot switch tabs to add controls to them. Any ideas?

public class ClosableTabCtrl : TabControl
{
#region Private Members
    private System.Windows.Forms.ImageList buttonImageList;

    private bool showCloseButton = true;
    private bool hideCloseButtonWhenOnlyOneTab;

    private const string tabText = "      ";

    private int buttonImageIndex;
#endregion

    public ClosableTabCtrl() : base()
    {
        buttonImageList = new ImageList();

        buttonImageList.Images.Add((Image)new Bitmap(Resources.InactiveCross));
        buttonImageList.Images.Add((Image)new Bitmap(Resources.ActiveCross));
        buttonImageList.Images.Add((Image)new Bitmap(Resources.ClickedCross));

        this.DrawMode = TabDrawMode.OwnerDrawFixed;
        this.DrawItem += new DrawItemEventHandler(ClosableTabCtrl_DrawItem);

        this.MouseMove += new MouseEventHandler(ClosableTabCtrl_MouseMove);
        this.MouseLeave += new EventHandler(ClosableTabCtrl_MouseLeave);
        this.MouseClick += new MouseEventHandler(ClosableTabCtrl_MouseClick);
        this.MouseDown += new MouseEventHandler(ClosableTabCtrl_MouseDown);
        this.MouseUp += new MouseEventHandler(ClosableTabCtrl_MouseUp);

        SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
        SetStyle(ControlStyles.AllPaintingInWmPaint, true);
    }

    void ClosableTabCtrl_MouseUp(object sender, MouseEventArgs e)
    {
        if (MouseIsOverButton(e) && buttonImageIndex != 1)
        {
            buttonImageIndex = 1;
            this.Invalidate();
        }
    }

    void ClosableTabCtrl_MouseDown(object sender, MouseEventArgs e)
    {
        if (MouseIsOverButton(e) && buttonImageIndex != 2)
        {
            buttonImageIndex = 2;
            this.Invalidate();
        }
    }

    void ClosableTabCtrl_MouseClick(object sender, MouseEventArgs e)
    {
        if (MouseIsOverButton(e))
        {
            // TODO: raise the event
        }

    }

    void ClosableTabCtrl_MouseLeave(object sender, EventArgs e)
    {
        if (buttonImageIndex != 0)
        {
            buttonImageIndex = 0;
            this.Invalidate();
        }
    }

    void ClosableTabCtrl_MouseMove(object sender, MouseEventArgs e)
    {
        if (MouseIsOverButton(e))
        {
            if (buttonImageIndex != 1)
            {
                buttonImageIndex = 1;
                this.Invalidate();
            }
        }
        else
        {
            if (buttonImageIndex != 0)
            {
                buttonImageIndex = 0;
                this.Invalidate();
            }
        }
    }

    public bool ShowCloseButton
    {
        get { return showCloseButton; }
        set { showCloseButton = value; }
    }

    public bool HideCloseButtonWhenOnlyOneTab
    {
        get { return hideCloseButtonWhenOnlyOneTab; }
        set { hideCloseButtonWhenOnlyOneTab = value; }
    }

    bool MouseIsOverButton(MouseEventArgs e)
    {
        Rectangle r = this.GetTabRect(this.SelectedIndex);
        r.Offset(2, 2);
        Rectangle b = new Rectangle(new Point(r.X + (this.GetTabRect(this.SelectedIndex).Width - 20), this.GetTabRect(this.SelectedIndex).Height / 2 - 7),
                                    new Size(17, 17));

        if (b.Contains(e.Location))
        {
            return true;
        }
        else
        {
            return false;
        }
    }


    void ClosableTabCtrl_DrawItem(object sender, DrawItemEventArgs e)
    {
        Rectangle r = this.GetTabRect(e.Index);
        string title = String.Empty;

        r.Offset(2, 2);
        Brush TitleBrush = new SolidBrush(Color.Black);
        Font f = this.Font;

        if (e.State == DrawItemState.Selected)
        {
            if (!this.TabPages[e.Index].Text.EndsWith(tabText))
            {
                this.TabPages[e.Index].Text += tabText;
            }
            title = this.TabPages[e.Index].Text + tabText;


            if (showCloseButton)
            {
                if (!(this.hideCloseButtonWhenOnlyOneTab && this.TabPages.Count == 1))
                {
                    e.Graphics.DrawImage(buttonImageList.Images[buttonImageIndex],
                                         new Point(r.X + (this.GetTabRect(e.Index).Width - 20),
                                             this.GetTabRect(e.Index).Height / 2 - 7));
                }
            }
        }
        else
        {
            if (this.TabPages[e.Index].Text.EndsWith(tabText))
            {
                this.TabPages[e.Index].Text = this.TabPages[e.Index].Text.Replace(tabText, string.Empty);
            }

            title = this.TabPages[e.Index].Text + tabText;
        }
        // center the text in the tab
        e.Graphics.DrawString(title, f, TitleBrush, new PointF(r.X, (r.Height - f.Height) / 2 + 1));

        TitleBrush.Dispose();
    }
}


Thanks in advance.
The FoZ
modified on Wednesday, June 16, 2010 11:46 AM

AnswerRe: OwnerDrawn TabControl behaving differently in Design Mode Pin
Johnny J.16-Jun-10 3:49
professionalJohnny J.16-Jun-10 3:49 
GeneralRe: OwnerDrawn TabControl behaving differently in Design Mode Pin
TheFoZ16-Jun-10 4:32
TheFoZ16-Jun-10 4:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.