|
There's the SelectionChanged event. This event is fired when the cursor is moved (because the cursor basically is a selection with SelectionLength==0 )
You'll have to calculate the line and column yourself from the given SelectionStart property.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Thanks guys! Here's what I ended up doing...
<code>
char[] before = textBox.Substring(0, textBox.SelectionStart);
int lineBreaks;
int lastLineIndex;
for (int a = 0; a < before; a++) {
if (before[a] == '\n') {
lineBreaks++;
lastLineIndex = a + 1;
}
}
cursorPositionLabel.Text = "Ln " + lineBreaks.ToString()
cursorPositionLabel += " , Col " + (textBox.SelectionStart - lastLineIndex).ToString();
</code>
So much for preserving the tabs...
If I had a sig, it would probably go here.
|
|
|
|
|
please help me
I want to insert new rows into the DataGrid for WindowsCE4.2 Application using c#2003
-- modified at 6:06 Sunday 22nd July, 2007
|
|
|
|
|
Is there a way to stop the form from closing within its OnClosing event? I'm making a program that asks if you really want to close it when you press the "x". So I've got a dialog that pops up and conditional statements for whichever button is pressed in the dialog, but I'm not sure what to put in the conditional statements to make the form stop closing. Could anyone help me out with this?
If I had a sig, it would probably go here.
|
|
|
|
|
Yep:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult result = MessageBox.Show("Are you sure you wish to cancel?", "Cancel?", MessageBoxButtons.YesNo);
if (result == DialogResult.No)
{
e.Cancel = true;
}
}
"It was the day before today.... I remember it like it was yesterday."
-Moleman
|
|
|
|
|
yes, see martin's reply. Thats exactly why the Closing event exists, so you can prevent
a Closed event from happening.
|
|
|
|
|
Thanks guys!
If I had a sig, it would probably go here.
|
|
|
|
|
You're welcome.
max29297 wrote: If I had a sig, it would probably go here
You probably mean: I'm happy I dont need a sig anymore...
|
|
|
|
|
lol, yeah, right
If I had a sig, it would probably go here.
|
|
|
|
|
HELLO!!!
Is it possible to remove one item from listview without reloading, refreshing?
Thanks.
One nation - underground
|
|
|
|
|
This will remove the first selected item from the list view.
if (myListView.SelectedItems.Count > 0)
myListView.Items.Remove (myListView.SelectedItems[0]); /ravi
|
|
|
|
|
I think a javascript will help if you want it without reloading!
I was born dumb!!
Programming made me laugh !!!
--sid--
|
|
|
|
|
Ok here is the problem. I am developing a server in C and a client in C#. The server send streams of data to the client, and the client is responsible for decoding and interpreting these stream. So, if I send a simple "Hello world" from the server to the client, it works. If I send a byte representing an integer (I use memcpy) I can decode it in the client. But, the problems start when after some integers, I also put a string. If I put 2 bytes, each representing some number, I am still able to decode the string that follows using:
System.Text.Encoding.ASCII.GetString(buffer,2,length)
But if I say 3 bytes, and then the string, I don't get anything (yes, I said buffer,3,length to reflect the server changes), I get garbage.. Can anyone please help me? Thank you.
|
|
|
|
|
What kind of "garbage" do you get?
I think that we have to see some code in order to tell what's wrong with the code...
---
single minded; short sighted; long gone;
|
|
|
|
|
Okay then.
Here is the server
memcpy(msg,&type,1);
memcpy(msg+1,&nr,1);
memcpy(msg+2,&online,1);
memcpy(msg+3,&p,sizeof(p));
type is 2, nr is 4 online is 0 and p is "Hello world". And on the client I get some unrecognizable characters (those squares you sometimes get). BUT, when online is 1 the string stays in one piece.. What am I supposed to make of this?
|
|
|
|
|
if only you had shown the client code and the server code in one message...
and, if at all possible, the hex representation of these data bytes arriving at the client.
|
|
|
|
|
But I already showed more than enough. Since I am able to transmit messages between the server and the client THERE IS NO PROBLEM HERE. Anyway, the server uses fprintf and the client uses BeginReceive - EndReceive (IAsync bla bla).
The problem is the way I am handling the array of bytes coming from the server. I suspect EndReceive thinks that a 0 means \0 (as in end of string). So it stops there. I don't know why this happens..
|
|
|
|
|
nc3b wrote: But I already showed more than enough
Sorry for trying to help you.
Debug Rule #1: when the system does not perform as designed, at least one element is wrong,
and it could be anything; not a single assumption is beyond scrutiny.
|
|
|
|
|
nc3b wrote: But I already showed more than enough.
I haven't seen a single line of the code that recieves the message.
nc3b wrote: Since I am able to transmit messages between the server and the client THERE IS NO PROBLEM HERE.
Just because some code works in some cases doesn't automatically mean that it works in all cases.
nc3b wrote: I suspect EndReceive thinks that a 0 means \0 (as in end of string). So it stops there. I don't know why this happens..
I don't know why it happens either, as I don't know if you use BeginRecieve and EndRecieve correctly.
---
single minded; short sighted; long gone;
|
|
|
|
|
The thing is that it's a lot of code.. Anyways, let's see...
The BeginReceive
sock.BeginReceive(buffer,0,buffer.Length,SocketFlags.None,receive,_sock);
The EndReceive
int stop=_sock.EndReceive(result);
Is it not correct?
|
|
|
|
|
That code is correct, but I have no idea if the surrounding code is correct, so that the buffer, receive, _sock and result variables are correct.
---
single minded; short sighted; long gone;
|
|
|
|
|
I might as well archive the project and attach it But anyways. I don't mind
private System.Byte[] buffer=new Byte[1024];
private void SetupReceiveCallback(Socket _sock)
{
AsyncCallback receive=new AsyncCallback(OnReceive);
_sock.BeginReceive(buffer,0,buffer.Length,SocketFlags.None,receive,_sock);
}
private void OnReceive(IAsyncResult result)
{
try
{
Socket _sock=(Socket)result.AsyncState;
int stop=_sock.EndReceive(result);
String str=System.Text.Encoding.ASCII.GetString(buffer,0,stop);
MessageBox.Show(str);
process(buffer,stop);
SetupReceiveCallback(_sock);
}
catch
{
MessageBox.Show("Out");
this.Close();
}
}
So?
|
|
|
|
|
Hi Guys
Does anyone know an open source library for skinned windows controls written in C#?.
Thanks in advance
Mahmoud Zidan
|
|
|
|
|
I am trying to figure out how to list all user accounts that exist in the SAM. I have figured out how to get the account name of the owner of a file, but not a list of all accounts on the machine.
Thanks for helping.
|
|
|
|
|
You might want to take a look at this article[^].
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|