2021年3月22日星期一

After compiling custom container, the position and size of the child controls in the container are changed in C#

I have write a custom container, the code:

 [Designer(typeof(ParentControlDesigner))]  public partial class JzContainer : UserControl  {        public JzContainer()      {          this.SetStyle(ControlStyles.ContainerControl, true);          this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);          this.SetStyle(ControlStyles.DoubleBuffer, true);          this.SetStyle(ControlStyles.ResizeRedraw, true);          this.SetStyle(ControlStyles.Selectable, true);          this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);          this.SetStyle(ControlStyles.UserPaint, true);          this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;      }        public Color _borderColor = Color.Gray;      public Color BorderColor      {          get { return _borderColor; }          set          {              _borderColor = value;              Refresh();          }      }                protected override void OnPaint(PaintEventArgs e)      {          base.OnPaint(e);          int radius = 10;          Graphics g = e.Graphics;          g.SmoothingMode = SmoothingMode.AntiAlias;          g.InterpolationMode = InterpolationMode.HighQualityBicubic;          g.CompositingQuality = CompositingQuality.HighQuality;          Rectangle rectBack = this.ClientRectangle;          using (var sb = new SolidBrush(BackColor))          {              g.FillRectangle(sb, rectBack);          }         ControlPaint.DrawBorder(g, rectBack, BorderColor, ButtonBorderStyle.Solid);               }  }  

i override the OnPaint() fuction,and redraw the user control. In this class i i drag a button in this custom container, the button's location and size are OK, but when compiling this program the both the button's size and button's position have changed.

https://stackoverflow.com/questions/66757553/after-compiling-custom-container-the-position-and-size-of-the-child-controls-in March 23, 2021 at 01:06PM

没有评论:

发表评论