Window inside a Window with thread? without thread ?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Window inside a Window with thread? without thread ?

  1. #1
    Join Date
    Dec 2009
    Posts
    34

    Question Window inside a Window with thread? without thread ?

    I did like some advices on this little project i am trying to do so i will start explainning a little what it is.

    What i am planning to do is a 2 windows application where the first window will hold configurations, database edition, etc... and the second window will display the information of something when you have your mouse over it.

    So right now what i am trying to do is something really basic... First something i am not sure about is how should i create this second window.

    Should i just create the new form in the public autox function and then reuse it on the thread process or should i create it inside the thread ? but then again if i create it inside the thread how should i manage it ?

    Here is a little sample of my main window, it has no content but the checkbox that begins false and changes to true once u check it.

    then you can see that i am defining and calling my thread and it is function which what i wanted to do with that function basicly is if the checkBox is check the window will be display if it is uncheck it will hide.

    But since on the future i will have data being updated in there and that data will be called after reading another process i tought that it did be better having it on a thread so i could still do or manage other stuffs within the application.
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Threading;
    
    namespace AutoX
    {
        public partial class AutoX : Form
        {
            bool run = true;
            Thread WindowShowHide;
    
            public AutoX()
            {
                InitializeComponent();
    
                WindowShowHide = new Thread(new ThreadStart(WindowInfo));
                WindowShowHide.Start();
            }
    
            public void WindowInfo()
            {
                while (run == true)
                {
                    if (iOnMouseBox.ThreeState == false)
                    {
                        ShowItem.Show();
                    }
                    else
                    {
                        ShowItem.Hide();
                    }
                }
            }
        }
    }
    Here is my second window which at the momment has no content... i just want to be able to do what i said above
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace AutoX
    {
        public partial class ShowItem : Form
        {
            public ShowItem()
            {
                InitializeComponent();
            }
        }
    }
    looking forward to any tips, advices etc ...

    Even if i am doing something wrong if you can atleast point me on the right direction it would be awesome.

    Thanks in advance.

    PS if u need any additional code please let me know and i will post here.

  2. #2
    Join Date
    Dec 2009
    Posts
    34

    Re: Window inside a Window with thread? without thread ?

    After some test i've noticed a few mistakes and did some new changes but still i am sure i am doing things wrong and would love some guidance...

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Threading;
    
    namespace AutoX
    {
        public partial class AutoX : Form
        {
            bool run = true;
            Thread WindowShowHide;
            private Form sItem;
    
            public AutoX()
            {
                InitializeComponent();
    
                sItem = new ShowItem();
    
                WindowShowHide = new Thread(new ThreadStart(WindowInfo));
                WindowShowHide.Start();
            }
    
            public void WindowInfo()
            {
                while (run == true)
                {
                    if (iOnMouseBox.Checked == true)
                    {
                        if (sItem.Visible == false)
                        {
                            sItem.Show();
                        }
                    }
                    else
                    {
                        if (sItem.Visible == true)
                        {
                            sItem.Hide();
                        }
                    }
                }
            }
        }
    }
    So i've implemented the check for if the window is visible or not with the methods to show, hide it... now it works as it should but the window gets overloaded and i can't move it or whatever and i think it is because of my thread maybe ? not sure ...

    I am still working that out ... but if you have a better way for me to do it i would like to hear it...

    The window it opens, get updated with data very often and i am using thread so i can update that window without having my entire windows loaded with whiles etc ...

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

    Re: Window inside a Window with thread? without thread ?

    Generally you'll want to keep the UI in the main thread and use worker threads to send data to the controls in the main thread.

    See http://msdn.microsoft.com/en-us/libr...28(VS.80).aspx

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center