CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2013
    Location
    Georgia
    Posts
    4

    Using Graphics and Picture Boxes

    [Edit] Solved

    Hey again! You guys were pretty helpful last time, so I wanted to see if I could bug you again! Heh...

    Anyhow... I'm stumped. :x Been following a few leads but I haven't gotten anywhere solid.

    I wanted to use a picture box to display graphics loaded from a file. In VB6, I would have loaded the tilesheet in a rectangle of its own, then using program code, and a map object, I could display parts of the tilesheet rectangle in their appropriate locations on a seperate rectangle that served as the game screen. This rectangle would display itself on a picturebox control.

    I wanted to know if it would be possible to recreate that, if anyone else has ever attempted or even read something about this.

    I'll continue to Google around and read through books and APIs, I just wanted to know if anyone would know how I would go about starting this.

    Thanks!
    Last edited by solrachet; November 17th, 2013 at 05:26 AM.

  2. #2
    Join Date
    Nov 2013
    Location
    Georgia
    Posts
    4

    Re: Using Graphics and Picture Boxes

    I hope I'm not violating any rules by double posting, but I wanted to bump this post updating with some progress.

    I've gotten to the point to where I have the following code written (more like c&p'd/tweaked).

    Code:
    public partial class frmMapEditor : Form
        {
            public Image gfxTiles;
            public Graphics screenMain;
    
            public frmMapEditor()
            {
                InitializeComponent();
            }
    
            private void frmMapEditor_Load(object sender, EventArgs e)
            {
                screenMain = picMap.CreateGraphics();
    
                // Create image.
                //Image newImage = Image.FromFile("SampImag.jpg");
                gfxTiles = Image.FromFile(@Program.filePath + "Resources\\Tiles\\poatiles.png");
    
                // Create coordinates for upper-left corner of image. 
                int x = 1;
                int y = 1;
    
                // Create rectangle for source image.
                Rectangle srcRect = new Rectangle(16, 16, 16, 16);
                GraphicsUnit units = GraphicsUnit.Pixel;
    
                // Draw image to screen.
                screenMain.DrawImage(gfxTiles, x, y, srcRect, units);
            }
        }
    So now I build and run and I expect it to display a corner of the image I have, and nothing pops up. I even tried to change the name of the picture in the code to purposefully try to get it to throw an exception. I got nothing there, too.

    Am I missing something?

    [Edit] Figured it out, this thread can actually be deleted. xD Nothing came out of it. Sorry for wasting time/space.
    Last edited by solrachet; November 17th, 2013 at 05:25 AM.

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Using Graphics and Picture Boxes

    Quote Originally Posted by solrachet View Post
    [Edit] Figured it out, this thread can actually be deleted. xD Nothing came out of it. Sorry for wasting time/space.
    It might be a complete waste for you, but for many other members that will stumble upon this thread through a search, will be very unhappy. Why? Because you haven't shared your answer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured