Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

Trouble with UserControl

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Przemek - 27 Feb 2008 12:24 GMT
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[i] =
TransformPoint(mypointsdataarray[i]);
                   /*
                   Panel panel = new Panel();
                   panel.BackColor = Color.Red;
                   panel.Size = new Size(4, 4);
                   panel.Location = new Point(convertedpoints[i].X -
2, convertedpoints[i].Y - 2);
                   this.Controls.Add(panel);
                   */
                   ChartPoint chartpoint = new ChartPoint();
                   chartpoint.Location = new
Point(convertedpoints[i].X - 10, convertedpoints[i].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
Peter Duniho - 27 Feb 2008 18:29 GMT
> [...]
> I put second UserControl on default Form Application, with buttons.
[quoted text clipped - 4 lines]
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.