Creative2 Posted January 28, 2003 Posted January 28, 2003 Hi guys, I am using a background in my form, is there anyway that if the size of form changes (gets bigger) the image streches, right now my form is tiling the image. I tried to set the size of image but height and width are read only properties. Any Suggestions? I would apreciate your help. Quote
*Experts* Volte Posted January 28, 2003 *Experts* Posted January 28, 2003 Not sure this is the best way to do it, but I know this works. Change the constructor of your form to this (it's in the WinForms Generated Region): Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call SetStyle(ControlStyles.ResizeRedraw, True) setstyle(ControlStyles.AllPaintingInWmPaint, True) setstyle(ControlStyles.DoubleBuffer, True) End Sub And then add this to your Paint event of the form: Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint Dim b As Bitmap = Me.BackgroundImage Dim g As Graphics = e.Graphics g.DrawImage(b, Me.DisplayRectangle) End Subdivil will probably come by and tell me how much my method sucks, but meh; I don't know of any other way. :p Quote
*Gurus* divil Posted January 28, 2003 *Gurus* Posted January 28, 2003 I would have a picturebox as the background of my form, with its dock mode set to Fill so it takes up the whole form. Then any child controls can be placed on it. You can set the Image property of the picturebox to load your picture in, then the SizeMode of it to StretchImage. That should do what you need. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Experts* Volte Posted January 28, 2003 *Experts* Posted January 28, 2003 Wow, I was going to suggest that, but it seems even slimier. :p It does seem very effective though. Quote
Creative2 Posted January 29, 2003 Author Posted January 29, 2003 I tried picture box, but the problem is that I am using transparent labels and when i use picture box, labels show the color of the form, and Form cant be transparent. is there anyway around it? Quote
*Experts* Volte Posted January 29, 2003 *Experts* Posted January 29, 2003 When doing it my way, does it still do that? Quote
Creative2 Posted January 29, 2003 Author Posted January 29, 2003 I havent tried yours volteface, I will try tomorrow and let you know, and thank you very much guys for the help. sso in your method the image will stretch by itself or i will have to set the size properties? Quote
*Experts* Volte Posted January 29, 2003 *Experts* Posted January 29, 2003 With my way the image will stretch by itself in the .DrawImage method (that second parameter is the size to draw it as, and in this case, we're setting it to the size of the form). Quote
Creative2 Posted January 29, 2003 Author Posted January 29, 2003 Yeah Volteface it worked, now I am struggling to change the size and locations of my controls, never ending process :), Thanx a lot for your help. Quote
infimo Posted September 11, 2004 Posted September 11, 2004 Thanks Volteface Your code helped me out too!! Infimo Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.