|
-
Sep 20th, 2021, 09:57 AM
#1
Thread Starter
Member
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
-
Sep 20th, 2021, 10:17 AM
#2
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.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 20th, 2021, 11:01 AM
#3
Thread Starter
Member
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.
-
Sep 20th, 2021, 12:30 PM
#4
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)
-
Sep 20th, 2021, 02:36 PM
#5
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
 
-
Sep 21st, 2021, 12:35 AM
#6
Thread Starter
Member
Re: Tiling one Form with a part of another Form
It did not help. It is still not drawing anything on Form71.
-
Sep 21st, 2021, 12:37 AM
#7
Thread Starter
Member
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.
-
Sep 21st, 2021, 12:44 AM
#8
Re: Tiling one Form with a part of another Form
Is Form70 visible and TopMost when you try to capture the image?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 21st, 2021, 12:46 AM
#9
Re: Tiling one Form with a part of another Form
CopyFromScreen doesn't work if the form isn't visible...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 21st, 2021, 02:04 AM
#10
Thread Starter
Member
Re: Tiling one Form with a part of another Form
No. It is not. This might be difficult to do.
-
Sep 21st, 2021, 02:05 AM
#11
Thread Starter
Member
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?
-
Sep 21st, 2021, 02:07 AM
#12
Thread Starter
Member
Re: Tiling one Form with a part of another Form
 Originally Posted by .paul.
Is Form70 visible and TopMost when you try to capture the image?
No. It is not. This might be difficult to do.
-
Sep 21st, 2021, 02:07 AM
#13
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...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 21st, 2021, 02:07 AM
#14
Thread Starter
Member
Re: Tiling one Form with a part of another Form
 Originally Posted by .paul.
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?
-
Sep 21st, 2021, 02:31 AM
#15
Re: Tiling one Form with a part of another Form
How did you try to put the whole form background in your image property?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 21st, 2021, 04:30 AM
#16
Thread Starter
Member
Re: Tiling one Form with a part of another Form
 Originally Posted by .paul.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|