c#,怎样将窗体分成几部分,然后加载不同的图片

huang_12345yong 2008-02-04 12:28:22
我现在再做一个项目,有个要求是要将窗体做成有3d效果的房间;所以我打算将窗体分成几部分,然后加载不同的图片(如墙,地板,分别用不同的图片),拼凑起来,实现3d的效果;不知道怎么怎样将窗体分成几部分,然后加载不同的图片。请大家指教
...全文
389 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
eagle_2008 2008-04-20
  • 打赏
  • 举报
回复
up`````````````````
grellen 2008-04-20
  • 打赏
  • 举报
回复
up
yingshis 2008-02-20
  • 打赏
  • 举报
回复
up
lake_cx 2008-02-18
  • 打赏
  • 举报
回复
画图的过程中不要用窗体,比如说PictureBox。
窗体是一种有父窗体,有边缘大小,能够响应鼠标事件的东西。
ztlover 2008-02-05
  • 打赏
  • 举报
回复
直接做一个3D效果的图片放在Form中不是简单,你图片都有了,拼起来就是一个3D效果了!
lake_cx 2008-02-04
  • 打赏
  • 举报
回复
图片不规则??有非矩形的图片么?(只有那种支持透明色的图片)

思路是:
例如,窗体有上、左、右三张图片
Image imgLeft;
Image imgTop;
Image imgRight;

代码给你参考下
public partial class Form2 : Form
{
private Image imgLeft;
private Image imgTop;
private Image imgRight;

public Form2()
{
InitializeComponent();
imgLeft = Image.FromFile("");
imgTop = Image.FromFile("");
imgRight = Image.FromFile("");
}

private void DrawImage(Graphics g)
{
Rectangle rect = new Rectangle();
//这里计算imgLeft的rect
g.DrawImage(imgLeft, rect);
//这里计算imgTop的rect
g.DrawImage(imgTop, rect);
//这里计算imgRight的rect
g.DrawImage(imgRight, rect);
}

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
DrawImage(e.Graphics);
}

private void button1_Click(object sender, EventArgs e)
{
//操作imgLeft、imgTop、imgRight改变图像
Invalidate();//强制重绘(可以传一个Rectangle区域,告诉它只重绘改变区域,提高效率)
//这样背景图就马上变量
}
}
huang_12345yong 2008-02-04
  • 打赏
  • 举报
回复
我用的是c#哈
huang_12345yong 2008-02-04
  • 打赏
  • 举报
回复
呵呵,但是我的图片不规则,计算位置因为很困难吧,还有我画出来以后,需要随时修改,可以实现吗?
lake_cx 2008-02-04
  • 打赏
  • 举报
回复
重载OnPaint函数中自己画就行了,需要你自己根据窗体客户区计算每个图片的位置和大小
也可以重载话窗体背景的函数去画图片,画图不难,查下MSDN很快就能搞定。
lextm 2008-02-04
  • 打赏
  • 举报
回复
看你的需求,使用Windows Forms来做肯定是十分困难的。建议用WPF来做界面,使用Visual Studio 2008.WPF做3D效果要好一些,但是执行效率仍然不够高。有条件的话,用DirectX或者OpenGL来做是最可靠的。不过任何做法,都复杂的可以写一本书了。
cloudgamer 2008-02-04
  • 打赏
  • 举报
回复
建议用flash来做
js的话要看图形规不规则
不规则的话可能要用点阵可以参考那些js游戏
huang_12345yong 2008-02-04
  • 打赏
  • 举报
回复
DotNetBar 是什么东西啊? 没用过,那位知道的,说说,请结合我的 要求
liwang003 2008-02-04
  • 打赏
  • 举报
回复
你可以用第三方控件做啊,比如 DotNetBar
pears2017ms 2008-02-04
  • 打赏
  • 举报
回复
画图方面俺还是空白,帮你顶一个吧
huang_12345yong 2008-02-04
  • 打赏
  • 举报
回复
上面的代码已经将窗体分成了5个区域myPath myPath1 myPath2 myPath3 myPath4 ,那位再给我点建议,怎样在这些去区域加载图片呢
huang_12345yong 2008-02-04
  • 打赏
  • 举报
回复
我其实是想将一个窗体分割成房间顶,房间低,四面墙,然后对这几部分区域填充不同的颜色或者图片,就会形成3D效果。
我需要的不是规则的矩形哈,其实是一个五边形,谢谢楼上的,给我提供了一种思路。
我的做法: 我重载了
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
AddPathExample(e);

}
private void AddPathExample(PaintEventArgs e)
{
Pen myPen = new Pen(Color.Black, 2);


// Create the first pathright side up triangle.
Point[] myArray =
{
new Point(00,00),
new Point(200,200),
new Point(400,200),
new Point(600,00),
new Point(00,00),
};
GraphicsPath myPath = new GraphicsPath();

myPath.AddLines(myArray);
PictureBox mypic = new PictureBox();
mypic.BackColor = Color.FromArgb(123, 0, 234);
mypic.Region = new Region(myPath);
// this.Controls.Add(mypic);
e.Graphics.DrawPath(myPen, myPath);


// Create the second pathinverted triangle.
Point[] myArray2 =
{
new Point(600,00),
new Point(400,200),
new Point(400,400),
new Point(600,600),
new Point(600,00),
};
GraphicsPath myPath2 = new GraphicsPath();
myPath2.AddLines(myArray2);
PictureBox mypic1 = new PictureBox();
mypic1.BackColor = Color.FromArgb(23, 0, 24);
mypic1.Region = new Region(myPath2);
this.Controls.Add(mypic1);

// myPath.FillMode = FillMode.
e.Graphics.DrawPath(myPen, myPath2);

Point[] myArray3 =
{
new Point(0,600),
new Point(200,400),
new Point(400,400),
new Point(600,600),
new Point(0,600),
};
GraphicsPath myPath3 = new GraphicsPath();
myPath3.AddLines(myArray3);
e.Graphics.DrawPath(myPen, myPath3)
Point[] myArray4 =
{
new Point(0,600),
new Point(200,400),
new Point(200,200),
new Point(00,00),
new Point(0,600),
};
GraphicsPath myPath4 = new GraphicsPath();
myPath3.AddLines(myArray4);
e.Graphics.DrawPath(myPen, myPath4);

Point[] myArray5 =
{
new Point(200,200),
new Point(400,200),
new Point(400,400),
new Point(200,400),
new Point(200,200),
};
GraphicsPath myPath5 = new GraphicsPath();
myPath5.AddLines(myArray5);
e.Graphics.DrawPath(myPen, myPath5);
// Add the second path to the first path.
myPath.AddPath(myPath2, true);
// Draw the combined path to the screen.
e.Graphics.DrawPath(myPen, myPath);
}
然后用GraphicsPath 得到一个特定区域,用线画出了特定区域,但是还不能加载图片。 本来打算用PictureBox 将得到的myPath赋给mypic.Region,但是发现好像画出的picturebox大小不对,变得很小。
我打算用楼上提供的方法实施哈。

111,119

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