本人最近欲实用C#开发一个简单的绘图程序
通常使用
theImage = new Bitmap (this.ClientRectangle .Width ,this.ClientRectangle .Height );
就可以在Form中创建绘图工作区可是本人在From中添加了tabControl控件后且Dock属性为Fill,想把绘图工作区建立在tabControl的其中一个页面上,却看不到绘图区,且进行一些绘图操作后,看不到绘图结果,保存图像也看不到。还请达人出手相救啊!!先谢了!
通常使用
theImage = new Bitmap (this.ClientRectangle .Width ,this.ClientRectangle .Height );
就可以在Form中创建绘图工作区可是本人在From中添加了tabControl控件后且Dock属性为Fill,想把绘图工作区建立在tabControl的其中一个页面上,却看不到绘图区,且进行一些绘图操作后,看不到绘图结果,保存图像也看不到。还请达人出手相救啊!!先谢了!
要想实现你说的,就得在你绘图时,去得到Tab的Graphics,然后就用这个Graphics画,再保存,就可以看到了。
void paint(Graphics g)
{
// do your painting...
}protected overrided viod OnPaint(PaintEnvetArgs e)
{
using(Graphics g = Graphics.FromHwndInternal(tabControl.Handle))
{
paint(g);
}
}
的正确,你也可以把TAB去掉试下
private void menuItem3_Click(object sender, System.EventArgs e)
{
Graphics g = this.CreateGraphics();
g.Clear(backColor);
//创建一个Bitmap
theImage = new Bitmap(this.ClientRectangle .Width ,this.ClientRectangle .Height );
editFileName = "新建文件名";
ig = Graphics.FromImage (theImage);
ig.Clear (backColor);
}我根据你提供的代码的提示,将我的代码中的:
ig = Graphics.FromImage (theImage);
修改为:
ig=Graphics.FromHwndInternal(this.tabControl1.Handle);
修改后就建立了绘图区,因为已经可以看到我设定的绘图区的背景色,但是还是建立在TabControl之后的Form上,
Sample code as follows:
Graphics g = yourTabPage.CreateGraphics();
g.Clear(backColor);
//创建一个Bitmap
theImage = new Bitmap( yourTabPage.ClientRectangle.Width ,yourTabPage.ClientRectangle .Height );
editFileName = "新建文件名";
ig = Graphics.FromImage (theImage);
ig.Clear (backColor);
我试过了可还是不行啊,绘图工作区还是建立在Form上面,没有在tabControl的tabPage上。
不知道你有完整的方案吗?
给个参考吧