Trouble with UserControl

P

Przemek

Hello,

I write a little UserControl
-------

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace UserControlPoint
{
public class ChartPoint : System.Windows.Forms.UserControl
{
private ContainerControl _containerControl = null;

public ContainerControl ContainerControl
{
get { return _containerControl; }
set { _containerControl = value; }
}

public ChartPoint()
{
InitializeComponent();
}

private void InitializeComponent()
{
this.SuspendLayout();
//
// ChartPoint
//
this.BackColor = System.Drawing.Color.Transparent;
this.Name = "ChartPoint";
this.Size = new System.Drawing.Size(20, 20);
//this.Paint += new
System.Windows.Forms.PaintEventHandler(this.ChartPoint_Paint);
//this.MouseLeave += new
System.EventHandler(this.ChartPoint_MouseLeave);
//this.MouseMove += new
System.Windows.Forms.MouseEventHandler(this.ChartPoint_MouseMove);

this.ResumeLayout(false);

}
}
}
-------

and when I want to use it in second UserControl

-------
....
for (int i = 0; i < mypointsdataarray.Length; i++)
{
convertedpoints =
TransformPoint(mypointsdataarray);
/*
Panel panel = new Panel();
panel.BackColor = Color.Red;
panel.Size = new Size(4, 4);
panel.Location = new Point(convertedpoints.X -
2, convertedpoints.Y - 2);
this.Controls.Add(panel);
*/
ChartPoint chartpoint = new ChartPoint();
chartpoint.Location = new
Point(convertedpoints.X - 10, convertedpoints.Y - 10);
this.Controls.Add(chartpoint);
}
....
-------

I put second UserControl on default Form Application, with buttons.
And when I click one of this buttons actions described in loop above
is running. BUT ... this code give me a "Error creating window
handle." message, so I try to do this without my ChartPoint
UserControl and I test default Panel Component and every thing works
fine. So What is wrong with my ChartPoint UserControl, because I don't
know what I'm doing wrong.

Best Regards
Przemek
 
P

Peter Duniho

[...]
I put second UserControl on default Form Application, with buttons.
And when I click one of this buttons actions described in loop above
is running. BUT ... this code give me a "Error creating window
handle." message, so I try to do this without my ChartPoint
UserControl and I test default Panel Component and every thing works
fine. So What is wrong with my ChartPoint UserControl, because I don't
know what I'm doing wrong.

I don't either. However, if you are going to get a good answer, you are
going to need to post a more useful code sample.

Your sample should be concise-but-complete, and of course it should
reliably reproduce the problem.

Concise means it doesn't include anything that doesn't need to be there.
So, all that stuff you've posted that's commented out, that should've been
left out. If the loop dealing with the points isn't required, that
should've been left out (and if it is required, then I'd guess your
problem has something to do with that).

Also, telling use the error message isn't very useful unless you tell us
exactly where you get the error message and how you cause the code to
generate the error (you mention "click one of this buttons actions", but
there aren't any buttons in your code sample!).

Complete means you provide a code sample that can be compiled and run
without _any_ additional effort on someone's part. We shouldn't have to
add code in order to see what your code does. The need for the sample to
be complete is part of the reason why the sample needs to be
concise...otherwise, someone would have to waste too much time looking at
code that doesn't matter, just to figure out which code does matter.

If you can provide a code sample like that, then maybe someone will be
able to suggest what's wrong with your code.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top