November 27, 2017 c#mdi form creation & Notepad printing & notepad find, wrap line

Source: Internet
Author: User



The first parent form of an MDI form



Set the IsMdiContainer in the attribute to true.



Parent Form Connection Subform


//Create a new class to connect other forms that are unique
List<Form> F = new List<Form>();
private void opendao(Form f)
{
Form F1 = null;
bool isopen = false;
foreach(Form gf in F)
{
Gf.Hide ();
if(gf.Name == f.Name)
{
isopen = true;
F1 = GF;
}
}
If (isopen)
{
F.Close ();
F1.Show ();
}
Else
{
f.MdiParent = this;
f.WindowState = FormWindowState.Maximized;
f.Parent = panel1;
f.FormBorderStyle = FormBorderStyle.None;
F.Show ();
F.Add (f);
}
} 


The first button connection or anything else can


//Connect to second window
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Name = "1";
Opendao (F2);
}


The second button connection or something else is OK.


//Connect to second window
private void button2_Click(object sender, EventArgs e)
{
Form3 f3 = new Form3();
f3.Name = "2";
Opendao (F3);
} 


Note: Multiple form connections can be displayed only in the parent form






Notepad Page Setup


 
 private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            pageSetupDialog1.Document = printDocument1;
            DialogResult dr = pageSetupDialog1.ShowDialog(); if (dr == DialogResult.OK)
            {


            }
        }


Notepad print


//Note: the first code for painting, string painting, important!
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
string s = textBox1.Text;
Font f = new system.drawing.font ("Microsoft YaHei", 25.5f);
Brush b = new SolidBrush(Color.Red);
e.Graphics.DrawString(s, f, b, 20, 20);
}
/ / print
Private void print ptoolstripmenuitem [click (object sender, EventArgs E)
{
printDialog1.Document = printDocument1;
DialogResult dr = printDialog1.ShowDialog();
if (dr == DialogResult.OK)
{
printDocument1.Print();
}
} 


Notepad Print Preview


   private void 打印预览VToolStripMenuItem_Click(object sender, EventArgs e)
        {
            printPreviewDialog1.Document = printDocument1;
            printPreviewDialog1.ShowDialog();

        }


Notepad Wrap Line


Private void auto wrap toolstripmenuitem [click (object sender, EventArgs E)
{
if (textBox1.WordWrap)
{
//Don't wrap
textBox1.WordWrap = false;
textBox1.ScrollBars = ScrollBars.Both;
Auto wrap toolstripmenuitem.checked = false;
}
Else
{
//Auto wrap
textBox1.WordWrap = true;
textBox1.ScrollBars = ScrollBars.Vertical;
Auto wrap toolstripmenuitem.checked = true;
}
}


Notepad new Form Lookup


//This is the setting for the second window
Form1 F1;
public Form2(Form1 f1)
{
InitializeComponent();
F1 = F1;
}
Int a = 0;
private void button1_Click(object sender, EventArgs e)
{
string s = textBox1.Text;
a = F1.textBox1.Text.IndexOf(s, a + 1);
If (a! = -1)
{
F1.textBox1.Select(a, s.Length);
F1.textBox1.Focus();
}
Else
{
MessageBox. Show ("no match! "";
}
}
//This is the first window to use
Private void find toolstripmenuitem [click (object sender, EventArgs E)
{
Form2 f2 = new Form2(this);
f2.Owner = this;
F2.Show ();
} 





November 27, 2017 c#mdi form creation & Notepad printing & notepad find, wrap line


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.