Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / November 2003

Tip: Looking for answers? Try searching our database.

WM_PASTE and textbox control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gerry Viator - 11 Nov 2003 17:41 GMT
Hi all,

Trying to not allow anything being pasted in textbox control in vb.net.

The following doesn't seem to be working

  Private Const WM_COPY = &H301
   Private Const WM_PASTE = &H302
   Private Const WM_CUT = &H300

   Protected Overrides Sub WndProc(ByRef m As Message)
       If m.Msg = WM_PASTE Then
           Dim txt As String =
Clipboard.GetDataObject().GetData(GetType(String))
           If txtboxYear.Focus = True Then
               Return
           End If
       End If
       MyBase.WndProc(m)
   End Sub 'WndProc

Thanks for any help
Gerry
Gerry Viator - 11 Nov 2003 19:18 GMT
Hi all,

I figured my own problem out.

I did this:

Public Class MyTextBox
   Inherits TextBox

   Private Const WM_COPY = &H301
   Private Const WM_PASTE = &H302
   Private Const WM_CUT = &H300
   Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

       'Stop the control from excepting paste commands
       If m.Msg = WM_PASTE Then
           Dim txt As String =
Clipboard.GetDataObject().GetData(GetType(String))

           Return
       End If

       MyBase.WndProc(m)

   End Sub

End Class

This works fine, do you have to always do it this way to add functionality
to the control? Can't you just entercept the
message from the form where the control is located?

One more thing how can I change the selected text color  in a textbox?

Thanks
Gerry

> Hi all,
>
[quoted text clipped - 19 lines]
> Thanks for any help
> Gerry
"Ying-Shen Yu[MSFT]" - 13 Nov 2003 14:34 GMT
Hi Gerry,

I'm afraid you need do in this way, .NET TextBox class is a wrapper of the
unmanaged TextBox common control. In this case, you are trying to change
the default behavior of the unmanaged TextBox, you need override the
WndProc and do it in traditional way.

In your another question, as far as I know, the text box only support
setting the text color and back color,
it doesn't support setting the color of selected text.  To set the selected
text color you may try the RichTextBox.

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending.
Gerry Viator - 13 Nov 2003 14:48 GMT
Thanks

Gerry

> Hi Gerry,
>
[quoted text clipped - 17 lines]
> You should not reply this mail directly, "Online" should be removed before
> sending.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.