Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
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
 
Old February 5th, 2006, 01:42 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default 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

 
Old February 5th, 2006, 01:53 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

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

 
Old February 5th, 2006, 02:31 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

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

 
Old February 5th, 2006, 02:40 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old February 5th, 2006, 03:45 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

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





 
Old February 5th, 2006, 03:46 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

The excption thrown reads:

Key cannot be null.
Parameter name: key

Bob

 
Old February 5th, 2006, 04:01 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

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

 
Old February 5th, 2006, 04:34 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

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

 
Old February 5th, 2006, 04:50 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

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


 
Old February 5th, 2006, 05:56 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Deploying Windows Project to 360 Emmulator BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 3 August 2nd, 2007 01:03 PM
Need help in starting Windows Project g_vamsi_krish Visual Studio 2005 0 January 3rd, 2007 01:16 PM
debugging windows service project sasidhar79 Pro VB.NET 2002/2003 0 August 17th, 2005 04:34 PM
Web Control in Windows Project madhanagopal Pro VB.NET 2002/2003 1 September 26th, 2004 07:19 PM
Windows 98 OCX control issues vs Windows XP benoyraj VB How-To 0 May 5th, 2004 08:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.