Here is a quick sample app I made which illustrates the problem I am having
making my own UserControl: how do I get scrollbars to appear if I draw
something bigger than the ClientSize ?
Apparently Autoscroll doesn't do it, and if I change the properties Size or
ClientSize to reflect the size of the image I draw it simply makes the entire
control grow instead of forcing scorllbars.
In Java I would have updated the control's PreferredSize, and it looks like
C# has such a property on UserControl but it is read-only.
I need help! I need scrollbars ..
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
MyWidget widget = new MyWidget();
widget.AutoScroll = true;
widget.BorderStyle = BorderStyle.FixedSingle;
widget.Location = new Point(10, 10);
widget.Size = new Size(280, 280);
this.Controls.Add(widget);
}
}
public class MyWidget : UserControl
{
public MyWidget()
{
}
protected override void OnPaint(PaintEventArgs e)
{
Pen p = new Pen(Brushes.Goldenrod, 6);
e.Graphics.FillRectangle(Brushes.IndianRed, 0, 0, 600, 600);
e.Graphics.DrawRectangle(p, 0, 0, 600, 600);
}
}