private void button8_Click(object sender, EventArgs e) { if(radioButton1.Checked) { MessageBox.Show("第一个"); } else if(radioButton2.Checked) { MessageBox.Show("第二个"); } else if(radioButton3.Checked) { MessageBox.Show("第三个"); } } public void showpic() { pictureBox1.Image = Image.FromFile(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + @"\image.jpg"); pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; } private void pictureBox1_Click(object sender, EventArgs e) { if(pictureBox1.Image != null)//不为空 { pictureBox1.Image.Dispose(); pictureBox1.Image = null; } else { showpic(); } } private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { label8.Text = "当前操作统计信息为:页面为第" + this.tabControl1.SelectedIndex.ToString() + "页,选项卡为" + tabControl1.SelectedTab.Text + ",共有页数" + tabControl1.TabCount.ToString(); label8.Visible = true; } private void button10_Click(object sender, EventArgs e) { progressBar1.Visible = true; progressBar1.Minimum = 0; progressBar1.Maximum = 100; progressBar1.BackColor = Color.Red; for(int i=0; i<100;i++) { progressBar1.Value++; this.label9.Text = progressBar1.Value.ToString(); //有bug } } private void button11_Click(object sender, EventArgs e) { toolStripStatusLabel1.Text = "字数信息是: " + richTextBox1.Text.Length; } private void button12_Click(object sender, EventArgs e) { timer1.Start(); } private void button13_Click(object sender, EventArgs e) { timer1.Stop(); } private void timer1_Tick(object sender, EventArgs e) { pictureBox1.Left -= 5;// pictureBox1.Left -= 5; 语句是错误的 if(pictureBox1.Right<0) { pictureBox1.Left = Width; } } //直线 private void button14_Click(object sender, EventArgs e) { Graphics g = this.CreateGraphics(); Pen p = new Pen(Color.Black); g.DrawLine(p, 0, this.Height / 2, this.Width, this.Height / 2); p.Dispose(); g.Dispose(); } //圆 private void button15_Click(object sender, EventArgs e) { Graphics g = this.CreateGraphics(); Pen p = new Pen(Color.Black); Rectangle r = new Rectangle(200, 200, 200, 200);//圆 LinearGradientBrush brush = new LinearGradientBrush(r,Color.Orange,Color.Purple,90);//画刷 g.FillEllipse(brush, r);//用画 brush.Dispose(); //g.DrawEllipse(p, 600, 250, 100, 100); p.Dispose(); g.Dispose(); } //矩形 private void button16_Click(object sender, EventArgs e) { Graphics g = this.CreateGraphics(); Pen p = new Pen(Color.Red,3);//笔刷的宽度 Brush b = p.Brush;//用画笔作为笔刷 // g.DrawRectangle(p, 500, 250, 200, 100);//长200,高100, Rectangle r = new Rectangle(400, 200, 200, 100); g.FillRectangle(b, r); b.Dispose(); p.Dispose(); g.Dispose(); } //圆柱 private void button17_Click(object sender, EventArgs e) { int height = this.ClientSize.Height - 100; int width = this.ClientSize.Width - 50; int vHeigth = 200; int vWidth = 100; Graphics g = this.CreateGraphics(); g.Clear(Color.White); Pen pen = new Pen(Color.Gray); SolidBrush brush = new SolidBrush(Color.Gainsboro); for(int i=height/2;i>0;i--) { g.DrawEllipse(pen, width / 2, i, vHeigth, vWidth); } g.FillEllipse(brush,width/2,0,vHeigth,vWidth);//填充的时候用brush } //字体 private void button18_Click(object sender, EventArgs e) { Graphics g = this.CreateGraphics();//图像对象 Font f = new Font("隶书",24,FontStyle.Italic);//字体 Pen p = new Pen(Color.Blue);//画笔 g.DrawString("Windows应用程序设计", f, p.Brush, 50, 50); p.Dispose(); f.Dispose(); g.Dispose(); } //绘制新界面 private void mainform_Paint(object sender, PaintEventArgs e) { Graphics g = this.CreateGraphics();//图像 g.Clear(Color.White);// Pen myPen = new Pen(Color.Red, 3);//画笔 g.DrawRectangle(myPen, 600, 200, 200, 100);//矩形 g.DrawEllipse(myPen, 600, 200, 200, 100);//填充 g.Dispose(); myPen.Dispose(); } //坐标平移 private void button19_Click(object sender, EventArgs e) { Graphics g = this.CreateGraphics();//图像 g.Clear(Color.White);// Pen myPen = new Pen(Color.Red, 3);//画笔 g.TranslateTransform(30,120);//坐标平移,转换 g.DrawRectangle(myPen, 600, 200, 200, 100); g.DrawEllipse(myPen, 600, 200, 200, 100);//填充 g.Dispose(); myPen.Dispose(); } //坐标缩放 private void button20_Click(object sender, EventArgs e) { Graphics g = this.CreateGraphics();//图像 g.Clear(Color.White);// Pen myPen = new Pen(Color.Red, 3);//画笔 g.ScaleTransform(1, 2);// g.ScaleTransform(1.5 , 2);1.5不行! // g.TranslateTransform(30, 120);//坐标平移,转换 g.DrawRectangle(myPen, 600, 200, 200, 100); g.DrawEllipse(myPen, 600, 200, 200, 100);//填充 g.Dispose(); myPen.Dispose(); } //图片上加文字 private void button21_Click(object sender, EventArgs e) { Graphics g = Graphics.FromImage(pictureBox2.Image); Font f = new Font("隶书",80,FontStyle.Italic); Pen p = new Pen(Color.OrangeRed); g.DrawString("花开花落",f,p.Brush,0,0); p.Dispose(); g.Dispose(); pictureBox2.Refresh();//刷新 //pictureBox2.Image.Save(iamg); } //创建位图 private void button22_Click(object sender, EventArgs e) { Bitmap bm = new Bitmap(this.ClientSize.Width, this.ClientSize.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);//创建位图图像 Graphics g = Graphics.FromImage(bm);//图像对象 Font font = new Font("隶书",80,FontStyle.Italic);//字体 Pen pen = new Pen(Color.OrangeRed);//画笔 g.DrawString("winddows application disigner",font,pen.Brush,0,0);//写文字 pictureBox2.Image = bm;//加载图像 //bm.Save() pen.Dispose(); g.Dispose(); }
时间: 2024-10-25 17:26:27