|
You can only update UI controls on the thread that created them. Property updates and method calls on those controls must be marshalled back onto the UI thread. Lookup Control.Invoke for more information.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I know that. In this[^] thread I tried to explain that, but was told by eligazit that the BackgroundWorker class could let you get around this.
Cheers,
Will H
|
|
|
|
|
It doesn't "get around it". It just fire an event on the correct thread. It insulates you from the details of getting code that modifies a UI control to run on the correct thread.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
To update GUI with the BackgroundWorker, you need to do the following steps:
1. When creating the wroker:
public void InitWorker()
{
worker = new BackgroundWorker();
worker.WorkerReportsProgress = true;
worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
}
Note that I've creating new event handler to update GUI, when ever I want to set something on the GUI, I should call the ReportProgress(...) method of the worker:
void worker_DoWork(object sender, DoWorkEventArgs e)
{
// Some long operation
// .....
Thread.Sleep(2000);
// Update GUI
worker.ReportProgress(30);
// Some long operation
// .....
Thread.Sleep(2000);
// Update GUI
worker.ReportProgress(60);
// Some long operation
// .....
Thread.Sleep(2000);
// Update GUI
worker.ReportProgress(90);
}
And, on the ReportProgress handler, I can update the GUI as I want, this is beacuse the worker handles moving the OS the the right thread so it is not my problem...
void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
Label label;
label.Text = e.ProgressPercentage + "%";
}
Note that on the ReportProgress you can send an object that will be set on the ProgressChangedEventArgs (State), in this property you can set all the values you want to update on the GUI (other than the precentage).
|
|
|
|
|
Ah... i see. Thanks
Cheers,
Will H
|
|
|
|
|
I have a complete API all in vb.net.
I need to view all code and run all code in visual studio express edition c#
How do i do this?
please tell me this is possible (it has got to be)
|
|
|
|
|
|
|
|
Hi,
Easy question here. I found this online, but (I'm still new to programming) I'm not sure how to use it.
protected override CreateParams CreateParams<br />
{<br />
get<br />
{<br />
CreateParams cp = base.CreateParams;<br />
cp.ExStyle |= 0x00000020;
return cp;<br />
}<br />
}
Do I create a new class for this code? Either way, how and where do I say that I want a label (not all labels) to be this way.
Thanks so much!!!
Mel
|
|
|
|
|
Hi again,
Ok, I created a class and put the code in it.
public class TransparentControl : Label<br />
{<br />
protected override CreateParams CreateParams<br />
{<br />
get<br />
{<br />
CreateParams cp = base.CreateParams;<br />
cp.ExStyle |= 0x00000020;
return cp;<br />
}<br />
}<br />
}
Back in the normal form, I made the label private TransparentControl label7; and changed the appropriate line in InitializeComponent() this.label7 = new HCAUT.TransparentControl(); . I also made the backcolor of the label Transparent. But when I run everything, the label's backcolor still isn't transparent. Can anyone see what I'm doing wrong?
Thanks again,
Mel
|
|
|
|
|
hi melanieab!
i think if you inherited the Label, it already supports transparency.
try to remove the override property you've added.
if still doesn't allow transparency, add this line of code on the constructor of your control.
SetStyle(ControlStyles.SupportsTransparentBackColor, true)
hope that helps!
microsoc
|
|
|
|
|
hi all, Im using Microsoft Data Application Block for this.
Im trying to execute a sql procedure that inserts a row. I need
to get the identity field (eventID) returned back to me.
Ive tried several ways but it wont work. Anyone have a complete
example written in c# 1.0 for sql server 8.0, with c# code and
stored procedure?
Really appreciate all the help.
thanks
Moazzam
|
|
|
|
|
Why don't you show us your code and we can show you where to put it right?
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
Assuming your table contains an Identity column ..
create procedure EmployeeCreate (@name varchar(20), @dept varchar(20), @employeeid numeric out)<br />
as<br />
begin<br />
insert into Emplyee (Name, Department) values (@name, @dept)<br />
select @employeeid = @@identity<br />
end
So when you execute your SQL command from .net and pass parameters, pass a parameter for "@employeeid". You wont need to set a value for this SqlParameter, but you'll have to set the correct Direction.
- Malhar
|
|
|
|
|
Hey guys, could anyone please tell me from where i can get the windows default bitmaps for standard toolbar buttons like 'cut', 'copy', 'print', 'save',etc..... in my C# forms
|
|
|
|
|
c:\program files\vs.net\common7\graphics\...
|
|
|
|
|
If you make a toolstrip and in its options choose to embedd standard items, then the cut copy save etc appear with icons
You could search for the strings they use to get the icons in the designer file
|
|
|
|
|
Our main application is written in vb 6.0. The latest module for this product is written in .net. To accomplish this our .net module expose a COM interface to start and stop the .net module from the vb 6.0 code base.
Furthermore the module needs to receive data from the vb application during the session. Otherwise the connection between both is useless. At the moment the .net module is a Inproc COM thing which runs in the same process as the vb app does.
At first glance the problem seemed just to be that the Tab key behaved strange. A few tests later we saw that the .net module opens a MDI Form but didn't create a message loop (Application.Run). A few coffees later we fixed that part and the .net module main window was finally running inside a Application.Run(new MdiMainForm()) call. Guess what, the tab problem was fixed...
I assume that the vb application message loop wasn't suitable for the .net part of the process I guess it's very strange to have such a constelation inside one process, right?
After seeking codeproject I know that the best solution would be to let the module run as an exe in his very own process, OutOfProcess as a COM Server or use one of the IPC solutions (Named Pipe, Remoting WM Messages etc..)
This seems all to be very compilcated, all I want is to start/control/stop our .net module by the vb application, any ideas?
myMsg.BehindDaKeys = "Jerry Maguire";
|
|
|
|
|
This doesn't apply specifically to C#, but it is the language I am using and I did not see a better place to post this. If there is a better place, please let me know.
I have a finite, positive number of integers (in most cases between 3 and 20)
I want to split the integers into two groups such that their sums are as equal as possible (easy)
now the part that I'm having trouble with:
I want to find the top X combinations of groupings with the closest total sums (not just the top 1)
Obviously, I need calculate the sums for every possible combination, but I'm having trouble figuring out how to do this. Any ideas from veteran developers on a strategy to approach this or a recommended data structure?
EDIT:
I should add one more stipulation, the two groupings must both have the same number of elements (or one off if an odd number of total elements).
-- modified at 13:02 Thursday 2nd February, 2006
|
|
|
|
|
Just to clarify - combinations of groupings (of any amount of the numbers) that have the closest possible sums with any of the other groupings (of any amount of the numbers).
This is going to work out to being a very large number of calculations/combinations...
Depending on the number of numbers of course...
-- modified at 12:27 Thursday 2nd February, 2006
|
|
|
|
|
I should add one more stipulation, the two groupings must both have the same number of elements (or one off if an odd number of total elements).
for example, if I had elements with values: 1, 5, 19, 10
and I wanted the best 2 groupings, I would get:
{ 19, 1 }, { 10, 5 }
{ 19, 5 }, { 10, 1 }
I hope that clarifies things. It will be a fair amount of calculations, but it shouldn't be too bad because the maximum number of elements (in this case) is 20. That and I can't think of a better way :/
|
|
|
|
|
Are there any limitations on the number of items in each group, or can one group have many more items as long as the totals are close?
An easy way to find all combinations is too look at each item belonging to either group as a bit value. If you have 8 items you need 8 bits to represent which group they belong to, so there are 256 (2^8) ways of dividing the items into two groups if there is no limitations on the number of items in each group.
If you place the (rather obvious) limitation that each group has to contain at least one item, you have (2^n)-2 combinations, where n is the number of items.
---
b { font-weight: normal; }
-- modified at 12:44 Thursday 2nd February, 2006
|
|
|
|
|
I editted my main post to include the limitation that both groups must have an as-close-to-equal-as-possible number of elements.
|
|
|
|
|
Which is more important then, the difference in total sum, or the difference in number of elements?
---
b { font-weight: normal; }
|
|
|
|