回复 10# ghl2312 的帖子
就是有两个窗体,当点击Form1上的按钮时,转到form2窗体显示画的图像,不用什么MDI吧,我新手,觉得MDI就是文档之类的。。。。
提示: 作者被禁止或删除 内容自动屏蔽
程序代码:/*
* Created by SharpDevelop.
* User: hellson
* Date: 2008-10-8
* Time: 17:00
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace draws
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm
{
Form f = new Form();
int a=0,b=0;
[STAThread]
public static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
private void Button1Click(object sender, EventArgs e)
{
a = Convert.ToInt32(textBox1.Text);
if (textBox2.Visible)
b = Convert.ToInt32(textBox2.Text);
this.Hide();
f.Paint += new System.Windows.Forms.PaintEventHandler(this.MainFormPaint);
f.Show();
}
void MainFormPaint(object sender, System.EventArgs e){
Graphics g = f.CreateGraphics();
Pen pen = new Pen(Color.Red, 2);
switch (comboBox1.Text)
{
case "正方形":
{
g.DrawRectangle(pen, 10, 10,a, a);
break;
}
case "长方形":
{
g.DrawRectangle(pen, 10, 10, a, b);
break;
}
case "圆":
{
g.DrawEllipse(pen, 10, 10, a, a);
break;
}
}
g.Dispose();
f.Show();
}
void ComboBox1SelectedIndexChanged(object sender, System.EventArgs e)
{
switch (comboBox1.Text)
{
case "正方形":
{ label1.Text = "正方形的边长";
//a= Convert.ToInt32 (textBox1.Text);
label2.Visible = false;
textBox2.Visible = false;
label3.Visible = false;
textBox3.Visible = false;
break;
}
case "长方形":
{
label1.Text = "长方形的长";
//int a = Convert.ToInt32(textBox1.Text);
//int b = Convert.ToInt32(textBox2.Text);
label2.Text = "长方形的宽";
label2.Visible = true;
textBox2.Visible = true;
label3.Visible = false;
textBox3.Visible = false;
/*Graphics g = f.pictureBox1.CreateGraphics();
Pen pen = new Pen(Color.Red, 2);
g.DrawRectangle(pen, 10, 10, a, b);*/
break;
}
case"圆形":
{label1.Text = "圆形的半径";
label2.Visible = false;
textBox2.Visible = false;
label3.Visible = false;
textBox3.Visible = false;
break;
}
}
}
}
}
