Watermarking a textbox

  • Thread starter Thread starter Johnny J.
  • Start date Start date
Yes and no - this was not what I was thinking of, but it might provide me
with a different solution. With this textbox I could put the image in an
imagebox behind the textbox, and all would be solved.

I hadn't thought of that...

Thanks a lot Mike, I'll give it a go,
Johnny J.
 
Johnny said:
I have tested now, and it does work with multiline

But the textbox behaves strangely:

1) It flickers when you write
2) You can actually place the cursor outside the text
3) If you doubleclick the text, it becomes bold and when the textbox
loses focus, it returns to normal

If somebody has experience solving these problems, I'd really like to
know... ;-)

Cheers
Johnny J.

For item 1, set the form containing the control to DoubleBuffered in the
properties.

I think this replacement code fixes/addresses items 2 and 3.

Protected Overrides Sub OnPaint _
(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
Dim size As Single = Font.SizeInPoints * e.Graphics.DpiY / 72.0!
Dim f As New Font _
(Font.Name, size, Font.Style, GraphicsUnit.Point, Font.GdiCharSet)

TextRenderer.DrawText(e.Graphics, Text, f, _
New Point(0, 0), Me.ForeColor)
End Sub
 
Johnny said:
I searched the web for code like that (not specifically VB6 code), but
didn't find any - hence my post to this forum. But I think I'm on my way
to finding the .NET solution. In another thread to the post, a solution
is suggested by another Mike (or is it you in disguise?), and that looks
promising.

Thanks a lot for the help,
Johnny J.

No, this was not me. He does go by other names, per some posters though.
 
Johnny J. said:
Sorry Nathan, but you misread my question. By watermark, I don't mean a
descriptive text, I mean a semi transparent image.

Besides: I'm trying to do it in a windows app - not ASP.NET

But thanks anyway,
Johnny J.

When you use Windows Forms controls, you must use them as is. Meaning there
is no way to do it. I think ASP .NET was brought up because you do have
some control over the rendering of HTML controls in a browser using CSS.

-Scott
 
Mike said:
Wrong again, Scotty.

Mike

No, he is actually correct. Strictly speaking, a text box cannot do
what was asked. Your answer and mine don't use a text box, but rather a
control derived from it, and therefore, not the text box.
 
Family Tree Mike said:
No, he is actually correct.

No - "strictly spoken" his statement is just wrong. ;-)
Strictly speaking, a text box cannot do what was asked.
Your answer and mine don't use a text box, but rather
a control derived from it, and therefore, not the text box.

So, to take up parts of Scotts response - the solution is:
When you use Windows Forms controls, you should
derive from them (and override appropriate routines) -
you don't have to use them "as is".
Meaning, there is a way to do it...

;-) SCNR

Olaf
 
Schmidt said:
Newsbeitrag


No - "strictly spoken" his statement is just wrong. ;-)


So, to take up parts of Scotts response - the solution is:
When you use Windows Forms controls, you should
derive from them (and override appropriate routines) -
you don't have to use them "as is".
Meaning, there is a way to do it...

;-) SCNR

Olaf

My response was that the Windows.Forms.Textbox does not allow for this
behavior and cannot be done using it.

If you want to do it, you must create your own implementation of the Textbox
(as has been shown).

-Scott
 
No, he is actually correct. Strictly speaking, a text box
cannot do what was asked. Your answer and mine
don't use a text box, but rather a control derived from
it, and therefore, not the text box.

Well according to the OP your own answer provided a very poor solution to
his problem, completely messing up the text entered in the box and causing
the image to flicker greatly, although I am sure it could probably be
improved when coded properly, whereas the solution at the link I posted had
neither of those problems. However, in both cases it was still a TextBox,
albeit a modified one. It's essentially the same thing. You are splitting
hairs. In VB6 you can do it directly on the TextBox simply by modifying its
behaviour, and apparently (according to what you have said) in VB.Net you
need to do it a slightly different way and derive a new and modified control
from a standard TextBox, but in either case the OP's requirements can very
definitely be done, both in VB6 and in VB.Net. I wondered why Scotty had
suddenly popped up again to lead you into this response after my recent post
in which I said I had corrected him.

The OP asked how he could have an image in a multi line TextBox in VB.Net
and Scott told him there is no way to do it. That was it! No "deriving other
controls from it" and no "modifying its normal behaviour" and no other
solution at all. Merely a blunt statement that it could not be done! Scott
was wrong, and he is still wrong. It can be done. If the OP had believed
Scotty then he would have gone away without a solution to his problem.
That's a bit nasty, isn't it. Hiding behind some VB.Net semantics in an
attempt to deceive the OP and to lead him to believe that there was no
solution to his problem, when in fact there very definitely is a solution
(as in the link I posted for him). In fact, since my posting the OP has
responded and has apparently gone away quite happy, whereas if he had
believed Scotty and had not waited for responses from people other than
Scotty who were more prepared to help him then he would not now have the
solution to his problem. Is that really the way you treat people who ask
questions on the VB.Net group? Do you really believe that Scotty was right
to hide behind some silly semantics and tell him that it could not be done,
when in fact it can be done? Jees! Is Scotty so insecure that he needs to
insist on continuing to deceive people and prevent them from getting a
solution to their problems just so that he can wallow in his silly semantics
and massage his own over inflated ego. What a nasty person he must be! No
wonder he enjoys himself in his trolling activities in the VB6 group, where
he provides almost no answers at all to programming questions and where he
restricts himself mainly to trolling. What a nasty piece of work he must be.

