我已创建此应用程序,如下图所示。
现在,如果我将右侧窗口向左移动一点,如下图所示,
我的第一个(或左边的那个)MDI窗口的图形已经消失,如下所示。
事实上,每当我最小化我的表格时,两个窗户的内容都消失了。我正在使用图形对象在面板上绘制。这是我的孩子表格的代码。主窗体只有一个菜单文件,其中有一个名为new的子菜单,它基本上打开了这个子窗体。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MDITest
{
public partial class EnhancedPainter : Form
{
bool paint = false;
string color = "Red";
int size = 5;
public EnhancedPainter()
{
InitializeComponent();
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
paint = true;
}
private void panel1_MouseUp(object sender, MouseEventArgs e)
{
paint = false;
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (paint)
{
Graphics g = panel1.CreateGraphics();
g.FillEllipse(new SolidBrush(Color.FromName(color)), e.X, e.Y, size, size);
//g.Dispose();
}
}
private void redRadioButton_CheckedChanged(object sender, EventArgs e)
{
color = "Red";
}
private void greenRadioButton_CheckedChanged(object sender, EventArgs e)
{
color = "Green";
}
private void blueRadioButton_CheckedChanged(object sender, EventArgs e)
{
color = "Blue";
}
private void blackRadioButton_CheckedChanged(object sender, EventArgs e)
{
color = "Black";
}
private void smallRadioButton_CheckedChanged(object sender, EventArgs e)
{
size = 5;
}
private void mediumRadioButton_CheckedChanged(object sender, EventArgs e)
{
size = 10;
}
private void largeRadioButton_CheckedChanged(object sender, EventArgs e)
{
size = 15;
}
private void resetButton_Click(object sender, EventArgs e)
{
Graphics g = panel1.CreateGraphics();
g.FillRectangle(new SolidBrush(Color.White), 0, 0, panel1.Width, panel1.Height);
g.Dispose();
}
}
}
那么我该如何防止这种情况发生呢?
由于