madcrow74 Posted July 16, 2003 Posted July 16, 2003 i've assigned a background image to a MDI form. When i resize the form, the image retain the same size, but I want it to resize with the form. i've tried in the Resize event this code: Graphic g = this.CreateGraphic(); g.DrawImage(img, this.ClientRectangle); but it doesn't works... How can I do? Quote
*Gurus* divil Posted July 16, 2003 *Gurus* Posted July 16, 2003 Bitmap myBitmap = null; MdiClient client = null; private void Form1_Load(object sender, System.EventArgs e) { myBitmap = new Bitmap(@"c:\windows\coffee Bean.bmp"); SetStyle(ControlStyles.ResizeRedraw, true); foreach(Control c in Controls) { if (c is MdiClient) { client = (MdiClient)c; break; } } if (client != null) client.Paint += new PaintEventHandler(PaintMdiClient); } private void PaintMdiClient(object sender, PaintEventArgs e) { e.Graphics.DrawImage(myBitmap, client.Bounds); } 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
madcrow74 Posted July 16, 2003 Author Posted July 16, 2003 GREAT! But can you explain me two things? The MDIClient control is part of the Form or is the Form itself? What the "@" does? Instead of the Bitmap, can I use an Image loaded from a resource file? TY :-) Quote
*Experts* Volte Posted July 16, 2003 *Experts* Posted July 16, 2003 (edited) The MDIClient is the part of the form which can hold children; an MDI window is made of two parts: the main window, same as all the other windows, and an MDI client window, which is the part with the (usually) gray background that can hold other forms. In C#, preceding a string with @ tells it not to process escape codes (they are in this format: \x where x can be a number of different things). Without it, divil would have had to change the path to "C:\\windows\\coffee bean.bmp", because \\ is the escape code for \. However, telling it not to look at escape codes allows him to use \ without error. To use an image from a resource file:private Bitmap GetResourceImage(String name) { return new Bitmap(System.Reflection.Assembly.GetExecutingAssembly.GetManifestResourceStream(name)); }Now as long as you've marked the image you want in your resource file as "Embedded Resource" (for Build Action), you can replace the linemyBitmap = new Bitmap(@"c:\windows\coffee Bean.bmp");with this:myBitmap = GetResourceImage("MyNamespaceName.ImageIdentifier"); Edited July 16, 2003 by Volte Quote
madcrow74 Posted July 16, 2003 Author Posted July 16, 2003 If I would not use the foreach, can I find the MDIClient's index with a foreach, delete the foreach and permanently set the control's index to the found index? Quote
ballisticnylon Posted July 16, 2003 Posted July 16, 2003 (edited) I'm actually trying to do something similar, except I'm drawing a gradient across the MDI client area. The relevant code: Dim cli as MDIClient Private Sub Form1_Load(.....) Dim ctrl as Control For Each ctrl in Me.Controls If TypeOf (ctrl) Is MDIClient Then cli = ctrl AddHandler cli.Paint, AddressOf cli_Paint End If Next End Sub Private Sub cli_Paint(ByVal sender as Object, ByVal e as PaintEventArgs) Dim G as Graphics = e.Graphics Dim br As New System.Drawing.Drawing2D.LinearGradientBrush(New Point(0, 0), _ New Point(Me.Width, Me.Height), Color.Azure, Color.DarkBlue) G.FillRectangle(br, e.ClipRectangle) G.Dispose() End Sub My problem is with getting rid of the flicker when the form is resized. I've tried putting these lines in the form's constructor: SetStyle(ControlStyles.DoubleBuffer, True) SetStyle(ControlStyles.UserPaint, True) SetStyle(ControlStyles.AllPaintingInWmPaint, True) SetStyle(ControlStyles.ResizeRedraw, True) If I comment out the last line, it doesn't flicker, but it doesn't redraw the gradient for the new client size, either. I thought about adding another handler for cli.Resize, but the Event Argument that gets passed doesn't contain a graphics object. Does anyone know of a way to get rid of resizing flicker in this situation? Edited July 16, 2003 by ballisticnylon Quote "It may be roundly asserted that human ingenuity cannot concoct a cipher which human ingenuity cannot resolve." - Edgar Allan Poe, 1841 I long to accomplish great and noble tasks, but it is my chief duty to accomplish humble tasks as though they were great and noble. The world is moved along, not only by the mighty shoves of its heroes, but also by the aggregate of the tiny pushes of each honest worker. - Helen Keller
madcrow74 Posted July 17, 2003 Author Posted July 17, 2003 I saw that, if u add a toolbar to the MDIparent, it will not been redrawed, thus maintaining graphic garbage. 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.