使用GDI+从数据库中读取数据进行绘图遇到若干问题,求教!!急!!
我从数据库中读取一组数据,然后在窗口上绘制若干个矩形,并在矩形内填充颜色并写上响应的文字,我要在鼠标单击其中一个矩形时该点中的矩形的填充色就改变。
在实现上述功能我遇到以下问题:
1、当窗口最小化再恢复时,所画的图形没了(我知道一般做法是在onpaint里写代码,但我为了实现上诉功能我想有没有其他方法)
2、当我改变填充色时,该点中的矩形中的文字就没了
改变填充色,我使用一下代码实现:
private void Panel_Click(object sender, System.EventArgs e)
{
Point p = this.PointToClient(Cursor.Position);
if(this._activeIndex == -1)
this.getActiveIndexAtPoint(p);
if(this._activeIndex > -1 && this.RegionClick != null)
{
this._graphics.DrawPath(Pens.BurlyWood,this._Temppath);
this.RegionClick(this._activeIndex, this._pathsArray[this._activeIndex].ToString());
}
}
////////////////////////////////////////////////////////
private int getActiveIndexAtPoint(Point point)
{
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
System.Drawing.Drawing2D.GraphicsPathIterator iterator = new System.Drawing.Drawing2D.GraphicsPathIterator(_pathData);
iterator.Rewind();
for(int current=0; current < iterator.SubpathCount; current++)
{
iterator.NextMarker(path);
if(path.IsVisible(point, this._graphics))
{
_Temppath = path;
//this._graphics.DrawPath(Pens.Blue,path);
return current;
}
}
return -1;
}