473,513 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UserControl not putting scrollbars if AutoScroll is true

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);
}
}
Nov 1 '06 #1
0 3700

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1506
by: Alexander Brown | last post by:
I have a custom control inside a frame. The frame has autoscroll set to true. The control has its dock set to Fill, and anchose set to top and left. If i scroll around the control using the...
5
4933
by: MrNobody | last post by:
I'm doing some custom drawing to a Panel object overriding the onPaint, and the stuff I draw usually goes beyond the ClipRectangle of the panel's current size- so I set autoscroll to true yet it...
17
2070
by: Dino M. Buljubasic | last post by:
I have a treeview and a checked list view controls one beside another. I want to make them work so that when I scroll down or up one of them the other does the same. Any help will be...
0
927
by: Yaron | last post by:
In a UserControl, I know that the control will automatically create scrollbars and a scrolling ability when needed. However, how exactly does it decide how big the control's paintable "region" is?...
5
11081
by: Christopher Kurtis Koeber | last post by:
Dear All, This may sound like an elementary question but how do you implement scrollbars for the Picturebox control. Do I have to create my own code to do this or is there some property that I can...
5
3466
by: james | last post by:
How can I control the placement of scrollbars in mdi child windows? I need to place a control at the top of my child form and this control needs to always be visible. The rest of the page needs...
3
2005
by: Martin | last post by:
Hi ! I've developed a small UserControl with five textbox and label. However, when I want to display the UserControl in a form, controls appear slowly one after one. I've activated double...
4
2457
by: Martin | last post by:
Hi everyone ! For those who haven't read my previous post, I have a problem with a UserControl. When I try to display it on a form, controls seem to appear one after one. In the following...
1
3547
by: =?Utf-8?B?TmV3YnJv?= | last post by:
I have this program running on PDA compact framework in which it will receive paint message from server's networkstream and updates the client's screen by drawing on this custom 'Draw' userControl....
0
7264
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7543
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7106
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5689
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3226
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1601
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
805
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
459
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.