CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2008
    Posts
    154

    [RESOLVED] TabControl selectedIndex 1 with colorDialog

    weird bug - not sure what I am doing wrong
    dragged a ColorDialog from the toolbox to the form...

    I have a TabControl for my form. Tab 0 and Tab 1, as long as I am on selectIndex 0, if I open my colorDialog it works fine. If I switch to selectedIndex 1 and open my colorDialog, program crashes. I've done this too..

    Code:
            private void buttonSetColor_Click(object sender, EventArgs e)
            {
                tabControl.SelectedIndex = 0;
                colorDialog.ShowDialog();
            }
    works great.. but for this situation I don't want to have to make it switch tabs just because I want to bring up the colorDialog. This code > if selectedIndex 1 - crashes my form

    Code:
            private void buttonSetColor_Click(object sender, EventArgs e)
            {
                colorDialog.ShowDialog();
            }
    weird?!?

  2. #2
    Join Date
    Jun 2008
    Posts
    6

    Re: TabControl selectedIndex 1 with colorDialog

    I just tried with the following code by adding tabcontrol and a color dialog with VisualStudio-2005 and .Net Framework 2.0

    Irrespective of the selected index of the tabcontrol( 0/1 ) the color dialog opens fine.

    Can you please let us know the visual studio and framework version which you are using ?

    Thanks

    Murali

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: TabControl selectedIndex 1 with colorDialog

    Check out what the control the colorDialog is a child of. Is it the main form? Is it the tabcontrol? Is it a page or a panel inside the tab control?

  4. #4
    Join Date
    Jun 2008
    Posts
    154

    Re: TabControl selectedIndex 1 with colorDialog

    @ rockmurali - im using 4.0 Framework
    @ arjay - thanks you gave me some ideas: but I don;t know how to check the control for a child control so I just dragged another ColorDialog directly onto Tab 1, and named it colorDialogTab1 - and this still does not work. Additionally I've tried dragging the colorDialog directly onto the main form.

    I am not doing anything but ShowDialog(), so there are no hidden dependencies... I will open a new project and test this again.

  5. #5
    Join Date
    Jun 2008
    Posts
    154

    Re: TabControl selectedIndex 1 with colorDialog

    @ rockmurali, yeh started new project used many different combinations of adding the colorDialog to the form and it all works. There must be something deep in the form that is causing this. Additionally when I switch tabs some of my labels are black transparent boxes, meaning where that label is located; I can see the previous Tab behind it. This goes away when I move the form.

    I've decided to create a new project, and just port most of the code over while 1st creating the structure of the form environment. I hope this solves it.

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: TabControl selectedIndex 1 with colorDialog

    Quote Originally Posted by bixel View Post
    @ arjay - thanks you gave me some ideas: but I don;t know how to check the control for a child control so I just dragged another ColorDialog directly onto Tab 1, and named it colorDialogTab1 - and this still does not work.
    You can open the designer file. Right click on the myform.designer.cs and choose view code. To find what the colorDialog1 control's parent, just search for it's name in the file and look for the like that says .AddControl( colorDialog1 ).

    I might be off a bit on the naming, but you get the idea.

  7. #7
    Join Date
    Jun 2008
    Posts
    154

    Re: TabControl selectedIndex 1 with colorDialog

    Even creating a new project did not work. I tested with a simple project and works fine.. However as soon as I add more Dialogs to the main Form, colorDialog get hidden somewhere when I try to fire it.
    I've added a TimerControl, ContextMenu, MenuStrip, Tooltip, and another ContextMenu as my added components.

    I've completely got rid of TabControl by this point. And my set color button is on the main form. But when I click it the form flashes like its opening colorDialog, but there is nothing there. I have to stop debugging to close the main Form.

    I've also tried this
    Code:
                foreach (Control c in this.Controls)
                {
                    if (c.Name == "colorDialog")
                    {
                        c.Show();
                        c.BringToFront();
                    }
                }
    but that doesn't work since colorDialog is not a control....
    not sure what to do here.

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: TabControl selectedIndex 1 with colorDialog

    Did you try what I suggested in post #6?

  9. #9
    Join Date
    Jun 2008
    Posts
    154

    Re: TabControl selectedIndex 1 with colorDialog [SOLVED]

    Arjay: yes checked and double checked

    I found the problem!!! I had a Picture box with a custom Paint command. It seemed it was try to paint waaay too many times. So I slowed it down with a Control Timer

    Code:
            void FormMain_Load(object sender, EventArgs e)
            {
                    controlTimer.Tick += new EventHandler(controlTimer_Tick);
                    controlTimer.Enabled = true;
                    controlTimer.Interval = 17; //about 60 FPS
                    ....
                    other code
            }
    
            void controlTimer_Tick(object sender, EventArgs e)
            {
                frameCount = ++frameCount % 6;
                pictureBoxNPCSprite_Paint();
            }
    This solved it perfectly!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured