UserControl中的AutoScroll问题。。在线急求答案
林夕合鸟 2014-10-17 02:31:01 Form1中代码:
public Form1()
{
InitializeComponent();
UserControl1 userc = new UserControl1();
userc.Height = 100;
userc.Width = 200;
userc.Left = 10;
userc.Top = 10;
userc.BackColor = Color.Aqua;
userc.Parent = this;
}
UserControl中构造函数的代码:
ScrollControl sc = new ScrollControl();
sc.Parent = this;
sc.Left = 0;
sc.Top = 0;
AutoScroll = true;
ScrollControl中只有一个事件,即Paint,代码如下:
Rectangle tb;
tb = new Rectangle(180-AutoScrollPosition.X, 10, 50, 25);
if (180 + 50 > Right)
Width = 180 + 50 + 20;
Graphics g = CreateGraphics();
g.DrawRectangle(new Pen(Brushes.Purple), tb);