|
Try this:
int StartX = (e.Location.X > mrctRectangle.X ? e.Location.X : mrctRectangle.X);
int StartY = (e.Location.Y > mrctRectangle.Y ? e.Location.Y : mrctRectangle.Y);
int EndX = (e.Location.X < mrctRectangle.X ? e.Location.X : mrctRectangle.X);
int EndY = (e.Location.Y < mrctRectangle.Y ? e.Location.Y : mrctRectangle.Y);
You have here the start and end points of an rectangle. Hope it helps.
I will use Google before asking dumb questions
|
|
|
|
|
Hi,
this looks the easiest to me: store MouseDown point in pt1, current MouseMove position in pt2,
and in OnPaint for both x and y do:
xMin= x1<=x2 ? x1 : x2;
width= x1+x2-xMin -xMin;
ADDED: then Graphics.DrawRectangle(..., xMin, yMin, width, height);
BTW: You might want to add 1 to width/height to always see the rectangle...
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hello,
I would like to know the way to use the Serialport class for receiving the data from more than a port at a time. I mean, how to create multiple threads at a time so as to read the data from multiple ports?
Techie..
|
|
|
|
|
There's no restriction on the number of SerialPort instances can be created, so all you need to do is create a SerialPort instance for eacht port you want to use and add eventhandlers for each ports DataReceived event.
Standards are great! Everybody should have one!
|
|
|
|
|
hi everyone!
i created a service and an installer.
the service works fine when testing it as an executeable.
when i install it and choose "automatic" (start mode) then it does not start but displays a message telling me, services in idle mode are sometimes stopped.
i guess i forgot to add an option to not allow termination or similar.
could anyone tell me where the problem might be located?
thanks!
stephan.
|
|
|
|
|
There's an exception occurring somewhere in your startup procedure. Check the event viewer to see if something has appeared in there - and log any exceptions that you encounter/consume.
|
|
|
|
|
Hi,
I've to read display the contetns of a folder that is placed on a web server. For instance i've to display the contents of http://localhost on in a list view of my windows application. Please help me out. It would be nice of you.
Arslan Ilyas
|
|
|
|
|
Well, you're probably better off using web services for this sort of thing rather than interpreting web pages. If the latter is what you require take a look at HttpWebRequest and HttpWebResponse - this will allow you to simulate the communication a web-browser uses and give you a response stream from the server you can parse.
Regards,
Rob Philpott.
|
|
|
|
|
|
Hi, I want to dispaly the time on the form. For every elapse the event should be raised. so for every 1000 milliseconds the time should be change on screen.
No other threads are running in my program...
But i getting the following error:
Cross-thread operation not valid: Control 'label1' accessed from a thread other than the thread it was created on.
please help.
Thanks in advance
private void button1_Click(object sender, EventArgs e)
{
label1.Text = Convert.ToString(DateTime.Now);
System.Timers.Timer objTimer = new System.Timers.Timer();
objTimer.Elapsed += new ElapsedEventHandler(DisplayTimeEvent);
objTimer.Interval = 1000;
objTimer.Start();
}
public void DisplayTimeEvent(object source, ElapsedEventArgs e)
{
label1.Text = Convert.ToString(DateTime.Now);
}
G. Satish
|
|
|
|
|
Satish - Developer wrote: But i getting the following error:
Cross-thread operation not valid: Control 'label1' accessed from a thread other than the thread it was created on.
What you are doing wrong is that you want to change the label's text property from another thread than the one is was created on. You need to use Invoke and InvokeRequired.
I will use Google before asking dumb questions
|
|
|
|
|
Fianlly i got answer by invoking the label
public void DisplayTimeEvent(object source, ElapsedEventArgs e)
{
this.label1.Invoke(
(MethodInvoker)delegate()
{
label1.Text = Convert.ToString(DateTime.Now);
}
);
}
|
|
|
|
|
As Andrei has stated above, the rule is that only the thread which creates a control should update it.
You could alternatively use the System.Windows.Forms timer, as this always fires on the primary GUI thread and no thread switch is required.
Regards,
Rob Philpott.
|
|
|
|
|
Finally i got the answer by invoking the Label. Thank u
public void DisplayTimeEvent(object source, ElapsedEventArgs e)
{
this.label1.Invoke(
(MethodInvoker)delegate()
{
label1.Text = Convert.ToString(DateTime.Now);
}
);
}
|
|
|
|
|
I have this application that sends mail to a mail server.The server uses Domino Lotus iNote to distribute and display the mails.But when a user receives the mail,the column that suppose to show the "Who" is always blank/empty making the mail look more like a spam.And some users don't care to open it thinking that it is a spam.
Can anyone help me out with how to fill this "Who" column.
I use:
MailMessage myMail = new MailMessage();
myMail.From = "myname@me.com";
myMail.To = "emailTxt.Text";
myMail.Fields.Add("SenderName","myname");
myMail.Subject = "You Have Been Appraised!";
myMail.BodyFormat = MailFormat.Text;
myMail.Body = "Go and confirm or contest your mail! ";
SmtpMail.SmtpServer = "10.12.19.105";
SmtpMail.Send(myMail);
I don't know if there is another parameter that is required to be able to send an email to domino lotus iNote.
|
|
|
|
|
Hi I need to get the Focused Property of My ListBox list from within a thread. The thread makes calls to following function
<br />
bool listFocused()<br />
{<br />
if (this.list.InvokeRequired)<br />
{<br />
ListFocusCallBack d = new ListFocusCallBack(listFocused);<br />
Object obj = this.list.Invoke(d, new object[] {});<br />
}<br />
else<br />
{<br />
return this.list.Focused;<br />
}<br />
}<br />
If I compile the above then I get a "not all code paths return a value" error, because I'm not returning anything in "ProblemLine"
I tried replacing "ProblemLine" with
if( obj.Equals(Boolean.TrueString ))<br />
return true;<br />
return false;<br />
but I'm not sure if it is the right approach.
Please Advice
Thanks...
|
|
|
|
|
Hello,
You don't need the else statement in your method.
If invoke is called the code after that will not been worked threw.
Set a breakpoint at the first line of the method and Debug it to see it better.
Your method could look like that:
bool listFocused()
{
if(this.list.InvokeRequired)
{
ListFocusCallBack d = new ListFocusCallBack(listFocused);
this.list.Invoke(d, new object[] {});
}
return this.list.Focused;
}
-- modified at 8:07 Wednesday 21st November, 2007
Wrong Information Sorry
All the best,
Martin
|
|
|
|
|
To my knowledge, it's not thread safe this way, let me explain :
bool listFocused()
{
if(this.list.InvokeRequired)
{
ListFocusCallBack d = new ListFocusCallBack(listFocused);
this.list.Invoke(d, new object[] {});
}
return this.list.Focused;
}
what you need to do is to return value that Control.Invoke method returns
bool listFocused()
{
if(this.list.InvokeRequired)
{
ListFocusCallBack d = new ListFocusCallBack(listFocused);
return (bool)this.list.Invoke(d, new object[] {});
}
else
{
return this.list.Focused;
}
}
zilo
|
|
|
|
|
Hello Zilo,
I do not agree with you.
Zilo(svk) wrote: return this.list.Focused; // !!! again [T1] - if u invoke a delegate using control invoke, it doesn't mean // that the rest of this method will be executed on that invoked thread. it // remains on thread [T1], where it's not safe to get the Focused value.
This code will never be executed by [T1] AFAIK.
After the Invoke call, the method will no longer go threw the rest of the method code.
I often debugged such a situation, and hope what I just told is not complete rubbish!
-- modified at 8:09 Wednesday 21st November, 2007
I wrote: hope what I just told is not complete rubbish
It was rubbish!
All the best,
Martin
|
|
|
|
|
Test it. It really is the way I wrote. I mean I don't see any reason why Control.Invoke(delegate Method); should for any reason make calling method to return whatever the delegate returns. It does just doesn't make any sense. Execution continues. It just blocks until delegate completed.
zilo
|
|
|
|
|
Hello Zilo,
Just testet it, and have to say THANK YOU SO MUCH for pointing that out.
First of all, I was not consistend in my Projects.
And second, I was completely wrong.
Thats what I like at CP.
By answering (or trying to do so at least), you also get support!
Got my '5'.
Thanks again!
All the best,
Martin
|
|
|
|
|
np,
It's good to know that you know something ) . I wasn't sure either about this one.
zilo
|
|
|
|
|
I was also thinking on similar lines what I actually did was
<br />
if (this.list.InvokeRequired)<br />
{<br />
ListFocusCallBack d = new ListFocusCallBack(listFocused);<br />
Object obj = this.list.Invoke(d, new object[] {});<br />
<br />
if( obj.Equals(Boolean.TrueString ))<br />
return true;<br />
return false;<br />
}<br />
else<br />
{<br />
return this.list.Focused;<br />
}<br />
Your solution about converting Object to bool as (bool)obj never came to my mind. I never knew it was possible.
Thanks...
The Show Ain't Over Yet...
|
|
|
|
|
it send data to tcp/ip port number, ex 8080, now i want to write socket program to read data from that port. Any body help me? How can i do that?
plz post the code
|
|
|
|
|
No more comment!
All the best,
Martin
|
|
|
|