我不想在OnPaint里来绘制图,我在外面建了一个函数,然后调用这个函数,函数来进行画图。怎么做呀?
public void vGdi_impact(object ob, int iType, int x, int y, int w, int h,string simge,ResourceManager rRm)
{
Type tType=ob.GetType();
bImg = (Bitmap)rRm.GetObject(simge);
sPonint = new int[4] { x, y, w, h };
if (iType == 1)
{
switch (tType.FullName)
{
case"System.Windows.Forms.Panel":
System.Windows.Forms.Panel obs = (System.Windows.Forms.Panel)ob;
obs_Paint(obs,new PaintEventArgs(obs.CreateGraphics(),obs.ClientRectangle));
break;
}
}
} void obs_Paint(object sender, PaintEventArgs e)
{
Graphics g =e.Graphics;
g.DrawImage(bImg, sPonint[0], sPonint[1], sPonint[2], sPonint[3]);
}
为什么不能执行呀???我要在一张图里,在画两个小图。
public void vGdi_impact(object ob, int iType, int x, int y, int w, int h,string simge,ResourceManager rRm)
{
Type tType=ob.GetType();
bImg = (Bitmap)rRm.GetObject(simge);
sPonint = new int[4] { x, y, w, h };
if (iType == 1)
{
switch (tType.FullName)
{
case"System.Windows.Forms.Panel":
System.Windows.Forms.Panel obs = (System.Windows.Forms.Panel)ob;
obs_Paint(obs,new PaintEventArgs(obs.CreateGraphics(),obs.ClientRectangle));
break;
}
}
} void obs_Paint(object sender, PaintEventArgs e)
{
Graphics g =e.Graphics;
g.DrawImage(bImg, sPonint[0], sPonint[1], sPonint[2], sPonint[3]);
}
为什么不能执行呀???我要在一张图里,在画两个小图。
你居然还出现
obs_Paint(obs,new PaintEventArgs(obs.CreateGraphics(),obs.ClientRectangle));
难道你知道什么时候该重绘了?
但是随便怎么都只会画一个图,我想写个函数,让图片在加载的时候,都从这个函数来进行画图。
意思就是,obs被其他窗体盖住了,被你点击它要被显式出来的时候,就会调用obs_Paint函数
这个函数本来就是用来绘图的,所以顺便把Graphics对象给你准备好了一般只有这种做法
void obs_Paint(object sender, PaintEventArgs e)
{
DrawImage(Graphics g);
Draw...
...
}void DrawImage(Graphics g);
{
//计算位置大小等
//然后用g进行画图
}