cybercrypt13

As usual, I have a need and can't find help, so hoping you guys can point me in the right direction.

I want to design some components to do various things, but can't find a book or any information on how to go about this. I know how to create a component class and work with it, as I've been playing around but as an example:

I have a textbox I've derived and added a label below it so that when I drop a field on the form it comes along with its label instead of having to set these things all seperate. However, they both have a text property, so I worked around this small issue by adding another LabelText property and got that all hooked up nicely. Then I had to override the main Text property to hook it to the main edit control.

Now, I'm stuck, I want to derive another component from this new component but can't get the Text property to expose itself and don't know why. I've purchased $200 of books so far and none even discuss components except on a very basic level, and each of course tell you how easy it is.

Anyway, help with my problem, or a good book is what I'm looking for.


Thanks,

glenn




Re: Windows Forms General How to write components

Friendly Dog

If you could post your code you will probably get more help faster...

Are you creating a custom control I don't see how the Text properties can conflict... again, posting some code will help to clarify






Re: Windows Forms General How to write components

cybercrypt13

Well, I'd love to post some code but it really is quite simple to reproduce.

I created a component class, added a text box and a label to it so that if you add it to a form, the text box comes with a label.

However, now you have 1 component on the form, not two, so to get to the label text property you have to add another property to the new component to allow you to set the property. No problem here. But now go use your new component and you'll see that you also lost the original Text property of the text box. So now you go override the text property and your good to go. Component works perfectly and the world is great.

However, now is where the real problem comes in. I now want to create another component and derive it from this new edit control that I created. But the new control has no Text property and no apparent way to get one. In fact, by deriving the control from the other, I've lost the ability to get at any aspect of the component because its all readonly in the new control.

I then remove that and try to just create a component normally and drop my new textbox and label control onto it and again, I have no Text property and even trying to over ride doesn't make it show up.

Can anyone suggest a good component book I can purchase

Thanks,

glenn






Re: Windows Forms General How to write components

cybercrypt13

Let me clarify something on the derived comments above. When I derive from my earlier control, I do see all the properties I want, however, everything is read only and I can't set or use anything. Can anyone explain to me why everything is readonly when You derive a control directly from another control

Thanks,

glenn






Re: Windows Forms General How to write components

cybercrypt13

I'm sorry but this is just getting very confusing. I have been playing around and noticed that I can tell this thing to create a new component class, drop a plain old label onto the thing and compile and when I try to use it on a form, I have no Text property on the component. I seem to loose this property on all my components I'm creating... What gives

This was a totally new object, totally new component with absolutely no code in it what so ever. Obviously something is wrong here with Visual Studio

glenn






Re: Windows Forms General How to write components

Zaben

Add property to get and set the TextBox.Text

public string BoxText
{
get

{
return this
.textBox1.Text;
}
set

{
this.textBox1.Text = value
;
}
}

the BoxText property will appear in the Misc section if your properties sorted by Category and if I wanted to appear in a desired category you will add this statement above the property

[Category("Appearance")]
public string
BoxText
...
...






Re: Windows Forms General How to write components

cybercrypt13

Ok, again, you've told me how to create a new property which I already know how to do. What I'm asking is why is the Text property disappearing in my new component I've lost .Text and .TextAlign and who knows what else.

All I've done is create a component, dropped a label on the form and compiled it. When I then go drop my new component which is nothing but a new component with a label on it, I have no way to set the properties of the Text and TextAlign from the original label component.

Very confused...

glenn






Re: Windows Forms General How to write components

Zaben

First i am not trying to tell you how to make a property i am trying to tell you how to make property that appears on the properties toolbar that can control the text property of the textbox ...

  1. Not all of us understand engilish very well and to me i can't understand exactly your problem
    1. once you add any control to your custom control all of the properties of the added control will not appers on the Properties Toolbar.
    2. And Remember that the control that add to this custom control is private so you cannot access them even through the code, so you must change the Modifiers Property for the control added from private to public
  2. In the example i had previously wrote i amde a property to control the Text of the TextBox and making it visible in the design time

If you can write to us your code to see where is the problem.

There is good book for custom control and it's name

Pro .NET 2.0 Windows Forms and Custom Controls in C# --- From APress






Re: Windows Forms General How to write components

cybercrypt13

What language do you speak

Yo hablo espanol y ingles... si espanol es mas bueno entonces...

Anyway, There is no code. Follow these steps:

1) Create new component File, New, Control Library

2) Add a text box to the control form

3) Compile and save

4) Add control to your toolbox

5) Add new control to a windows form

6) Try to set the text property. Its gone. not there.

So my question is, why What happened to the Text Property

If you speak spanish I'll retype it in spanish but its the only other language I could try to communicate in. My spanish is not perfect by any means but I understand it well enough to communicate with you...

Thanks,

glenn






Re: Windows Forms General How to write components

Zaben

If you mean the text property for the textbox ... Yes it will not appear when The control Library added to the form... because it is a property for the Textbox and not a property for the control Library - The properties that appears are only for the control Library you have created and you even cannot move or change its position

And if the Textbox modifier is private you cannot access its property through the code but if it is public to access it you will write

mycontrol.textbox1.text = "Hello";

or write a property for myControl as above that can access the property desired

I am not sure if there walkthrough or code add to make it possibe that all i knew

I don't speak spanish ... :(
Arabic and quiet good in English

Thanks






Re: Windows Forms General How to write components

cybercrypt13

Thanks, I think I understand although I have to admit it does seem strange that VS would allow us to create our own components based on existing ones, but then not share out any of its methods that make it function.

I'll keep playing with it and try to figure out what I"m missing.

thanks again,

glenn