469,626 Members | 1,241 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

Custom Control Problem

Hi all,

I have created a custom control which displays Image using Graphics..

I am using this control in a different windows application.
I am dynamically creating the control and putting that in the form.

In the Control's InitializeComponent() function following statement is
present

class MyControl
{
InitializeComponent()
{
this.Size = new System.Drawing.Size(150, 150);
}

DisplayImage(ImageFileName)
{
Graphics.DrawImage(...);
}
}

While creating the control dynamically I am using following statements

class Client
{
AddControl()
{
MyControl control = new MyControl();
control.Left = 10;
control.Top = 10;
control.Width = 100;
control.Height = 100;
}
}

and when I call control.DisplayImage(ImageFileName);
the function MyControl.DisplayImage() shows image correctly.
But If in AddControl() I change the control.Width > 150 or control.Height >
150.
The control does not display the image after 150.
But the trace statements in MyControl.DisplayImage() shows all the values
correctly.

Can anybody help me how to add controls dynamically, without this problem.?

Thank you in Advance.
-Anand
Nov 16 '05 #1
2 1347
Anand,

The problem has nothing to do with the fact that you are adding the
controls dynamically. Basically, the problem arises from the fact that you
are painting the image once on the screen, and when the screen is
invalidated, you no longer know what to paint.

What you want to do is store the image passed to you in the DisplayImage
method (store the Image instance). Once you have that, call Invalidate on
yourself to cause a repaint.

Finally, override the OnPaint method of your control so that you draw
the image to the Graphics object passed to you there.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"anand" <no****@micro.com> wrote in message
news:cb**********@news.mch.sbs.de...
Hi all,

I have created a custom control which displays Image using Graphics..

I am using this control in a different windows application.
I am dynamically creating the control and putting that in the form.

In the Control's InitializeComponent() function following statement is
present

class MyControl
{
InitializeComponent()
{
this.Size = new System.Drawing.Size(150, 150);
}

DisplayImage(ImageFileName)
{
Graphics.DrawImage(...);
}
}

While creating the control dynamically I am using following statements

class Client
{
AddControl()
{
MyControl control = new MyControl();
control.Left = 10;
control.Top = 10;
control.Width = 100;
control.Height = 100;
}
}

and when I call control.DisplayImage(ImageFileName);
the function MyControl.DisplayImage() shows image correctly.
But If in AddControl() I change the control.Width > 150 or control.Height

150.
The control does not display the image after 150.
But the trace statements in MyControl.DisplayImage() shows all the values
correctly.

Can anybody help me how to add controls dynamically, without this problem.?
Thank you in Advance.
-Anand

Nov 16 '05 #2
anand,

The destRect in the drawImage function is the tricky part.When the custom
control is resized, the destRect value must be updated, for the image to
automatically streched.

If your problem still exists, can you paste the code of DrawImage?

Shak.
"anand" <no****@micro.com> wrote in message
news:cb**********@news.mch.sbs.de...
Hi all,

I have created a custom control which displays Image using Graphics..

I am using this control in a different windows application.
I am dynamically creating the control and putting that in the form.

In the Control's InitializeComponent() function following statement is
present

class MyControl
{
InitializeComponent()
{
this.Size = new System.Drawing.Size(150, 150);
}

DisplayImage(ImageFileName)
{
Graphics.DrawImage(...);
}
}

While creating the control dynamically I am using following statements

class Client
{
AddControl()
{
MyControl control = new MyControl();
control.Left = 10;
control.Top = 10;
control.Width = 100;
control.Height = 100;
}
}

and when I call control.DisplayImage(ImageFileName);
the function MyControl.DisplayImage() shows image correctly.
But If in AddControl() I change the control.Width > 150 or control.Height

150.
The control does not display the image after 150.
But the trace statements in MyControl.DisplayImage() shows all the values
correctly.

Can anybody help me how to add controls dynamically, without this problem.?
Thank you in Advance.
-Anand

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Tinus | last post: by
2 posts views Thread by ahmed.maryam | last post: by
3 posts views Thread by Tomasz J | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.