0

I need to paint images from one panel to another panel like painting colors in a Windows Forms application but not colors, only Images.
I use an OpenFileDialog to open multiple images onto a panel and then paint those images by clicking on one and painting it with my mouse to the panel2.

My code for the openstripmenuitem:

private void openProjectToolStripMenuItem_Click(object sender, EventArgs e)
{
    OpenFileDialog ofd = new OpenFileDialog();
    ofd.Title = "Please select your files";
    ofd.Multiselect = true;
    ofd.Filter = "PNG|*.png|JPEG|*.jpeg|GIF|*.gif|TGA|*.tga|DDS|*.dds";
    DialogResult dr = ofd.ShowDialog();
    if (dr == System.Windows.Forms.DialogResult.OK)
    {
        string []files = ofd.FileNames;
        int x = 20;
        int y = 20;
        int maxheight = -1;
        foreach(string img in files)
        {
            PictureBox pic = new PictureBox();
            pic.Image = Image.FromFile(img);
            pic.Location = new Point(x, y);
            pic.SizeMode = PictureBoxSizeMode.StretchImage;
            x += pic.Width + 10;
            maxheight = Math.Max(pic.Height, maxheight);
            if (x > this.ClientSize.Width - 100)
            {
                x = 20;
                y += maxheight + 10;
            }
            this.flowLayoutPanel1.Controls.Add(pic);


        }

    }
}

Any advice code examples welcome or link to references.

Jimi
  • 22,563
  • 6
  • 34
  • 49
John Nay
  • 13
  • 4
  • 2
    [TextureBrush](https://docs.microsoft.com/en-us/dotnet/api/system.drawing.texturebrush) class. – Jimi May 09 '19 at 23:24
  • Give me a c# code Example. Please, I'm not sure where to start. – John Nay May 10 '19 at 00:34
  • 1
    I can show you how to use a TextureBrush without crashing the application or causing it to flicker as hell, but you need to show you understand the basics of these tools. Otherwise, you'll never be able to get it to work. You need to know, at least, how to paint a shape, how [Graphics.TranslateTransform](https://docs.microsoft.com/en-us/dotnet/api/system.drawing.graphics.translatetransform) works, or how to use a Matrix transformation. See the notes about the Matrix class and a sample code here: [Flip the GraphicsPath that draws the text](https://stackoverflow.com/a/53182901/7444103) – Jimi May 10 '19 at 02:28
  • 1
    You may also want to [study this post](https://stackoverflow.com/questions/49290951/creating-different-brush-patterns-in-c-sharp/49298313#49298313), which looks like color painting but really uses bitmaps as brush patterns.. – TaW May 10 '19 at 07:20
  • @Jimi: Did you note the update in my post? I talks about limitations of TextureBrushes.. – TaW May 10 '19 at 12:36
  • 1
    @TaW Yes, I know your post quite well (voted up that one and the other you linked a while ago). Anyway, in relation to what the OP is proposing, a TextureBrush initialized with `WrapMode.Clamp`, can paint non-tiled Images relatively well, if this is what you're referring to. Of course, you have to fill a shape with it, it won't be as smooth as the direct .DrawImage result or a complex Pen mixed with a Blend class, transparency and whatnot. I'll build up and post somethig OP-related, if you want. – Jimi May 10 '19 at 13:07
  • @Jimi Yes, I would like that post it. – John Nay May 10 '19 at 13:54
  • @Jimi Yes, I would like that, and I understand what you are saying I can fill a rectangle shape with a texture aka image like here is my code example: https://textuploader.com/1d9qa but I need to do this a little different I have 1x openstripmenuitem, 1x flowoutpanel, 1x panel | my flowoutpanel holds the images and the panel paints the images from clicking on the images in the flowoutpanel my openstripmenuitem opens an openfiledialog with multi-select to add the images to the flowoutpanel – John Nay May 10 '19 at 14:04
  • All right, I'll post an example. Maybe, update your question with something related to what you're asking: as of now, you're showing how to use an `OpenFileDialog`. – Jimi May 10 '19 at 14:54
  • @Jimi thanks much appreciated. – John Nay May 10 '19 at 20:35
  • @Jimi Ive got this far with the tool here is my code https://textuploader.com/1d9ws I also show a pic here https://imgur.com/a/VeCL3RK but im only drawing 1 image The window called tiles I need to be able to click on one of those images and paint to the form instead of painting an image from the image URL path. I dont want it this way here "Image image = Image.FromFile("C:\\Users\\Duck\\source\\repos\\mitt\\mitt\\bin\\Debug\\game assets\\Tileable1c.png");" – John Nay May 11 '19 at 14:27

0 Answers0