| Код | using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Windows.Forms;
namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); TRectangle a = new TRectangle(10, 10, 100, 100); this.Controls.Add(a); }
private void Form1_Scroll(object sender, ScrollEventArgs e) { foreach(UserControl elem in this.Controls){ elem.Invalidate(); } } } public class TRectangle : UserControl { private GraphicsPath path = new GraphicsPath(); private RichTextBox text = new RichTextBox(); public TRectangle(int x, int y, int width, int heigth) { this.Location = new Point(x, y); this.Size = new Size(width,heigth); path.AddRectangle(new Rectangle(x, y, width, heigth));
/*text.Location = new Point(x + 2, y + 2); text.Size = new Size(width - 10,heigth - 100); this.Controls.Add(text);*/
this.Region = new Region(path); }
protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; g.DrawRectangle(new Pen(Color.Red, 1), new Rectangle(this.Location.X, this.Location.Y, this.Width-1, this.Height-1)); base.OnPaint(e); } } }
|
почему у меня не прорисовывается весь прямоугольник? только верхняя и правая граница
| Код | using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Windows.Forms;
namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); TRectangle a = new TRectangle(10, 10, 100, 600); this.Controls.Add(a); }
private void Form1_Scroll(object sender, ScrollEventArgs e) { foreach(UserControl elem in this.Controls){ elem.Invalidate(); } } } public class TRectangle : UserControl { private GraphicsPath path = new GraphicsPath(); private RichTextBox text = new RichTextBox(); public TRectangle(int x, int y, int width, int heigth) { this.Location = new Point(x, y); this.Size = new Size(width,heigth); path.AddRectangle(new Rectangle(x, y, width, heigth));
/*text.Location = new Point(x + 2, y + 2); text.Size = new Size(width - 10,heigth - 100); this.Controls.Add(text);*/
this.Region = new Region(path); }
protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; g.FillRectangle(Brushes.AliceBlue, new Rectangle(this.Location.X, this.Location.Y, this.Width - 1, this.Height - 1)); base.OnPaint(e); } } }
|
в данном варианте происходит мерцание( |