示例#1
0
        private int WorldCoordinatesToLineIndex(Point position)
        {
            if (!documentHasData)
            {
                return(-1);
            }
            if (position.Y < margin || position.X < margin)
            {
                return(-1);
            }
            int index = (int)(position.Y - margin) / (int)this.lineHeight;

            // check position isn't below document
            if (index >= documentLines.Count)
            {
                return(-1);
            }
            // now check that horizontal position is within this line
            TextLineInformation theLine =
                (TextLineInformation)documentLines[index];

            if (position.X > margin + theLine.Width)
            {
                return(-1);
            }

            // all is OK. We can return answer
            return(index);
        }
示例#2
0
        protected override void OnDoubleClick(EventArgs e)
        {
            int i = PageCoordinatesToLineIndex(this.mouseDoubleClickPosition);

            if (i >= 0)
            {
                TextLineInformation lineToBeChanged =
                    (TextLineInformation)documentLines[i];
                lineToBeChanged.Text = lineToBeChanged.Text.ToUpper();
                Graphics dc       = this.CreateGraphics();
                uint     newWidth = (uint)dc.MeasureString(lineToBeChanged.Text,
                                                           mainFont).Width;
                if (newWidth > lineToBeChanged.Width)
                {
                    lineToBeChanged.Width = newWidth;
                }
                if (newWidth + 2 * margin > this.documentSize.Width)
                {
                    this.documentSize.Width = (int)newWidth;
                    this.AutoScrollMinSize  = this.documentSize;
                }
                Rectangle changedRectangle = new Rectangle(
                    LineIndexToPageCoordinates(i),
                    new Size((int)newWidth,
                             (int)this.lineHeight));
                this.Invalidate(changedRectangle);
            }
            base.OnDoubleClick(e);
        }
示例#3
0
        private void LoadFile(string FileName)
        {
            StreamReader sr = new StreamReader(FileName);
            string       nextLine;

            documentLines.Clear();
            nLines = 0;
            TextLineInformation nextLineInfo;

            while ((nextLine = sr.ReadLine()) != null)
            {
                nextLineInfo      = new TextLineInformation();
                nextLineInfo.Text = nextLine;
                documentLines.Add(nextLineInfo);
                ++nLines;
            }
            sr.Close();
            if (nLines > 0)
            {
                documentHasData              = true;
                menuFilePrint.Enabled        = true;
                menuFilePrintPreview.Enabled = true;
            }
            else
            {
                documentHasData              = false;
                menuFilePrint.Enabled        = false;
                menuFilePrintPreview.Enabled = false;
            }

            CalculateLineWidths();
            CalculateDocumentSize();

            this.Text = standardTitle + " - " + FileName;
            this.Invalidate();
        }
示例#4
0
文件: Form1.cs 项目: alannet/example
        private void LoadFile(string FileName)
        {
            StreamReader sr = new StreamReader(FileName);
            string nextLine;
            documentLines.Clear();
            nLines = 0;
            TextLineInformation nextLineInfo;
            while ( (nextLine = sr.ReadLine()) != null)
            {
                nextLineInfo = new TextLineInformation();
                nextLineInfo.Text = nextLine;
                documentLines.Add(nextLineInfo);
                ++nLines;
            }
            sr.Close();
            if (nLines > 0)
            {
                documentHasData = true;
                menuFilePrint.Enabled = true;
                menuFilePrintPreview.Enabled = true;
            }
            else
            {
                documentHasData = false;
                menuFilePrint.Enabled = false;
                menuFilePrintPreview.Enabled = false;
            }

            CalculateLineWidths();
            CalculateDocumentSize();

            this.Text = standardTitle + " - " + FileName;
            this.Invalidate();
        }