Mike
 
Johnny said:
Does anyone have any sample code on how to draw a semi transparent image
as a watermark on a multiline textbox?

Maybe you can utilize this technique:

Tile a Bitmap Into a TextBox Background
<URL:http://vbaccelerator.com/article.asp?id=1204>

The sample is in VB6, but the technique can be transformed to a Windows
Forms textbox because both a Win32 edit controls.
 
Scott --
When you use Windows Forms controls, you must use them as is. Meaning there
is no way to do it.

Most of the controls provide at least limited capabilities for styling,
such as adjusting the border and setting foreground and background
colors. In addition, Windows' theming/visual styles allow for further
customization of most controls.
I think ASP .NET was brought up because you do have
some control over the rendering of HTML controls in a browser using CSS.

Well, I think ASP.NET was brought up to enable people to write Web pages
which are hosted on Windows servers...
 
Sorry Mike

It's better, but not ok. All the three issues were basically solved with
this (including the flicker. I had already double buffered the control, but
it didn't help. With this new code, it doesn't flicker anymore thought), BUT
the text still looks strange.

It's hard to explain, without a screenshot, but I'll try:

I have two textboxes right next to one another, a normal textbox and the
"watermarktextbox", and therefor it's important that the text looks the same
in both. But in the watermark textbox:

1) The font is bigger (even though the two textboxes have the same -
standard - font properties) - the "size" value in your code shows 11 when
debugging

2) The text is still bold WHILE YOU WRITE (but it no longer gets bold when
you doubleclick the text), and when the textbox loses focus, it returns to
normal.

3) The cursor problem seems solved

Cheers
Johnny J.
 
Mike Williams said:
The OP asked how he could have an image in a multi line TextBox in VB.Net
and Scott told him there is no way to do it.

That's not quite *all* of what I said Mike, now you are splitting hairs. I
specifically talked about the System.Windows.Forms controls and said that
using them as it does not provide a way to do it.
That was it! No "deriving other controls from it" and no "modifying its
normal behaviour" and no other solution at all. Merely a blunt statement
that it could not be done! Scott was wrong, and he is still wrong. It can
be done.

I interpreted the question to be asking if there was a built in way to do it
with the Textbox provided in .NET out of the box. If you believe that is
wrong, please show how to do it with that control.


What follows is Mike just stroking his own ego and making a mountain out of
his own misunderstanding of my response.
 
Herfried K. Wagner said:
Scott --


Most of the controls provide at least limited capabilities for styling,
such as adjusting the border and setting foreground and background colors.
In addition, Windows' theming/visual styles allow for further
customization of most controls.

So, how do you use the System.Windows.Forms.Textbox to solve the OP's
question using any of the techniques you just mentioned?
Well, I think ASP.NET was brought up to enable people to write Web pages
which are hosted on Windows servers..

I think that ASP .NET was "invented" for the reasons you state. I think it
was brought up in this thread for the reasons I stated.
..
 
That's not quite *all* of what I said Mike, now you are splitting hairs.

No I am not splitting hairs, Scotty. I have posted EXACTLY what you said,
and so far you have ignored it. You are telling lies again. I'll say it
again Scotty, since you are currently lying about it. The following is
EXACTLY what I posted the other day. The OP asked:

"Does anyone have any sample code on how to draw
a semi transparent image as a watermark on a multiline
textbox?"

.. . . and you replied:

"When you use Windows Forms controls, you must use
them as is. Meaning there is no way to do it".

Stop lying, Scotty. The above is *exactly* what you said, as I have
mentioned before.
I specifically talked about the System.Windows.Forms controls and
said that using them as it does not provide a way to do it.

I'll take it that you meant to say "as is" rather than just "as" in the
above statement Scotty, otherwise it does not make sense, even in Australia.
But you are lying again, Scotty. You did not merely say that using them as
is does not provide a way to do it. In fact the OP did not ask about using
the control "as is" and you put those words into your reply yourself and you
told the OP that he ***MUST*** use them "as is". You also told him that
there is no way to do what he asked. Your EXACT WORDS are as I have quoted
above. Stop lying Scotty. Just admit you were wrong and then stop lying
about it. You'll feel better for it. The OP is now in a position to do what
he had asked, a position he would not be in if he had believed your lies and
if he had not waited for a better response from others. You did not help the
OP at all, Scotty, and you lied to him (unless of course you simply did not
know how to do it yourself, which is what I personally think, and that you
are now frightened to admit it). There's no shame in not knowing something,
Scotty. It happens to us all, lots of times. Just admit it, and stop telling
lies.
I interpreted the question to be asking if there was a built in way
to do it with the Textbox provided in .NET out of the box.

