要求在状态栏显示光标所在位置
public partial class Form1 : Form
{
//public static extern bool GetCaretPos(ref System.Drawing.Point lpPoint);
public static extern bool GetCaretPos(ref System.Drawing.Point lpPoint);
private int X=0;
private int Y=0;
public Form1()
{
InitializeComponent();
} private void toolStripMenuItem2_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
//MessageBox.Show("Open "+openFileDialog1.FileName );
// Assign the cursor in the Stream to the Form's Cursor property.
//this.Cursor = new Cursor(openFileDialog1.OpenFile());
this.richTextBox1.LoadFile(openFileDialog1.FileName,RichTextBoxStreamType.PlainText);
toolStripStatusLabel1.Text = this.openFileDialog1.FileName;
Point p = new Point(0);
GetCaretPos(ref p);
int pos ;
pos = this.richTextBox1.GetCharIndexFromPosition(p);
this.Y = this.richTextBox1.GetLineFromCharIndex(pos); if (this.Y > 0)
{
int offset = 1;
while (this.richTextBox1.Text[pos - offset] != '\n')
offset++;
this.X = offset;
this.Y++;
}
else
{
this.X = pos + 1;
this.Y = 1;
}
toolStripStatusLabel2.Text = "line: "+this.X.ToString() + "Row: "+this.Y.ToString() ; this.toolStripProgressBar1.Minimum = 0;
this.toolStripProgressBar1.Maximum = 10;
this.toolStripProgressBar1.Step += 1;
this.toolStripProgressBar1.PerformStep();
}
public partial class Form1 : Form
{
//public static extern bool GetCaretPos(ref System.Drawing.Point lpPoint);
public static extern bool GetCaretPos(ref System.Drawing.Point lpPoint);
private int X=0;
private int Y=0;
public Form1()
{
InitializeComponent();
} private void toolStripMenuItem2_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
//MessageBox.Show("Open "+openFileDialog1.FileName );
// Assign the cursor in the Stream to the Form's Cursor property.
//this.Cursor = new Cursor(openFileDialog1.OpenFile());
this.richTextBox1.LoadFile(openFileDialog1.FileName,RichTextBoxStreamType.PlainText);
toolStripStatusLabel1.Text = this.openFileDialog1.FileName;
Point p = new Point(0);
GetCaretPos(ref p);
int pos ;
pos = this.richTextBox1.GetCharIndexFromPosition(p);
this.Y = this.richTextBox1.GetLineFromCharIndex(pos); if (this.Y > 0)
{
int offset = 1;
while (this.richTextBox1.Text[pos - offset] != '\n')
offset++;
this.X = offset;
this.Y++;
}
else
{
this.X = pos + 1;
this.Y = 1;
}
toolStripStatusLabel2.Text = "line: "+this.X.ToString() + "Row: "+this.Y.ToString() ; this.toolStripProgressBar1.Minimum = 0;
this.toolStripProgressBar1.Maximum = 10;
this.toolStripProgressBar1.Step += 1;
this.toolStripProgressBar1.PerformStep();
}
[DllImport("user32")]