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
Printable View
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
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.
Would that even work? What's the use of it?
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
Sounds like you should rethink your code design. Why do you need to reference it from static methods?
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
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.
Sounds very interesting.
But take heed of this remark in the documentation of the Control class:
Quote:
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.
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
In Form: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{}
}
}
}
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);
}