|
Don't just do the re-draw in the Paint event, do all drawing there. Call the Invalidate method of the control when it needs to be redrawn.
Make sure to use the Graphics object that is supplied in the EventArgs for the event, and not create your own.
The supplied Graphics object is clipped to the area that should be redrawn, if you create a new one it won't be clipped, and you might draw on top of someone elses window.
---
b { font-weight: normal; }
|
|
|
|
|
how to generate a new label for every click event of a send button in panel in a new row in asp.net c#.please see the code below.its working but not creating new label in a new line withfirst label vissible
i am trying to write code for chating application.Please help me as soon as possible..
private void btnSend_Click(object sender, System.EventArgs e)
{
System.Web.UI.WebControls.Label lbl=new Label();
lbl.Text=entr;
Panel1.Controls.Add(lbl);
}
|
|
|
|
|
specify the location of every new label
|
|
|
|
|
thanks for the reply..can u plz tell me more on it in code
|
|
|
|
|
Hi,
/********** Visual Studio 2005, C# .NET 2.0 - Windows Form ***********/
Within my code, I want to hold for certain seconds like Thread.Sleep(2000). But I dont want to block the User Interfaces. Now, I had a choice to use Timer, and When I need to start sleeping, I can call the timer.Start() and use While Loop to check how many seconds passed, if time over then exit the loop, otherwise Application.DoEvents(). But This is a very dirty way and I am looking for an efficient way and I believe there must be some class to do this job. Would you please let me know about that.
Thanks again
Emran.
|
|
|
|
|
bashiwala wrote: I want to hold for certain seconds like Thread.Sleep(2000). But I dont want to block the User Interfaces.
ummmm.... "hold" what?
led mike
|
|
|
|
|
Hello,
Thanks for your reply.
Actually my purpose is not to trigger timed event. Ok, just consider the following code,
private void doNothing_Important()
{
int a = 5;
int b = 6;
int c = a + b;
Thread.Sleep(2000);
b = c - 1;
}
Now, in my that code, I want to wait for 2 seconds before executing the last line but If I use Thread.Sleep(2000), then all user interface controls are blocked. An alternative way to perform this task without blocking is to use a thread or backgroudnworker. I can call the Background worker Asynchronously and make a while loop to check if the thread is completed. like this,
private void doNothing_Important()
{
int a = 5;
int b = 6;
int c = a + b;
backGroundWorker1.runWorkerAsyncrhonous();
while(backGroundWorker1.IsBusy)
Application.DoEvents();
b = c - 1;
}
backGroundWorker1_DoWork(BWEventargs e.....)
{
Thread.Sleep(2000);
}
Now, My question is, IS there any other better short cut way to perform the same sleeping task ?
Regards
emran
|
|
|
|
|
Hi!
If I understand you correctly, you want a certain action to be performed at a certain time, right?
You could do this by creating the timer and setting its Interval property to the time difference between now (DateTime.Now ) and the time you want the action to be performed.
That way you just have to put your action in the timer's Tick event handler and you're done.
Btw. don't forget to stop the timer in the tick event handler, otherwise you could get the action performed more than once.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hello,
Thanks for your reply.
Actually my purpose is not to trigger timed event. Ok, just consider the following code,
private void doNothing_Important()
{
int a = 5;
int b = 6;
int c = a + b;
Thread.Sleep(2000);
b = c - 1;
}
Now, in my that code, I want to wait for 2 seconds before executing the last line but If I use Thread.Sleep(2000), then all user interface controls are blocked. An alternative way to perform this task without blocking is to use a thread or backgroudnworker. I can call the Background worker Asynchronously and make a while loop to check if the thread is completed. like this,
private void doNothing_Important()
{
int a = 5;
int b = 6;
int c = a + b;
backGroundWorker1.runWorkerAsyncrhonous();
while(backGroundWorker1.IsBusy)
Application.DoEvents();
b = c - 1;
}
backGroundWorker1_DoWork(BWEventargs e.....)
{
Thread.Sleep(2000);
}
Now, My question is, IS there any other better short cut way to perform the same sleeping task ?
Regards
emran
|
|
|
|
|
You're using the wrong approach.
While a method is being executed in your UI thread, the UI will not respond.
Using Application.DoEvents() is just a workaround for certain cases and shouldn't be used in this case.
The right way IMO would be to put b = c - 1; in a separate method and call this method when a timer elapses.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Maybe somthing like this?
int b;
int c;
private void doNothing_Important(){
int a = 5;
b = 6;
c = a + b;
System.Windows.Forms.Timer tim = new System.Windows.Forms.Timer();
tim.Tick += new EventHandler(tim_Tick);
tim.Interval = 2000;
tim.Start();
}
private void tim_Tick(object sender, EventArgs e){
System.Windows.Forms.Timer tim = (System.Windows.Forms.Timer)sender;
tim.Stop()
tim.Tick -= new EventHandler(tim_Tick);
tim.Dispose();
b = c - 1;
}
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick || Fold With Us! || Pensieve || VG.Net ||
|
|
|
|
|
Thanks Marc,
Although, I thought, Application.DoEvents() was equivalent to nonBlocking Sleep function. BEcause, I used following snippet whereever I needed to wait for asynchronous methods, i.e.,
while (webBrowser1.ReadyState != ReadyState.Complete)
Application.doEvents();
Now, according to your solution, I will have to split up my methods in timers. Anyway, if C# doesnot provide any more simpler way... what can I do ,
Thanks again,.
Emran
|
|
|
|
|
Hehe you're welcome
DoEvents sort of flushes all the windows messages (from the controls and stuff). A method usually isn't supposed to 'hang' for 2 seconds. Like the poster above me said, DoEvents is mostly a workaround, don't use it too often.
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick || Fold With Us! || Pensieve || VG.Net ||
|
|
|
|
|
[Marc] wrote: DoEvents is mostly a workaround
Thanks.
I did not get the term "WorkAround". What does it mean ! Can you give me an example ?
Thanks and regards
|
|
|
|
|
Sorry, can't give an example, i never had to use it as fart as i remember.
A workaround[^] is, as the name states it, that you work around a bug or other weird thing instead of solving the bug/weird thing. Sometimes you can't solve that problem because it's not your fault, and you dont have access to the problems code and so on. Then you have to work around it.
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick || Fold With Us! || Pensieve || VG.Net ||
|
|
|
|
|
I have a C#.Net program that once a button is clicked it goes to a public class(called Tal) and gets data in a vector, then exits the class, and goes back to the main form(program). I will do this task over and over. I want to take the data ,do many(over 20) calculations, and go back to the program. How can I get access to the data array(vector) from the main program? I keep getting different errors and have tried so many different ways. Thanks in advance.
Code:
{
Mainfrm
tal.talbars();
}
Public Class tal
// get vector array
Price[] closes = row["SETTLE"] == null ? null : row SETTLE"].PriceVectorValue;
int first_element = elements - 5; // to get 5 back
for (int i = first_element; i < elements; i++)
static void talbars
tal();
So I want to use closes[1-5] in the main program. I get not in namespace error(I put the whole class in the main form, so that shouldnt be an issue). I get name doesnt exist in class also. Any ideas would be greatly appreciated.
|
|
|
|
|
I will make it more basic.
Namespace Program
{
Main()
{
class.tal; // goto class to get data
double calc;
calc = data[1]+data[2];
Console.Writeline(calc);
} //end of Main
Public Class Class()
public void tal
{
// get data for data[1] and data[2]
} // end of class.tal
} // end namespace
I will have alot of data[] and a lot of calcs to be done in the main(cant be done in class). So I get errors when I try and use data[] in Main. Im new to C# and I know its something simple, I just cant figure it out. Thanks again.
|
|
|
|
|
how can i change textbox width at runtime. I want to drag the textbox like v do while designing.
AjayO@PMAM.com
|
|
|
|
|
ajayo wrote: how can i change textbox width at runtime
I would guess you could use the Size property.
|
|
|
|
|
thanks but as i mentioned I want to be able to drag right side of the textbox and change size like v do it in designer.
|
|
|
|
|
Hi Ajay,
did u got the solution for ur problem?
we can write the code to change the textbox width at runtime, but i don't know how to write the code to allow the user to drag the textbox. please whenever u find the solution, try to post the code here.
thanks,
Rahi
|
|
|
|
|
Hi, I know that it's possible to set the ProcessorAffinity in Diagnostics.Process to use only one processor, but how can I do this for a forms application?
|
|
|
|
|
Get a process object for your form and use the ProcessorAffinity member.
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
Thanks for the suggestion, it sounds logical and I was figuring the same. I haven't found a way to retrieve a process object from a form, however. There's no property or method that lets me fetch it. Would anyone happen to know how this is done?
|
|
|
|
|
There's a static method Process.GetCurrentProcess() you can use.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|