Well if you misinterpreted the OP's question then that's your own fault,
Scotty. Don't try to blame other people for your own mistakes. The OP never
mentioned the phrase "as is", nor did he mentionn the phrase "out of the
box", nor the phrase "built in way" or anything even remotely similar, and
neither did he imply any of those phrases. The exact words the OP used were,
"Does anyone have any sample code on how to draw a semi transparent image as
a watermark on a multiline textbox?" and you told him that it could not be
done. Just admit that you made a mistake, Scotty, and that you were wrong.
Just stop lying Scotty. Here, again, is EXACTLY what the OP said, and
EXACTLY what you said in your response to him.

The OP said:

"Does anyone have any sample code on how to draw
a semi transparent image as a watermark on a multiline
textbox?"

.. . . and you replied:

"When you use Windows Forms controls, you MUST use
them as is. Meaning there is no way to do it".

Come on, Scotty. Don't be scared. Just admit you were wrong. You'll feel
better for it.

Mike
 
Mike Williams said:

I really don't think you understand what the word "lie" means, because you
use it everytime you "disagree" with something I've said. Your disapproval,
does not make my statement a lie.
Well if you misinterpreted the OP's question then that's your own fault,
Scotty. Don't try to blame other people for your own mistakes.

I really don't think I'm trying to "blame" anyone for anyting. But, it sure
seems as if you are.
The OP never mentioned the phrase "as is", nor did he mentionn the phrase
"out of the box", nor the phrase "built in way" or anything even remotely
similar, and neither did he imply any of those phrases. The exact words
the OP used were, "Does anyone have any sample code on how to draw a semi
transparent image as a watermark on a multiline textbox?" and you told him
that it could not be done.

I'm not going to defend or explain the OP and it's quite frankly ridiculous
for you to. I've told you how I intepreted the question and hence my
response.
Just admit that you made a mistake, Scotty, and that you were wrong. Just
stop lying Scotty. Here, again, is EXACTLY what the OP said, and EXACTLY
what you said in your response to him.

So, given my response was very clear about using the Windows Forms controls
"as is", please tell me how to add a watermark to a
System.Windows.Forms.Textbox as it is, out of the box.

I can tell that you are simply a barnacle that is going to "attach" yourself
to every post I make everywhere and immeidately start a flame war each time.
But, I have no time for children besides my own. I'm happy with my reply
and that's all I need. If you aren't, you'll have to find a way to get
through your day.

-Scott
 
So, given my response was very clear about using
the Windows Forms controls "as is"

You are lying again, Scotty. Your reply was not merely "about" using the
Cotrol "as is". The OP asked how to perform a specific task, without even
once mentioning wanting to use a Control "as is", and your reply
specifically said that the OP ***MUST*** use the Control "as is", and that
the job could not be done, which is simply not true on either count. You
were wrong, Scotty. Simply wrong. Why are you finding it so difficult to
admit that you were wrong!
please tell me how to add a watermark to a
System.Windows. Forms.Textbox as it is,
out of the box.

Stop begging, Scotty. Why on Earth should I do that? The OP never asked
about using a Control "as is" or "out of the box" to perform that task he
had asked about, and I never once mentioned anything about him being able to
do so. In fact the code at the link I posted made it abundantly clear that
the Control's behaviour must be modified in order to perform the task he
wanted to do, and many other similar tasks, and it showed him exactly how to
do it. You did not help him at all, Scotty. In fact you did him a
disservice. You told him that he MUST use the Control "as is" (or "out of
the box" as you are now calling it), and you were wrong to tell him that.
You also told him that the job could not be done, which is also wrong. You
were wrong on both counts, Scotty.

Just admit it, Scotty. You'll feel all the better for it. You are just
duckin' and divin' in your attempt to wriggle out of your mistakes. Here,
again, is exactly what the OP said, and exactly what you said in return. Why
do you keep skirting around the issue. You are pathetic, Scotty.

The OP said . . .

"Does anyone have any sample code on how to draw
a semi transparent image as a watermark on a multiline
textbox?"

Scotty said . . .

"When you use Windows Forms controls, you MUST use
them as is. Meaning there is no way to do it".

You are wrong, Scotty. Just admit it.
I'm happy with my reply and that's all I need.

You might be happy with your reply Scotty, but the OP certainly isn't,
because you did not tell him the truth and you did not help him. In fact you
hindered him. I would have thought that you were here to help people who
asked questions Scotty, but that is obviously not the case, and you have at
last admitted it, by telling us that you are here simply to make yourself
happy, even though by doing so you are hindering people who ask questions
and you are telling them lies (I shall continue to call it a lie Scotty
because you have still not admitted that it was one of your mistakes, and
that you were wrong). What a pathetic, unhelpful little troll you are. You
are beginning to look more and more pathetic in your fruitless duckin' and
divin'. Just admit that you were wrong, Scotty, and get on with the rest of
your life.

Mike
 
Back
Top