|
Hi,
I've built a custom control derived from System.Windows.Forms.Label. This custom control is a part of MyControls project which is a part of a solution (this solution contains a simple windows forms application and the MyControls project).
WHat is the best way to use this custom control in the abovementioned windows forms application? THis is what I did: opened the toolbox, added the custom control into the toolbox, and then dragged it into the windows form. But this approach seems pointlessly complicated to me, and it doesn't work as I expected (my custom control disappeared from the designer after a while, but when the application is compiled it is there). Another thing is that even when the MyControls is recompiled, the changes will not show in my windows forms application
What am I doing wrong? Am I doing something stupid? Is there any other way?
Thanks for any clues/suggestions.
rado
Radoslav Bielik
http://www.neomyz.com/poll [^] - Get your own web poll
|
|
|
|
|
First, add a Project reference to your Windows Forms project by right-clicking on it, click Add Reference, then click the projects tab. Select the project containing MyControl. This makes sure that no matter which build (debug, release, or any number of custom configurations) you do, both assemblies are the right builds.
Next, forget the toolbox - type in the control into the source manually. If you use the same style/format as the other controls in the form (a field at the top, instantiated in the first secton of InitializeComponent , and the properties set under a specially formatted source comment like the others), you'll see it in the designer next time. If you use the toolbox, it might interpret the assembly location as being different from the one you added in the step above (might, might not).
The toolbox is really for third-party libraries that have one or many class libraries and want to integrated with VS.NET for developer ease and better product visibility/returns. For internal development - as you've seen - it's usually just a pain.
There's really no easier way to do it. Being able to drag a control from the solution or class views to a form would be great - like UserControls in ASP.NET - but I have seen that yet in the features list for VS.NET.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
|
I was about to ask the same question as this thread..
So are you saying that if you have access to the source and dll of a user control project, add it manually in the 'windows generated' section of code, and if you only have access to the user control as a dll (no source) add it via the toolbox?
If you add it via the toolbox it stays there for all projects, doesn't it?
Cheers,
Barry
|
|
|
|
|
Source doesn't matter. You're just adding a control reference to your source files manually to begin with, where VS.NET's designer would do it for you if you dragged it from the toolbox. Nothing more than that. Doesn't matter if the Type is defined in the current project's assembly, another project's assembly, or a third-party (or BCL) assembly. Just think of it as programming without VS.NET - frankly, I find the designers to be annoying (except, in some cases, for initial design of complex forms).
Barry Lapthorn wrote:
If you add it via the toolbox it stays there for all projects, doesn't it?
Yes, but just to be thorough, you can actually write a designer for a custom control that creates a ToolBoxItem only for the project in which the control is used. This has no relevance to this topic, but just thought I'd throw that in there.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath Stewart wrote:
You're just adding a control reference to your source files manually to begin with, where VS.NET's designer would do it for you if you dragged it from the toolbox
So once you've added it, does it render it on the control for you to then use the gui tools to size it and position it? I really should get on a c# course I'll maybe have a try later.
Cheers,
Barry
|
|
|
|
|
Yes, so long as you added it like the other controls added via the designer (instantiated in InitializeComponents and added to its parent's Controls collection). Then you're free to design it like the others. Anything done outside that method won't show in the designer.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath Stewart wrote:
Yes, so long as you added it like the other controls added via the designer (instantiated in InitializeComponents and added to its parent's Controls collection).
Ah, I see (I just knocked up a project). That means I can remove some of the controls I added to the toolbox. That's a shame, you'd hope that MS would have allowed you to add controls to the toolbox on a per project basis. Oh well. Thanks....
Cheers,
Barry
|
|
|
|
|
You can, if you want to write your own designer and get the IToolboxService service provider (or you can get it from the Control.Site property at design-time) and call IToolboxService.AddLinkedToolboxItem , which means you also have to implement IToolboxItem that instantiates your control. If you do that, the control is only added to the toolbox for the project in which its loaded.
There's also one more trick that's possible, but sometimes hard to reproduce. If you open a control in the designer (after it's compiled) it is automatically added to the toolbox for the project in which the control is located. I believe this is also supposed to work for any project in your solution - but like I said - it's hard to reproduce.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hello.
I'm using the ToDouble function from the System.Convert namespace to convert from a String to Double.
I have problems using it. With a String that has the value of '56.3' I'm getting as a result a double like this 56.2999999993.
I have tried to use the ToDouble Method of the String object and I get the same result.
What I'm doing wrong ??
|
|
|
|
|
What happens when you try Double.Parse("56.3") ?
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
|
Well, you can always make it work with another call
Math.Round(double.Parse("3.2"), 3);
The graveyards are filled with indispensible men.
|
|
|
|
|
A double is a double precision floating point number. Floating point numbers can't always represent a number perfectly. If you need better accuracy, there is the Decimal data type (But it is VERY slow compared to double)
Beginning of this article talks a bit about it
http://tom.cs.byu.edu/~557/text/ch14.pdf
|
|
|
|
|
Thanks
|
|
|
|
|
I can't believe this sh*t!
I was workin on a C# form using VS.NET 2003. When I added a new button using the Form Designer I got this error message :-
Code generation for property 'Text' failed. Error was: 'There was an error loading app.config. Since the document being loaded uses Dynamic Properties, the config file must be valid. Correct the following error in app.config:<br />
<br />
The item 'app.config' does not exist in the project directory. It may have been moved, renamed or deleted.'<br />
VS.NET closed on its own and when I reopened the project I lost all my form control properties and now have a blank form.
Blast it!
Nish
Extending MFC Applications with the .NET Framework [NW] (coming soon...)
Summer Love and Some more Cricket [NW] (My first novel)
Shog's review of SLASMC [NW]
This post was made from Trivandrum city, India on a 0.0001 KB/s net connection
|
|
|
|
|
Hi Nish,
One time I lost a custom control... I manage to type it in the resource file ( at least it was in xml not like with the old rc files), or in the part that is created... quite sh*tty...
But your crash... it's quite better than mine
|
|
|
|
|
Yeah, this happened to me too with VS.NET 2002 as well as VS.NET 2003. I am not aware of a fix for that.
RSS feed
|
|
|
|
|
Ctrl+S is your friend. Get acquainted with her.
Regards,
Alvaro
He who laughs last, thinks slowest.
|
|
|
|
|
|
I'm sorry that happened.
I make it a point to back up my forms before using design mode - partly because in previous releases of SharpDevelop that kind of trouble was commonplace (unlike w/ the v0.98 release). I've been glad I did it a number of times. It is a pain though.
Another hint is to do all your forms designer work w/o saving, then switch to source mode and ensure that everything works before saving.
Anyway, good luck and I hope you manage to re-construct your work.
|
|
|
|
|
Could You recommend me some Internet sites containing free download electronic books devoted to :
- .NET technology (C#, ASP, ADO, Wireless/Mobile, …) , MSSQL&XML
- application mathematics – numeral methods, artificial intelligence, …
- GPS & navigation systems
Thank You !
|
|
|
|
|
safari.oreilly.com is a online book program, you can browse books for free, but must pay a monthly fee for your "bookshelf". They have alot on .NET, but not much on mathematics, and nothing on GPS. Is there anything specific you need to know about GPS, I've done my share of research on the topic...
|
|
|
|
|
Hello, I was just wondering if any of you know how to make the buttons on a toolbar have pictures in them instead of text? I'm trying to make a paint like program and I thought I would make a toolbar in which the buttons have a picture of the drawing tool you can use ie. pencil.
|
|
|
|
|
haha nevermind, found this image list property thingo
|
|
|
|