|
-
Jan 5th, 2003, 08:26 AM
#1
Thread Starter
Member
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
-
Jan 5th, 2003, 11:36 AM
#2
Frenzied Member
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
-
Jan 5th, 2003, 11:53 AM
#3
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.
-
Jan 5th, 2003, 12:09 PM
#4
Thread Starter
Member
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
-
Jan 5th, 2003, 03:15 PM
#5
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.
-
Jan 5th, 2003, 07:28 PM
#6
Thread Starter
Member
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
-
Jan 8th, 2003, 01:35 PM
#7
Hyperactive Member
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
-
Jan 8th, 2003, 01:54 PM
#8
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.
-
Jan 8th, 2003, 08:13 PM
#9
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|