I'm having a problem using custom components at runtime. I have this custom FlowLayoutPanel component:
public partial class UserControl1 : System.Windows.Forms.FlowLayoutPanel
{
[Browsable(false)]
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x20;
return cp;
}
}
protected override void OnPaintBackground(PaintEventArgs e){}
public UserControl1(){}
}
it has nothing complicated. All it does is making the background transparent.
I added this component to my Toolbox using it's dll and it works perfectly fine when I drag and drop it to my Form. The problem is, I can't add it programmatically at runtime.
When I run the code below it should draw the picture on top of m开发者_如何学JAVAy custom FlowLayoutControl. But unfortunately it does nothing.
The custom component is under the WindowsFormsControlLibrary1 namespace.
namespace MyFilm_v2._0
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
UserControl1 test = new UserControl1();
test.BackColor = Color.Transparent;
test.Location = new Point(0, 110);
test.Width = 660;
test.Height = 478;
PictureBox b = new PictureBox();
b.Location = new Point(100, 100);
b.Width = 320;
b.Height = 475;
b.Image = Properties.Resources.movie;
this.Controls.Add(b);
//this.customScrollbar1.Minimum = 0;
//this.customScrollbar1.Maximum = test.DisplayRectangle.Height;
//this.customScrollbar1.LargeChange = customScrollbar1.Maximum / customScrollbar1.Height + test.Height;
//this.customScrollbar1.SmallChange = 15;//when click the arrows
//this.customScrollbar1.Value = Math.Abs(test.AutoScrollPosition.Y);
}
....
You adding picturebox to your test controls, but you not adding test to forms controls
public Form1()
{
InitializeComponent();
UserControl1 test = new UserControl1();
test.BackColor = Color.Transparent;
test.Location = new Point(0, 110);
test.Width = 660;
test.Height = 478;
PictureBox b = new PictureBox();
b.Location = new Point(100, 100);
b.Width = 320;
b.Height = 475;
b.Image = Properties.Resources.movie;
test.Controls.Add(b);
this.Controls.Add(test);//<- here
}
精彩评论