|
hi,all
how can i drag a line with mouse from a point to another
and it is extended whenever i drag it with mouse
thanx
|
|
|
|
|
If you want the line to disappear when the mouse is lifted, use the CreateGraphics method to draw it, otherwise you need to handle the paint event. Either way, you want to handle the mouse down, mouse move and mouse up events, you need to store the position where the mouse went down, and keep painting new lines from there to where they mouse is as you move it.
What do you want to achieve ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
hi, Christian
i donot want it to disappear but tie two points (actually two images) and when i move image the line extended
|
|
|
|
|
What do you mean, two images ? What do you want to do ?
If you want to draw two lines that persist, you need to handle the paint event, then when you call Invalidate(), the paint event will redraw your form. Store a bool to say if the mouse button is down, and two points, one for each end of the line. Set both to the current mouse pos when the mouse goes down, set one to the mouse position when it moves, and in your paint event, draw a line between them, if the mouse is down ( via that flag you set )
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
thanx Christian
about ur question
iam making a mobile simulator project and i want to tie
for example mobile node with base station node
thanx alot
generator
|
|
|
|
|
OK, that's a little more complex, you need to then store the locations of 'objects' you want to draw lines between ( assuming you don't want to allow arbitrary lines to be drawn ).
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
( assuming you don't want to allow arbitrary lines to be drawn ).
what is the mean of this
generator
|
|
|
|
|
You want lines to only be drawn between components, or just anywhere that people feel like it ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
In my application I need to use a timer. Depending on it the text of a Label control must be changed and when the time counter reaches the value of '0' an event must happen.
Now so far I wasn't even able to change the value of Label Text property.
I can't figure out what is wrong. Samples I tried from books and MSDN worked just fine, but not the timer in my application. All I get is an infinite 'while' loop. This is the code I used:
this.countDownTimer.Enabled = true;
while(this.timeCounter > 0)
{
this.countDownTimer.Tick += new EventHandler(this.countDownTimer_Tick);
}
this.countDownTimer.Enabled = false;
private void countDownTimer_Tick(object sender, EventArgs e)
{
this.timeCounter--;
this.lblTimeLeft.Text = timeCounter.ToString();
}
Would someone be so kind to help me with this. I have wasted a full day trying to make it work but no luck so far. Thank you!
|
|
|
|
|
vitaco wrote: while(this.timeCounter > 0){ this.countDownTimer.Tick += new EventHandler(this.countDownTimer_Tick); }
If timerCounter > 0, then your loop will run forever, as nothing is going to decrement it. also, your tick event is going to have many, many events tied to it ( that function will be called over and over ).
I think you're confusing timers and threads. Your timer will try to run, but it won't be able to, because your while loop will be eating the processor time.
Also, only set the tick event once, setting it more than once causes the function to be called over and over. Just remove the while loop, and start the timer ( you don't even to that, as far as I can see ), and it should work fine.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Well, I removed the 'while' loop. When I run the Debug mode I can see (as previously) that the line "this.countDownTimer.Tick += new EventHandler(this.countDownTimer_Tick)" never leads to execution of "countDownTimer_Tick". The lines of code
timeCounter--;
this.lblTimeLeft.Text = timeCounter.ToString();
are never accessed.
I'm certainly missing something. Can you help me with the actual line/lines of code that should do the trick?
|
|
|
|
|
in your first post u are disabling the timer after registering. remove this line
this.countDownTimer.Enabled = false;
and add it after
this.lblTimeLeft.Text = timeCounter.ToString();
Regards
Shajeel
|
|
|
|
|
As I said, the Timer has a Start method, I believe. Or, it's Enabled property has to be 'true'.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I've tried both. But it just doesn't work.
If I get it right when the program gets to the line
this.countDown.Start();
the 'countDown_Tick' must be executed. In my case it does not. For some
reason the program just 'remarks' the line and executes it after all the rest of the code is passed. I will illustrate the way it goes when I run it in the Debug mode.
//Step 1. The program enters the 'if' body
if(useTimeLimit)
{
this.pnlTimer.Enabled = true;
this.lblTimeLeft.Visible = true;
timeCounter = TimeLimit;
this.countDownTimer.Start();
and then goes further without going to 'countDown_Tick'
}
//Step 3. It goes through the rest of code in the method
else
{
some other code
}
some other code;
some other code;
//Step 4. After it goes through all the code in the method (Step 3)
the program executes the 'countDown_Tick'
private void countDownTimer_Tick(object sender, EventArgs e)
{
while (timeCounter > 0)
{
timeCounter--;
this.lblTimeLeft.Text = timeCounter.ToString();
}
this.countDownTimer.Stop();
}
I know this is stupid, but imagine how stupid I feel in such a situation! Please help!
|
|
|
|
|
vitaco wrote: I've tried both. But it just doesn't work.
If I get it right when the program gets to the line
this.countDown.Start();
the 'countDown_Tick' must be executed.
No i think you misunderstood timer functionality. After Start() function timer interval is started and once interval is elapsed countDownTimer_Tick is called. It is not a function, why do you want it to act like a function. If you want to execute a function then simply call it yourself.
Regards
Shajeel
|
|
|
|
|
create simple window application with form, button, label and timer. In button click and timer tick add following code.
private void button1_Click(object sender, System.EventArgs e)
{
this.timer1.Tick += new EventHandler(timer1_Tick);
this.timer1.Interval = 1000;
this.timer1.Start();
}
private int currentSecond = 0;
private void timer1_Tick(object sender, EventArgs e)
{
this.label1.Text = currentSecond++.ToString();
}
Hope this help
Regards
Shajeel
|
|
|
|
|
Yes it helped! Thank you! Now I will have to get the idea!
Christian Graus also helped me to understand something, namely "A timer will never tick until the method that called it ends". I didn't know that! Probably I will have to call a new method inside the while loop to change the Text property of the Label. Thank you both!
|
|
|
|
|
A timer will never tick until the method that called it ends, the tick is another function call that gets added to the list of pending events. It's not a direct function call, even if the time interval is 0. Timers are not that precise.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Really depends on what timer you are using. A UI timer obviously won't fire until the current queue of messages is empty, but System.Threading.Timer and System.Timers.Timer can both potentially fire even before the method that started them ends.
|
|
|
|
|
I want to develop a ActiveX control in c#.Net, that can handle mouse events, like mouse down, enter, leave, drag and drop events. plz guide me, I will be thank you..
|
|
|
|
|
Why do you want to use ActiveX ?
What info did you find on the web ? What further info do you need ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Thanks for u r reply, actually I want to draw almost 1 to 2 million rectangles (nodes) on the screen, for this purpose I have checked many controls but they don’t support such ability. Now I have decided to use C# drawing library. For this purpose I need a light weight object that can be drawn to the screen and manage mouse handling as well. I think ActiveX can help me in this regards. Plz guide me or if u knows any batter solution plz let me know. Thanks a lot.
|
|
|
|
|
ActiveX is a worthless layer of complexity. 1-2 million nodes is a lot, you will have to be careful to handle it correctly. How do you expect to display that many nodes ? Will your control be scrollable ?
Just writing a C# control will give you as much power as C# is going to give you, without the hassle of a ( potentially useless ) ActiveX layer.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Actually I want to give a full picture of entire business at one quick look. So I have to draw the entire nodes. And yea, my control will be scrollable. If you have any batter idea to perform such a scenario plz let me know. In my point of view I should go towards the c# library and handle all the mouse events by myself. What you suggest.
Thank you.
|
|
|
|
|
faheem424 wrote: In my point of view I should go towards the c# library and handle all the mouse events by myself. What you suggest.
Thank you.
Yes, that seems reasonable. The only thing that you don't need, is ActiveX.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|