Link to home
Start Free TrialLog in
Avatar of cyberdevil67
cyberdevil67

asked on

Extending Textbox in c#

Ok guys this is my first question posted to EE..

Anyway I am trying to extend the textbox, which I have done sort of. but what I want to do is do custom borders. So everytime that I have tried to date I do get my custom border, but I also get the default  border as well.

I have even tried in the onPaint method to not call the base.OnPaint.

Anyone have any examples, references that will help me in my quest that would be good.
Avatar of TDSnet
TDSnet

How much of the existing TextBox functionality do you need..?  Might be easier to just create a new control from scratch rather than one that inherits from the TextBox.

Cheers,
Jack
Avatar of cyberdevil67

ASKER

Ok, do you know how to do that? Without reinventing the textinput, and events rewriting and the properties?
You can see in the following article what the problems of repainting a text box are and how this guy changed the behavior to create a transparent background. I think you can use a similar solution to create a custom border:

http://www.codeproject.com/cs/miscctrl/alphablendtextbox.asp
How does that work?

First of all every form control already has a region, secondly it will not stop the parent controls drawing? Seeing as I already have control of the region, I am able to do anything I want to draw to it, but I can't stop the base control from doing what it does in terms of drawing.

Did you look at the link I sent you?
Yes,

I have already seen that code. And that code doesn't tell me any more than I already know or done. But thanks anyway, I have search codeproject and the net extensively, but there are no examples on doing custom drawing of the borderstyle. Thats what I am looking for here.
Well, that code shows you how to make full custom drawing. It uses an image to draw the text box and you can draw whatever you want on an image in C#
Actually you are wrong on that issue...

All it does is use a property to change the background colour and appy transparency, the backgroundstyle is  a different kettle of fish. I am able to do the same thing as I said I have searched codeproject for all the examples I could find, I came across this many times.

I have gone over this code with a fine tooth comb, and have not seen any evdidence that it can override the OnPaint event or allow a differnt form of borderstyle, thats what this question is about.

I can do the same thing this code does already and am not interested in links to code I have seen, I am looking at someone who can explain to me how or what I need to do.
I haven't seen the code itself but here is what the article says:

When the control needs to be painted, it does the following:

1. temporarily sets the UserPaint style to false
2. captures a bitmap of the original TextBox by sending a WM_PRINT message
3. switches back to UserPaint style
4. uses a ColorMap to convert the solid background into a transparent/alpha background
5. figures out where the caret should be and draws it if necessary
6. then copies the new alpha image to the PictureBox, which when drawn will be blended with the background

Point 2 creates an image, point 4 changes the image. So what you need it to replace point 4 with "draw new border" and leave the rest as it is.
i have read it...

And I have I read the code, and looked at the code many times in the last 6 months. Don't always read what you believe..

The code uses two controls to acheive what it does, that is a fudge I am not looking for. I am still looking for a way to override the borderstyle drawing, nothing more nothing less.
The same article mentions that the user painting of the text box is not possible and if such a workaround does not work for you, you need to create a new control, from scratch.
BTW what is your final goal? Wouldn't it be possible to:
- Make a new user control
- Put a text box on it with border style set to None
- Draw the border around the text box, either using OnPaint or other controls with the appropriate border

The only bad thing is that you will lose all the text box properties and will need to write things like:

public int TextLength { get {return this.textBox.TextLength;}}
Ok this right...

Then look at

www.purecomponents.com

They have a program that EXTENDS these normal controls, so it is possible.
I don't see a text box in this components. The statement was that overriding of TextBox especially does not work, not that all constrols are impossible to extend
You mentioned in the original post:

"So everytime that I have tried to date I do get my custom border, but I also get the default  border as well."

If you set the border type to none and then draw your own like you do? then the "default border" will actually be empty, or?
Look your waisting my time, I know its possible I have seen others do it.

The site I gave you has a component called EntrySetExtender, I have been beta testing it for over a month now and I can tell you it extends the textbox control and some others.

If you can't answer my question then don't continue. As I said I know its possible because I have seen $500 components/controls do what I am looking for if its not possible then how do they do it then?
You are very rude and will not get a lot of help here in this way. I tried to think together with you about different solutions but obviously you don't need that. I wish you a lot of luck.
Ok the border style set to none reduces the area in which to draw in, what this means is that the spacing around the control is reduced, I have tried that too.
i think the problem is you are drawing only the client area (i bet you use ClientRectangle to obtain the rectangle to draw)
this does not cover the non client area of the control :)

hth, A.

No I don't but if I could extend the client area then I might be on the right track.
ASKER CERTIFIED SOLUTION
Avatar of TheAvenger
TheAvenger
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And where is my text input on that code, it draws a border with no text input. No to mention crashes my IDE after running it.
Do you set anything additionally? Like UserPaint? Because UserPaint must be false in this case
It works just find in my environment (WinXP Pro, VS 2003) and draws a red border around the text box
TheAvenger,

I really Appreciate your help on this, but your solution is what I have already done.

What I would like is to extend the borderstyle, and that include not reducing the spacing around the input area.