Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
you should make a big bitmap which is empty at start and then you just draw in the bitmaps for every location and at the paint event you just draw the whole big bitmap (like doublebuffering)
Posted

after noticing that i forgot you and making the promise to code it, i noticed (again) that your code is in vb.net, which is a problem since i am coding in c#

 

nevertheless i coded it in c# and hope you understand everything, if not just ask!

 

using System;
using System.IO;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace ButtonBitmap
{
public class Form1 : System.Windows.Forms.Form
{
	private string Filename = "ground.bmp";
	private int X = 0;
	private int Y = 0;
	private int MaxX = 5;
	private int MaxY = 5;
	private Bitmap Tile = null;
	private Bitmap Map = null;
	
	private System.Windows.Forms.Button GroundBtn;

	private System.ComponentModel.Container components = null;

	public Form1()
	{
		InitializeComponent();
	}

	protected override void Dispose( bool disposing )
	{
		if( disposing )
		{
			if (components != null) 
			{
				components.Dispose();
			}
		}
		base.Dispose( disposing );
	}

	#region Windows Form Designer generated code
	/// <summary>
	/// Erforderliche Methode für die Designerunterstützung. 
	/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
	/// </summary>
	private void InitializeComponent()
	{
		this.GroundBtn = new System.Windows.Forms.Button();
		this.SuspendLayout();
		// 
		// GroundBtn
		// 
		this.GroundBtn.Location = new System.Drawing.Point(192, 32);
		this.GroundBtn.Name = "GroundBtn";
		this.GroundBtn.Size = new System.Drawing.Size(88, 32);
		this.GroundBtn.TabIndex = 0;
		this.GroundBtn.Text = "Make Ground";
		this.GroundBtn.Click += new System.EventHandler(this.GroundBtn_Click);
		// 
		// Form1
		// 
		this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
		this.ClientSize = new System.Drawing.Size(292, 273);
		this.Controls.AddRange(new System.Windows.Forms.Control[] {
																	  this.GroundBtn});
		this.Name = "Form1";
		this.Text = "Form1";
		this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
		this.ResumeLayout(false);

	}
	#endregion

	[sTAThread]
	static void Main() 
	{
		Application.Run(new Form1());
	}

	private void GroundBtn_Click(object sender, System.EventArgs e)
	{
		if (Tile == null) //init
		{
			if (File.Exists(Filename))
			{
				Tile = new Bitmap(Filename);
				Map = new Bitmap(Tile.Width*MaxX, Tile.Height*MaxY);
			}
		}
		if ((Tile != null) && (Map != null))
		{
			Graphics g = Graphics.FromImage(Map);
			g.DrawImage(Tile,X*Tile.Width,Y*Tile.Height);
		
			// Preparation for next Image!
			++X;

			if (X >= MaxX)
			{
				X = 0;
				++Y;
			}

			if (Y >= MaxY)
				Y = 0;

			((Control)sender).Parent.Refresh(); // Refreshing Form1 !
		}
	}

	private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
	{
		if (Map != null)
		{
			e.Graphics.DrawImage(Map, ClientRectangle.X, ClientRectangle.Y);
		}
	}
}
}

 

 

I also found out that you have a drawing problem if your app was hidden by another window ( which also leads to a OnPaint() )

Posted

thanks!

 

Thank you so much, Just what I needed. One more prob. tho, if I added Another button, say "PathBtn", I can change it so it makes the path just fine but when I click the ground btn agan then it makes a path....? I did it useing, Tile=new bitmap("tiles/path.bmp"), In the PathBtn_Click, now if i put, Tile=new Bitmap("tiles/gtound.bmp"), In the groundbtn_click, when I run the program Neither buttion does any thing, with only the tile= new bitmap("tiles/path.bmp") in the pathbtn_click it changes over, but then if I add the tile=new bitmap("tiles/ground.bmp") in the groundbtn_click then it wont do anything for either.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...