loyal Posted October 4, 2003 Posted October 4, 2003 hi All I do painting my Tab Control with Linear Brush it works well but when the application is minimize then Maximize the exception Handle with this message An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll Additional information: Rectangle '{X=0,Y=0,Width=0,Height=0}' cannot have a width or height equal to zero. then I know there's a method called Invalidate() but where should I use it and should I use a Refresh() Method or make no sense :D anyone help please Quote Gary Says: To be a good programmer, you must be good at debugging
aewarnick Posted October 4, 2003 Posted October 4, 2003 Are you changing the size of the Brush on Form_Resized? If you are, just prevent the Brush from being created with a 0 Rectangle. All Invalidate does is tell the Window or control to redraw itself. I myself have never used Refresh, but I'm sure it has it's purpose. Quote C#
aewarnick Posted October 4, 2003 Posted October 4, 2003 I just saw your title more closely. Take a look at this Form class it probably does what you want and more. Ignore all the junk. At the bottom you will probably see the answer to your problem. /// <summary> /// Inherits from Form and has additional features including the ability to center an image on the form at all times with transparency if you want. You can also paint the background with any brush you want. /// </summary> public class aForm : Form { /*public class FormBrush { public FormBrush(){} FormBrush FB=new FormBrush(); public FormBrush Brush { get{return FB;} set{FB=value;} } } /// <summary> /// Colors the BackGround of the Form. /// </summary> [ TypeConverter(typeof(ExpandableObjectConverter)) ] public class brush { Color c1= a.Colors.aControl; Color c2= a.Colors.aControl; Rectangle fiStartEndArea=new Rectangle(0,0,100,100); int rot=20; //----------------------------- public brush(Color color1, Color color2, Rectangle fillStartEndArea, int rotation) { Color1= color1; Color2= color2; FillStartEndArea= fillStartEndArea; Rotation= rotation; } public brush(Color color1) { Color1= color1; Color2= color1; } public brush() { } //----------------------------- public Color Color1 { get{return c1;} set{c1=value;} } //----------------------------- public Color Color2 { get{return c2;} set{c2=value;} } //----------------------------- public Rectangle FillStartEndArea { get{return fiStartEndArea;} set{fiStartEndArea=value;} } //----------------------------- public int Rotation { get{return rot;} set{rot=value;} } } //end class FormBrush //----------------------------*/ Brush backgrdBrush=null; Image backgrdImage=null; int backgrdImageTransp=100; bool controlsTransp=true; bool controlsTranspInclBut=false; /// <summary> /// If some controls are not being colored right you may be able to figure out why. /// </summary> public string Errors="Check to see if the FormBorderStyle is set to 3D.\n\n"; /// <summary> /// A brush to paint the background any color you want. Will always be behind the image. /// </summary> public Brush BackgrdBrush { get{return backgrdBrush;} set{backgrdBrush=value; this.Invalidate();} } /// <summary> /// Places an image in the center of the form keeping its proportions. /// </summary> public Image BackgrdIm { get{return backgrdImage;} set{backgrdImage=value; this.Invalidate();} } /// <summary> /// Sets the transparency percent to the backgrdImage. 0 is clear. If the image is not transparent at all the painting will draw faster: 100. /// </summary> public int BackgrdImTransp { get{return backgrdImageTransp;} set{backgrdImageTransp=value; this.Invalidate();} } /// <summary> /// Set to false if you want the controls on the form to take on the BackColor of the form. /// </summary> public bool ControlsTransp { get{return this.controlsTransp;} set{this.controlsTransp=value; this.Invalidate();} } /// <summary> /// You want your buttons to be transparent too. /// </summary> public bool ControlsTranspInclBut { get{return this.controlsTranspInclBut;} set{this.controlsTranspInclBut=value; this.Invalidate();} } //------------------------ public aForm() { this.SetStyle(ControlStyles.DoubleBuffer, true); this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.UserPaint, true); this.BackColor= a.Colors.aControl; } //------------------------ protected override void OnPaint(PaintEventArgs e) { e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; base.OnPaint(e); if( (controlsTransp || controlsTranspInclBut) && (this.backgrdBrush != null || this.backgrdImage != null) ) { if(controlsTranspInclBut) { foreach(Control c in this.Controls) { try { if(c is Label || c is GroupBox || c is Panel || c is LinkLabel || c is Button || c is CheckBox || c is RadioButton) ((Control)c).BackColor= Color.FromArgb(0,0,0,0); /*else if(c is TabControl) { foreach(TabPage tp in ((TabControl)c).TabPages) tp.BackColor= Color.FromArgb(0,0,0,0); }*/ } catch(Exception er) { this.Errors+= er+"\n\n"+c+"\n\n"; } } } else { ArrayList buttonsList= new ArrayList(2); ArrayList buttonsColorList= new ArrayList(2); foreach(Control c in this.Controls) { try { if(c is Label || c is GroupBox || c is Panel || c is LinkLabel || c is CheckBox || c is RadioButton) ((Control)c).BackColor= Color.FromArgb(0,0,0,0); else if(c is TabControl) { foreach(TabPage tp in ((TabControl)c).TabPages) { foreach(Control tc in tp.Controls) { if(tc is Button) { buttonsList.Add(tc); buttonsColorList.Add(tc.BackColor); } } tp.BackColor= Color.FromArgb(0,0,0,0); for(int i=0; i<buttonsList.Count; i++) { ((Button)buttonsList[i]).BackColor= ((Color)buttonsColorList[i]); } } } } catch(Exception er) { this.Errors+= er+"\n\n"+c+"\n\n"; } } } } try { if(this.backgrdBrush != null) { //LinearGradientBrush LGB=new LinearGradientBrush(this.backgrdBrush.FillStartEndArea, this.backgrdBrush.Color1, this.backgrdBrush.Color2, this.backgrdBrush.Rotation); e.Graphics.FillRectangle(this.backgrdBrush, this.ClientRectangle); } if(this.backgrdImage != null) { Size ImSize= a.graphics.ProportionalSize(backgrdImage.Size, new Size(this.ClientRectangle.Width, this.ClientRectangle.Height)); Rectangle centerR= a.graphics.CenterRect(this.ClientRectangle, ImSize); if(this.backgrdImageTransp != 100) { ImageAttributes IA = a.graphics.TrasparentImage(backgrdImageTransp); e.Graphics.DrawImage(backgrdImage, centerR, 0, 0, backgrdImage.Size.Width, backgrdImage.Size.Height, GraphicsUnit.Pixel, IA); } else e.Graphics.DrawImage(backgrdImage, centerR, 0, 0, backgrdImage.Size.Width, backgrdImage.Size.Height, GraphicsUnit.Pixel); } } catch(Exception er) { this.Errors += er+"\n\n"; } } //------------------- protected override void OnResize(EventArgs e) { base.OnResize(e); if(this.backgrdBrush != null || this.backgrdImage != null) this.Invalidate(); } } Quote C#
loyal Posted October 5, 2003 Author Posted October 5, 2003 hi in fact I didn't get it well as you read my Q this is the code I've written to paint the Tab control Private Sub tabTables_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Dim g As Graphics = e.Graphics Dim lBrush As LinearGradientBrush = New _ LinearGradientBrush(Me.ClientRectangle, Color.MediumBlue, _ Color.RoyalBlue, LinearGradientMode.BackwardDiagonal) g.FillRectangle(lBrush, Me.ClientRectangle) End Sub and I added a handler in Form Load Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AddHandler tb.Paint, AddressOf tabTables_Paint End Sub now What should I do to solve repaint when the Form Is Maximize ? I hope it clear Quote Gary Says: To be a good programmer, you must be good at debugging
aewarnick Posted October 5, 2003 Posted October 5, 2003 It's in my code above. In Resize call Invalidate(); Quote C#
loyal Posted October 5, 2003 Author Posted October 5, 2003 I am quite sorry , i do both but the exception still exist Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize Me.Invalidate() Me.tb.Invalidate() End Sub Protected Overrides Sub OnResize(ByVal e As System.EventArgs) Me.Invalidate() Me.tb.Invalidate() End Sub neither help Quote Gary Says: To be a good programmer, you must be good at debugging
aewarnick Posted October 5, 2003 Posted October 5, 2003 When you override, you must call the base class. You are also overriding the Form's OnResize not the TabControls. You must make a custom TabControl inheriting form TabControl. public class TB : TabControl { } Remember to check for an empty Rectangle. One with (anything, anything, 0, 0). Quote C#
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.