Results 1 to 16 of 16

Thread: Tiling one Form with a part of another Form

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2021
    Posts
    46

    Tiling one Form with a part of another Form

    I want to tile one Form with a small portion of another Form. What am I doing wrong?

    Code:
    Public Class Form71
    
        Dim backImg As New Bitmap(Form70.Picture1.Image) ' 214 by 169
        Dim tBr As New TextureBrush(backImg, wrapMode:=Drawing2D.WrapMode.TileFlipXY)
    
    '   Then we will replace the image with another one in Form_Load
    
        Private Sub Form71_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            Dim NewImage As New Bitmap(80, 60)
            Using g As Graphics = Graphics.FromImage(NewImage)
                g.CopyFromScreen(Form70.Location.X, Form70.Location.Y, 400, 100, NewImage.Size)
    '    One of these two things should work but neither is working
                g.DrawImage(Form70.frmImage, New Rectangle(400, 100, 80, 60))
            End Using
            tBr = New TextureBrush(NewImage, wrapMode:=Drawing2D.WrapMode.TileFlipXY)
            Me.Refresh()
    
        Private Sub Form71_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
            e.Graphics.FillRectangle(tBr, ClientRectangle)
        End Sub

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Tiling one Form with a part of another Form

    Is your Form70 the default instance or a new instance?
    Last edited by .paul.; Sep 20th, 2021 at 10:31 AM.

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2021
    Posts
    46

    Re: Tiling one Form with a part of another Form

    Form70 is used first. Then one can come to Form71. Form70 is not disposed. Only hidden.

  4. #4
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    846

    Re: Tiling one Form with a part of another Form

    did you hide the form before getting the part you want ? it may come from that. try without hiding form70
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: Tiling one Form with a part of another Form

    Whether it is used first or not wasn't the question. The question was whether it was the default instance, which is a different matter. The code you are showing is taking a clip from the default instance. If that isn't the instance you are looking at, then it might be working just fine, you just aren't seeing what you expect to see.

    However, what is it that isn't working? Are you seeing nothing? Are you getting an error message (and if so, what is it)?
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    Member
    Join Date
    Jul 2021
    Posts
    46

    Re: Tiling one Form with a part of another Form

    It did not help. It is still not drawing anything on Form71.

  7. #7

    Thread Starter
    Member
    Join Date
    Jul 2021
    Posts
    46

    Re: Tiling one Form with a part of another Form

    Yes. It is the default instance. (I have never used anything else.)

    It is not complaining but just not drawing anything on Form71. I just get a gray background on Form71.

    If I use the tBrush with Form70.Picture1 it shows that nicely. But if I change the image of the tBrush then it is not drawing anything.

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Tiling one Form with a part of another Form

    Is Form70 visible and TopMost when you try to capture the image?

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Tiling one Form with a part of another Form

    CopyFromScreen doesn't work if the form isn't visible...

  10. #10

    Thread Starter
    Member
    Join Date
    Jul 2021
    Posts
    46

    Re: Tiling one Form with a part of another Form

    No. It is not. This might be difficult to do.

  11. #11

    Thread Starter
    Member
    Join Date
    Jul 2021
    Posts
    46

    Re: Tiling one Form with a part of another Form

    OK. But I have also tried to put the whole form background on frmImage. And then from another Form I try to take a part of that frmImage. That too does not work. Why?

  12. #12

    Thread Starter
    Member
    Join Date
    Jul 2021
    Posts
    46

    Re: Tiling one Form with a part of another Form

    Quote Originally Posted by .paul. View Post
    Is Form70 visible and TopMost when you try to capture the image?
    No. It is not. This might be difficult to do.

  13. #13
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Tiling one Form with a part of another Form

    Is it a picturebox with a dynamically loaded image? Form70.frmImage should work as long as you set the property at the right time...

  14. #14

    Thread Starter
    Member
    Join Date
    Jul 2021
    Posts
    46

    Re: Tiling one Form with a part of another Form

    Quote Originally Posted by .paul. View Post
    CopyFromScreen doesn't work if the form isn't visible...
    OK. But I have also tried to put the whole form background on frmImage. And then from another Form I try to take a part of that frmImage. That too does not work. Why?

  15. #15
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Tiling one Form with a part of another Form

    How did you try to put the whole form background in your image property?

  16. #16

    Thread Starter
    Member
    Join Date
    Jul 2021
    Posts
    46

    Re: Tiling one Form with a part of another Form

    Quote Originally Posted by .paul. View Post
    How did you try to put the whole form background in your image property?
    More details are in the original post but here is that part:

    Code:
       Using g As Graphics = Graphics.FromImage(NewImage)
    '            g.CopyFromScreen(Form70.Location.X, Form70.Location.Y, 400, 100, NewImage.Size)
    '    One of these two things should work but neither is working
                g.DrawImage(Form70.frmImage, New Rectangle(400, 100, 80, 60))
            End Using
    frmImage contains the whole image for Form70. I want to take a part of it and tile it on Form71.

Tags for this Thread

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