Friday, December 19, 2014

WPF - Redrawing the whole control on resize - Coded in C# [C-Sharp]VB, C++ (Open Source)


Can't Afford A Bot? Buy SEO & Social Media Metrics For Cheap Starting at $1 Dollar



Redrawing The Whole Control On Resize[C#]

CODE WRITTEN BY: JASON "JAY STILLA" LEE

Written By Jason Jay Stilla Lee - Programmer / Musician 
Enjoy The Music While You Study This Code or Copy and Paste into .CS
Coded: C#  Text Editor: Visual Studios 2013  Project: Windows Forms - WPF Application
Tutorial # 6 How To Redraw The Whole Control on Resize.
Music By Yours Truly Jay Stilla: Album Jason Society
Press Play on a Song, Crack Your Fingers And Lets Get To Coding


When custom controls or Windows Forms controls like Panel are resized, only their newly exposed portions are redrawn. However, this behaviour sometimes does not provide the desired results (see fig. 1 below).
This example shows how to ensure redrawing of the whole control after resizing by setting the control's ResizeRedraw property.

Fig. 1. A partially redrawn control after resizing.

Redrawing the whole control on resize

The ResizeRedraw protected property defined in the Control class indicates, whether the control redraws itself when resized. To ensure redrawing of the whole control on resize set this property to true. This will usually be done in the constructor of a derived class.
[C#]
public MyControl()
{
InitializeComponent();
ResizeRedraw = true;
}
Alternatively, if you can not or don't want to create a derived class, set the property using reflection or simply call the Invalidate or Refresh method in the control's Resize event handler.
[C#]
using System.Reflection;

public static void SetResizeRedraw(Control control)
{
typeof(Control).InvokeMember("ResizeRedraw",
BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
null, control, new object[] { true });
}
[C#]
myControl.Resize += new EventHandler(myControl_Resize);

private void myControl_Resize(object sender, EventArgs e)
{
((Control)sender).Invalidate();
}

A sample control

The following is a code of a user control displaying an ellipse that stretches and shrinks when the control's size changes:
[C#]
public partial class MyControl : UserControl
{
public MyControl()
{
InitializeComponent();
ResizeRedraw = true;
}

protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
// draw a blue ellipse into the control area
e.Graphics.FillEllipse(new SolidBrush(Color.Blue), 2, 2,
ClientRectangle.Width - 4, ClientRectangle.Height - 4);
}
}
Whithout the ResizeRedraw statement, the control is redrawn only partially and the result looks like in figure 1 above. When the ResizeRedraw = true statement is included, the control is redrawn properly as shown in the following figure 2.

Fig. 2. A properly redrawn control after resizing.


Google Blogs. TopBots.BlogSpot.Com [Created By iMyriad CEO J Jay Stilla Lee" it is a Informative Social Media Marketing Bots News Blog & That List Free Downloads of Automated Bot Software Apps for Facebook, Twitter, Youtube, Google, Instagram & Social Media Websites Written By Jason "Jay Stilla" Lee Online. His Alias Mister Bots Is Software Creation Specialist whom Develops Marketing Bots and Software Scripts that are Given away at no cost weekly. He Also teaches SEO Secrets and Tools For Advertising" Blogger.Com -TopBots Website Blog Https://TopBots.BlogSpot.Com < Informative Software and internet Technology News Blog.. Web blogging on new 2015 Bots and 2014's Best Software Bots Automated and Scripted Combined.

Jay-Stilla Productions LLC - Limited Liability Corporation LLC

4 comments:

  1. ALL 2015 JAY STILLA WEB LINKS & INFO
    1. http://Period1.bigcartel.com/
    2. http://jaystilla.bigcartel.com/
    3. http://jaystilla.bandpage.com/
    4. http://topbots.blogspot.com/
    5. http://jaystilla.blogspot.com/
    6. http://facebook.com/jaystillabeats
    7. http://facebook.com/jaystillaent
    https://mtv.com/artists/JayStilla
    http://www.myspace.com/Jay-Stilla
    http://www.facebook.com/JayStillaBeats
    http://jaystilla.bandcamp.com/
    http://www.reverbnation.com/JayStilla
    http://www.sound.com/JayStilla
    http://www.purevolume.com/jaystilla
    http://www.fandalism.com/jaystilla
    http://www.youtube.com/jaystillatv
    http://www.soundcloud.com/jasonsociety
    http://www.fanmusic.com/jaystilla
    http://www.bandpage.com/Jaystilla

    ReplyDelete
  2. Work From Home Positions Available Now!

    YES! View 1000s of companies hiring social media marketers now!

    ReplyDelete
  3. Ever wanted to get free Twitter Followers?
    Did you know that you can get these ON AUTO-PILOT AND ABSOLUTELY FREE by registering on Like 4 Like?

    ReplyDelete

Feel Free To Request Any Content You Would Be Interested In Seeing Featured On TopBots.BlogSpot.Com This Blog is For Intellectual People Who Enjoy Learning New Knowledge And Sharing It With Others Open Source, Public Domain Empowering Light Seekers Of Advance knowledge and Tools And Multiple Levels Realms and Domains. If Would Like To Join The Team And Become A Blog Editor and Writer Feel Free To Request Information Below: Comment Whatever You Desire Its A Free Globe Last Time I Checked. Enjoy and Please Help By Subscribing And Re posting.