Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
i want to make Textviewer. this show Two pages. like book!!

so i want to know. how to make page (string[] array or list).

and i wish to use graphics.drawstring or textrenderer. not textbox control.

because i already make it use with textbox. but it is too slow loading and resizing.

i have a good target here 책보는 프로그램 - 별북 ( 1.5 정식 ) :: 제이드민

i wish it can open 10mbytes or bigger files.

let me know your knowhow.

What I have tried:

i already make this but it is slow. i used textbox control.
when i resize wordwrap is Change all text. and have to make page reindex all text.
it takes so long.
give me a tip.

ok i think my question is bad.

i wish this code be Fast
C#
string filetxt = string.Empty;
private void toolStripButton2_Click(object sender, EventArgs e)
{
    OpenFileDialog ofd = new OpenFileDialog();
    ofd.Filter = "Textfile|*.txt";
    string filename = string.Empty;
    if (DialogResult.OK == ofd.ShowDialog())
    {
        filename = ofd.FileName;
        filetxt = File.ReadAllText(filename, System.Text.Encoding.GetEncoding(51949));

        Graphics aa = CreateGraphics();
        SizeF sizefl = new SizeF(panel1.Width - 20, panel1.Height - 20);
        StringFormat stf = new StringFormat(StringFormatFlags.LineLimit);
        int charactersfitted;
        int linesfilled;
        //find max lines
        string bbb = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
        SizeF sf = aa.MeasureString(bbb, new Font("굴림", 12), sizefl, stf, out charactersfitted, out linesfilled);
        int maxlines = linesfilled;
        charactersfitted = 0;
        linesfilled = 0;
        int indexofchar = 0;
        int page = 0;
        while (true)
        {
            if (indexofchar < filetxt.Length - 10000)
            {
                string aaa = filetxt.Substring(indexofchar, 10000);
                SizeF sfefs = aa.MeasureString(aaa, new Font("굴림", 12), sizefl, stf, out charactersfitted, out linesfilled);
                indexofchar += charactersfitted;
                pages[page] = aaa.Substring(0, charactersfitted);
                page++;
            }
            else {
                break;
            }
        }
        hScrollBar1.Maximum = page;
        Invalidate();
        Refresh();
    }

}

private void panel1_Paint(object sender, PaintEventArgs e)
{
    Rectangle rect = new Rectangle(10, 10, panel1.Width - 20, panel1.Height - 20);
    e.Graphics.DrawRectangle(new Pen(Color.Black), rect);
    StringFormat stf = new StringFormat(StringFormatFlags.LineLimit);
    e.Graphics.DrawString(pages[pagesval], new Font("굴림", 12), new SolidBrush(Color.Black), rect, stf);
}
string[] pages = new string[100000];
int pagesval = 0;
private void hScrollBar1_ValueChanged(object sender, EventArgs e)
{
    pagesval = hScrollBar1.Value;
    Invalidate();
    Refresh();
}
Posted
Updated 22-Aug-16 7:44am
v5
Comments
Patrice T 22-Aug-16 7:03am    
And you have a question ?
njammy 22-Aug-16 7:09am    
brockeu wants to know an alternative text / drawing layout rendering controls to basic text box.
Patrice T 22-Aug-16 7:21am    
I think its problem is "i wish it can open 10mbytes or bigger files."
Which is unrealistic.
njammy 22-Aug-16 7:27am    
brockeu, ppolymorphe has a good point, think about partial loading of file or content for better performance with suitable choice of controls.
brockeu 22-Aug-16 8:26am    
when i resize i have to pagesort again and it takes so long.

You should explain in detail what you want to do because
Quote:
i wish it can open 10mbytes or bigger files.
is unrealistic.
Anything with such a file will be sloooow.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900