|
Never tried it, but from the code you've posted...
COORD coord = new COORD();
coord.X = 12;
coord.Y = 16;
font.cbSize = coord;
|
|
|
|
|
Thanks! It actually worked.
|
|
|
|
|
I've been working with C# for about 6 months. This is the first time that a little searching has not resolved a problem for me. I'm trying to change the text of a label and update a progress bar in a loop that does some graphic calculations. The progress bar is working fine but the label text does not change until the loop has completed.
int nImgCnt = m_Parent.m_ImageList.Count - 1;
int nStatBarAdd = 1000 / nImgCnt;
for (int nIdx = 0; nIdx <= nImgCnt; nIdx++)
{
lblProg.Text = "Calculating minimum image size. Image " + (nIdx+1).ToString() + " of " + (nImgCnt + 1).ToString();
lblProg.Focus();
lblProg.Invalidate();
CurRC = getImageMinSize(m_Parent.m_ImageList[nIdx]);
if (CurRC.Width > MinRC.Width)
{
MinRC.Width = CurRC.Width;
MinRC.X = CurRC.X;
}
if (CurRC.Height > MinRC.Height)
{
MinRC.Height = CurRC.Height;
MinRC.Y = CurRC.Y;
}
prgBr.Value += nStatBarAdd;
}
If anyone can help me out with this I will really appreciate it!
|
|
|
|
|
it all depends where your code is sitting.
if it is in a GUI event handler (say a button click handler) then the main thread would be busy with your code, and hence the GUI would not respond to the things the user does, and a lot of things your code does. The right approach would be to use a separate thread, maybe a BackgroundWorker would be fine.
if it is not in a GUI event handler, hence already being executed by some other thread, then you are performing illegal cross-thread operations to GUI components. You might want to read this article[^].
All the above applies to all kinds of Controls; from what I've seen, I can't tell why the progress bar works better for you, I don't think it should the way things are.
|
|
|
|
|
Thanks for the quick response Luc!
Sorry, I should have pointed out this is in a button click event handler. I will trying doing the calculations in a BackgroundWorker, thanks again!
Edit:
I added a BackgroundWorker and life is good again. Thanks again Luc! I should have worked this one out for myself. I must be having a bad code day.
modified on Sunday, January 2, 2011 1:47 PM
|
|
|
|
|
You're welcome.
|
|
|
|
|
Luc Pattyn wrote: if it is not in a GUI event handler, hence already being executed by some other thread, then you are performing illegal cross-thread operations to GUI components. You might want to read this article[^].
But since he's not getting an exception, that can't be it. Unless there's more to it than I've experienced.
|
|
|
|
|
He didn't mention exceptions, so it was unclear whether any occurred or not. And a ThreadPool thread would happily swallow any exception he didn't handle explicitly: ThreadPool threads are built to survive no matter what.
|
|
|
|
|
I don't think their is a way of making this syntax work, but I think it would be quite nice to see this in C# .Net:
Instead of something on the lines of :
for(int i = 0; i <= 10; i++)myArray[i]...
We could just:
myArray[0 to 10]....
Even:
myArray[(n) 0 to length-1]n++;//which could increment each item in the array.
Just an idea although Linq may have some way already
|
|
|
|
|
Something wrong with foreach ?
foreach (MyElement me in myArray)
{
...
}
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Dunno why that got you a visit from the univoter - the for loop is a bit old and clunky.
Compensated.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Thanks
I just find that sometimes using the for-loop for a trivial idea in an array is too much.
|
|
|
|
|
|
OriginalGriff wrote: the for loop is a bit old and clunky.
That is like saying the while loop is old and clunky.
foreach is appropriate for certain situations and for is appropriate for others. Attempting to use foreach in all situations would lead to some code that would be attempting to replicate what for already does.
|
|
|
|
|
Using a for loop for a simple iteration though all the elements of any list is old and clunky - foreach is much more appropriate. Since that is what the OP was trying to do, that is how I responded.
I agree that foreach is not appropriate in all cases - in some you cannot use it at all - but I was indicating that a language element already existed that did what the OP was trying to achieve.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
OriginalGriff wrote: Using a for loop for a simple iteration though all the elements of any list is old and clunky - foreach is much more appropriate. Since that is what the OP was trying to do, that is how I responded.
I didn't see a qualification limiting your comment to only what the OP was doing. Rereading your post several times I still don't see any way to read it that provides a qualification.
With the qualification I have no problem with that comment.
|
|
|
|
|
Write a macro.
|
|
|
|
|
Sounds like a candidate for T4 if you're using Visual Studio.
|
|
|
|
|
Nope, sorry - don't agree.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
I have array list contains bytes , I want to check if the first byte start with 99 and end with 0d this means i have received a complete message but message length may be either 6 or 30 so if i received message start with 99 and it's terminal is 0d with message length 6 I will do operation and if length of message is 30 I will do another operation.
How I can check like this.
|
|
|
|
|
You have an ArrayList of byte? ArrayList has a Count property ( from documentation: Gets the number of elements actually contained in the ArrayList.)
Whas that it?
|
|
|
|
|
You really shouldn't have to ask such a simple question. When you read a 99 put it and any following bytes into the List (don't use ArrayList) and when you find a 0d, check the Count. Take the appropriate action then clear the List.
|
|
|
|
|
This question has already been answered here[^].
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Hello Experts,
I would like to ask some help if how can I know the number of pc connected in my network.
Any link of suggestion/comments for me to read if what will I use is kindly appreciated.
Thanks,
DAN
|
|
|
|
|
Here[^] is a solution for you
|
|
|
|