473,378 Members | 1,364 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 1462
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Tinus | last post by:
Hello all, I've created a custom control that draws a monthly schedule (using the Draw function in C#). Basically it draws 31 boxes and writes the day number in every box. This works...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
0
by: Pavan | last post by:
My name is Pavan and I am a software engineer working on ASP .Net web development. Currently I am using .Net 2.0 Professional Edition to develop my web pages. I have a problem
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
2
by: ahmed.maryam | last post by:
Hello Everyone, I designed a custom control that is entirely covered by a picture box. I then dragged this custom control onto a windows form application (called main) and I need to handle mouse...
3
by: Tomasz J | last post by:
Hello Developers, I have a control derived from System.Web.UI.WebControls.WebControl. Control has this property: public string Value { set { _value = value; } get { return _value; }
5
by: gerry | last post by:
I am trying to create a custom container control that will only ever contain a specific type of control. At design time, when a control of a different type is added to the container I would like...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.