Results 1 to 9 of 9

Thread: static box at design time

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    35

    static box at design time

    this is probably a stupid question....but how do you make an object ... say a combobox static at design time? (in the design tab)

    i must be missing something but i can't see any option for it

    J

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    You have to do it in the code. When you add the combobox to your form, look where its declared and just add the static keyword to it.
    Dont gain the world and lose your soul

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Would that even work? What's the use of it?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    35
    DevGrp: thanks.....i was looking for a way around having to impliment it in the code....just being lazy i guess...oh well

    bee: i need to be able to manipulate the selectedItem property from within static methods and since it was created at design time i can't reference the instance ... at least i don't think i can

    cheers for the help and the speedy replies

    J

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Sounds like you should rethink your code design. Why do you need to reference it from static methods?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    35
    well.......

    I have a browser, pretty much exactly the same as ie, i have a separate thread that runs to evaluate the "mood" of a document that is being displayed by the browser. This has to be on a different thread because depending ong the machine learning technique that the user has chose, it can take a while to learn anything, and the desire was to have a browser that didn't interrupt the user with long delays. Once the machine learning techniques have made a desicion it calls a method in my original file to tell the combobox to change to reflect this discovery. It also sets a lable to show the percentage certanty that it has chosen the right mood.

    There is a lot more to it....but this is what i think you want to know

    If there's an easier way to reference methods across files and threads i'd love to know about it

    J

  7. #7
    Hyperactive Member Scott Penner's Avatar
    Join Date
    Dec 2000
    Location
    Mountain View
    Posts
    327
    There are a few things you could do.

    You could pass the mood class a reference to the combo box after it has been created. But, it might be more appropriate to fire an event from the mood class that the combo box class consumes.

    I believe this should work accross thread as long as you synchronize access to the combo box.
    -scott
    he he he

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Sounds very interesting.

    But take heed of this remark in the documentation of the Control class:
    Note There are four methods on a control that are safe to call from any thread: Invoke, BeginInvoke, EndInvoke, and CreateGraphics. For all other method calls, you should use one of the invoke methods to marshal the call to the control's thread.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9
    Hyperactive Member Scott Penner's Avatar
    Join Date
    Dec 2000
    Location
    Mountain View
    Posts
    327

    for instance...

    This should work.
    The worker class has a single method that takes a reference to a textbox control and starts a worker thread to pause for 5 seconds then append text to the text box.
    The code in the form simply creates the class and passes a reference to a created textbox control into the DoWork method.

    Worker Class
    PHP Code:
    public delegate void UpdateText(string NewText);

    public class 
    Worker
    {
        public 
    Worker()
        {
            
    // nothing to do
        
    }

        public 
    void DoWork(System.Windows.Forms.TextBox ReferencedBox)
        {
            
    // Put the work in the thread pool queue
            
    ThreadPool.QueueUserWorkItem(new WaitCallback(this.DoWorkAsync),ReferencedBox);
        }

        private 
    void DoWorkAsync(object state)
        {
            
    // Sleep for 5 seconds
            
    Thread.Sleep(5000);

            
    // Put in catch block in case object is not textbox type
            
    try
            {
                
    TextBox TempText = (TextBox)state;

                
    // Invoke the append text method via the updatetext delegate
                
    TempText.Invoke(new UpdateText(TempText.AppendText),new object[] {DateTime.Now.ToShortDateString()});
            }
            catch{}

        }
    }

    In Form:
    PHP Code:
    private System.Windows.Forms.TextBox textThreadTest;
    private 
    Worker localWorker;

    public 
    ControlMain()
    {
    ...
          
    // Instantiate the worker class and pass a reference to the
          // text box into the DoWork method
        
    localWorker = new Worker();
        
    localWorker.DoWork(this.textThreadTest);

    -scott
    he he he

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