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
Re: Tiling one Form with a part of another Form
Is your Form70 the default instance or a new instance?
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.
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
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)?
Re: Tiling one Form with a part of another Form
It did not help. It is still not drawing anything on Form71.
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.
Re: Tiling one Form with a part of another Form
Is Form70 visible and TopMost when you try to capture the image?
Re: Tiling one Form with a part of another Form
CopyFromScreen doesn't work if the form isn't visible...
Re: Tiling one Form with a part of another Form
No. It is not. This might be difficult to do.
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?
Re: Tiling one Form with a part of another Form
Quote:
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.
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...
Re: Tiling one Form with a part of another Form
Quote:
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?
Re: Tiling one Form with a part of another Form
How did you try to put the whole form background in your image property?
Re: Tiling one Form with a part of another Form
Quote:
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.