 |
| C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

February 5th, 2006, 01:42 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
Windows Control Project
Hello,
About a year ago I was wroking with the TaskVision XPander control and got it rewritten an functioning in C#. Revisited it, and pretty much forget how I built it.
I can't remember how to debug a Windows Control Library project. I created a new project which creates a default UserControl1. The UserControl1 appears in My User Controls toolox tab (custom tab I must of created). I added a windows project to the solution to test the control.
When I change the name of the control from the default UserControl1, it vanishes from the toolbax tab. How can I get my renamed control to reappear iin the Toolbox so I can drop it on the WIndows form test project?
Thanks for any help.
Bob
|
|

February 5th, 2006, 01:53 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
Looks like I got it. I had just changed the name in the GUI. When I changed it in the code module, all was well.
Bob
|
|

February 5th, 2006, 02:31 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
Still can't debug it though. I need to be able to have the user control run at design time when I drop the control on a windows form. Any idea hoe to do that??
Bob
|
|

February 5th, 2006, 02:40 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi Bob,
Maybe this helps?? http://imar.spaanjaars.com/QuickDocId.aspx?QUICKDOC=306
The idea is that you start another instance of the development environment, so you can debug your custom controls...
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

February 5th, 2006, 03:45 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
Hi Imar,
Wonderful. Works well.
The XPanderControl.dll really contains 2 controls: an XPanderListControl and instances of XPanderControl that are dropped onto the XPanderListControl. The individual XPanderControls then collapse and expand.
My XPanderControl code is breaking when I attempt to add the Expand and Collapse images to a Bitmap array:
Code:
private Bitmap[] _images = new Bitmap[4];
The code breaks at:
Code:
private void XpanderControl_Load(object sender, System.EventArgs e) {
// Load images from the .dll.
_images[1] = new Bitmap(this.GetType(), "Collapse.jpg"); //<=== Breaks here when attempt to add first image.
_images[2] = new Bitmap(this.GetType(), "Collapse_h.jpg");
_images[3] = new Bitmap(this.GetType(), "Expand.jpg");
_images[4] = new Bitmap(this.GetType(), "Expand_h.jpg");
this.DockPadding.Top = _captionHeight;
}
I just imported the .jpgs into the XPanderControl project. Any idea if the images need to be treated differently somehow?
Thanks again,
Bob
|
|

February 5th, 2006, 03:46 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
The excption thrown reads:
Key cannot be null.
Parameter name: key
Bob
|
|

February 5th, 2006, 04:01 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
The Bitmap constructor overload the code is using is prototyped as:
public Bitmap(Type type, string resource);
Don't know if that means its looking for a resource file, or if the code can see the .jpgs I just imported into the project.
Kinda' new terrain here for me.
Bob
|
|

February 5th, 2006, 04:34 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
Made some progress by setting the Build Action property of all the .jpgs to "Embedded Resource", now the first three Bitmap objects get created OK but the code breaks here:
Code:
private void XpanderControl_Load(object sender, System.EventArgs e) {
// Load images from the .dll.
_images[1] = new Bitmap(this.GetType(), "Collapse.jpg");
_images[2] = new Bitmap(this.GetType(), "Collapse_h.jpg");
_images[3] = new Bitmap(this.GetType(), "Expand.jpg");
_images[4] = new Bitmap(this.GetType(), "Expand_h.jpg"); //<=== Breaks here when attempt to add last image.
this.DockPadding.Top = _captionHeight;
}
Hmm...feel like I'm alomost there though.
Bob
|
|

February 5th, 2006, 04:50 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
|
|
Of course...C# arrays are 0-based.
This gets it:
1) Set Build Action of images to Embedded Resource.
2) Load a 4 element array with:
Code:
private void XpanderControl_Load(object sender, System.EventArgs e) {
// Load images from the .dll.
_images[0] = new Bitmap(this.GetType(), "Collapse.jpg");
_images[1] = new Bitmap(this.GetType(), "Collapse_h.jpg");
_images[2] = new Bitmap(this.GetType(), "Expand.jpg");
_images[3] = new Bitmap(this.GetType(), "Expand_h.jpg");
this.DockPadding.Top = _captionHeight;
}
Thanks for the invaluable debugging tip Imar, and for letting me think out loud.
Till next time,
Bob
|
|

February 5th, 2006, 05:56 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You're welcome. I was just about to suggest the "embedded resource" option, but it turns out you have already fixed it.
You may also want to take a look at this: http://imar.spaanjaars.com/QuickDocId.aspx?QUICKDOC=168
This article, although written for a Compact Framework application, talks a bit about embedding resources and getting them at run-time. In C#, you have to be aware of namespace issues when you store your images at locations other than the root....
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|
 |