|
That won't work, it will just delay the code.
You need to tell Windows to redraw the label with :
label1.Text = " method1";
label1.Refresh();
method1();
label1.Text = "method2";
label1.Refresh();
method2();
label1.Text = "method3";
label1.Refresh();
method3()
From the help for Control.Refresh:
Forces the control to invalidate its client area and immediately redraw itself and any child controls.
|
|
|
|
|
This won't fix the problem. Sleeping the UI for 5 seconds, after each update of a label, will only hang his app unnecessarily. Application.DoEvents() is what is needed in his situation.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
I think this cannot work. Setting the label text generates under water a message to the control. The label control then must update itself. If you change the label text three times inside the same method, you do not give control back to the message loop. So the message loop starts updating only after the third change and you will not notice the change.
I'm not sure how to solve this. It may be a design error. Maybe you can solve this using an owner drawn label or by using timers.
|
|
|
|
|
i got it.........
we can use doevents for repainting the form.......
thanks to all
My small attempt...
|
|
|
|
|
You can call Refresh() after each text change. It will force your control to repaint itself before executing the next method. If you're not concerned about an unresponsive UI and the slight performance loss when calling Refresh() then its the easiest solution.
|
|
|
|
|
Refresh won't work either because his code is not giving up control to allow the application's message pump to process the WM_PAINT messages and call the repaint code.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Refresh() is equivalent to {Invalidate(true); Update();} and the Update() method forces the control to repaint itselft executing any pending WM_PAINT messages bypassing the application queue. Update() is equivalent to the UpdateWindow() function. More info in: http://msdn2.microsoft.com/en-us/library/ms534874.aspx[^].
I might be missing something, but try this code here. It works perfectly if you can bare an unresponsive UI. My label is refreshing perfectly. Its a simple form with a label and a button to start the test:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
doTest();
}
private void doTest()
{
label1.Text = "Starting Method 1...";
label1.Refresh();
anyMethodCall();
label1.Text = "Starting Method 2...";
label1.Refresh();
anyMethodCall();
label1.Text = "Starting Method 3...";
label1.Refresh();
anyMethodCall();
label1.Text = "Starting Method 4...";
label1.Refresh();
anyMethodCall();
}
private void anyMethodCall()
{
System.Threading.Thread.Sleep(5000);
}
}
-- modified at 12:25 Thursday 3rd May, 2007
|
|
|
|
|
Ok, I'm wrong, damn OS being smart and getting in the way
My app fails to refresh if I try to move the window around.
During the first 2 calls to anyMethodCall() my UI is unresponsive and my label is refreshing perfectly but then the window will start to move perfectly according to my mouse requests even if the app is still executing calls 3 and 4. And whats worse, my label stops refreshing. This is due (I guess) to Windows (Xp in this case, don't know if 2000 or previous work the same way) detecting my window as unresposive and taking action.
DoEvents() will take care of this situation becuase it will inform the OS that my window is once again valid while Refresh() will not do that and the OS will keep on thinking its not responding.
So yeah DoEvents() is the best solution because you can't rely on the user not trying to move the window around. My bad
-- modified at 12:48 Thursday 3rd May, 2007
|
|
|
|
|
gumi_r@msn.com wrote: Ok, I'm wrong, damn OS being smart and getting in the way
My app fails to refresh if I try to move the window around.
OK, but that wasn't the point behind using Application.DoEvents(). Try updating 6 or 7 controls during a blocking operation. Now you'e got to call Update on those controls, individually. Mking all the changes then calling Application.DoEvents() let's all those controls repaint themselves all at once, with a single call.
gumi_r@msn.com wrote: So yeah DoEvents() is the best solution because you can't rely on the user not trying to move the window around. My bad
No big deal! Everything has a purpose, even Refresh!
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
After you change the Text of the label, you're code doesn't go idle to allow the message pump to process the WM_PAINT message it receives because you changed the label. You need to call Application.DoEvents() to get your code to let the message pump do it's work. This is easily done if you move the code to change the label to a method:
UpdateStatusMessage("Calling method1...");
method1();
UpdateStatusMessage("Calling method2...");
method2();
UpdateStatusMessage("Calling method3...");
method3();
.
.
.
private void UpdateStatusMessage(string message)
{
label1.Text = message;
Application.DoEvents();
}
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
this is what i done........
anyway thanks for all
My small attempt...
|
|
|
|
|
Hi All,
Here i develop a C# Application, in that App. I've 3 Textboxes and 2 Buttons, Default cursor set on TextBox1 and check some condition on TextBox1 Leave. But the problem is that after starting App. I wish to close that App. through Exit Button, but at that time cursor inside TextBox1 so it execute OnLeave function 1st and then I've to again click on Exit button, But i want when I clike on Exit Button in that case OnLeave function will not execute.
How it is posible if any one know plz reply.
Welcome any tips...
Thanx & Regards
SMK
|
|
|
|
|
Create a flag and make it false when the user clicks the exit button.
In the onleave function, first check if the flag is true or not.
Regards,
Arun Kumar.A
|
|
|
|
|
Hi,
Thanx for ur reply, But my pointer is already in TextBox1 and when I click on Exit button at that time OnLeave event is fired so its not posible to set a flag on exit button in my view I've to check that component(Exit Button)at OnLeave Function.
Thanx & Regrsds
SMK

|
|
|
|
|
As U have only
5 controls in Ur form,
better try this:
Create a member as follows:
TextBox LastBox;
For the OnLeave event of 3 textboxes,write like this:
Text1_OnLeave()
{
LastBox=TextBox1;
}
For the OnLeave event of other controls,assign null to the member "LastBox".
Create a function as follows:
=============================
Validate()
{
if(LastText==TextBox1)
{
Code to validate Textbox1.
}
else if(LastText==TextBox2)
{
Code to validate Textbox2.
}
else if(LastText==TextBox3)
{
Code to validate Textbox3.
}
}
Call the "Validate" function in the OnEnter event of all the controls,
except ExitButton.
If U R not able to find a better solution, use this.
Regards,
Arun Kumar.A
|
|
|
|
|
1) Don't check string.IsNullOrEmoty condition "if it is not necessary (acceptable for values which may be left empty)" which is "I think" true for your TextBox1 with Default cursor
OR
2) Don't set default cursor on your TextBox1 when the parent Form is activated (Shown, Selected...)
OR
3) update a text changed flag to true in TextBox.TextChanged event and use:
if(_boolTextChanged == true)
{
Validate(); // write your validation code here
}
else
{
return; // The user hasn't done anything, why make him/her crazy, DON'T validate anything!!!
}
4) I prefer validating everything in one function when the user is finished with all modifications and presses for example the Submit Button which does not break down the nerve system of the user hearing a BEEP sound or ToolTip warning if the validation fails for the control he/she is currently modifying.
|
|
|
|
|
Hey,
When I use a Culture and a resourceManager but there is no resourcebundle for my culture? What does he do?
And can I automaticly let him determin which resourcebundle he has to take (for example get the country settings of windows XP and use these to set your culture? (Don't know but I think this can)
Thx!
|
|
|
|
|
Hi,
For pulling information about a dll, I have tried Assembly.Load("dll name"), it doesn't work and I understand that I need to pass a full name. My requirement doesn't provide the full name, only the name of the dll should be passed and I should get full name with version, culture inforamtion etc.
Can some one tell how to fetch the version, culture etc information when given a dll name which is there in GAC..
Thanks for your help.
Satya 
|
|
|
|
|
SatyaDY wrote: it doesn't work
What happens? Does it throw an exception? Does it silently do nothing? Crash your hard disk?
I think the method you want is Assembly.LoadFile().
Cheers,
Vıkram.
Déjà moo - The feeling that you've seen this bull before.
Join the CP group at NationStates. Password: byalmightybob
|
|
|
|
|
Yes it throws exception..
Assembly LoadedAssembly = Assembly.LoadFile(@"c:\WINDOWS\assembly\mscorlib.dll");
Exception Occured: The system cannot find the file specified. (Exception from HR
ESULT: 0x80070002)
I tried both Load and LoadFile, getting the similar exception. Any clues?
Thanks
Satya
|
|
|
|
|
The issue that you have here is that there is no file "c:\WINDOWS\assembly\mscorlib.dll". If you go to the command line and type in dir c:\windows\assembly you will see that it lists directories. The version that you see in the Windows shell is a wrapper to make it convenient for managing GAC entries.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Yes, you are correct. Not aware of this point...
But how to find out the info about the dll which are in GAC, (only know the dll name)?
I am really struck here, Thanks for your help.
Satya
|
|
|
|
|
If you only know the DLL name, then you should use Assembly.Load(); Here's an example:
Assembly assem = Assembly.Load("mscorlib.dll");
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
It works only with mscorlib.dll, if you try with some other dlls it fails... I am trying to build an application which needs the full deatils of the dll and it uses this information to generate a binding file.
|
|
|
|
|
Well, the hack way to do this would be:
Assembly assem = Assembly.Load("mscorlib.dll");
if (assem != null)
{
string path = System.IO.Path.GetDirectoryName(assem.Location);
assem = Assembly.LoadFrom(System.IO.Path.Combine(path, "System.Xml.dll"));
}
Deja View - the feeling that you've seen this post before.
|
|
|
|