p_dog_2007 Posted January 29, 2004 Posted January 29, 2004 I have a program that I'm going to use to make a map, I made it so on button press it draws the bitmap I want, in the next location, I want it to draw a new bitmap and leave the other there. I've atached the file, can any one help? buttonbitmap.zipFetching info... Quote
NK2000 Posted January 29, 2004 Posted January 29, 2004 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) Quote
NK2000 Posted February 2, 2004 Posted February 2, 2004 ups sorry i forgot you, i will code it now and send it in some minutes :) Quote
NK2000 Posted February 2, 2004 Posted February 2, 2004 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() ) Quote
p_dog_2007 Posted February 4, 2004 Author Posted February 4, 2004 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.