caeanis Posted January 27, 2010 Posted January 27, 2010 (edited) I have a custom textbox class that is set public scope. I created it because I needed to override the WndProc sub to handle paste messages sent from this control. The problem I'm having is that when the form is compiled, I get no error messages but the textbox doesn't show on the form. I've posted my code below, and would appreciate any observations on what I missed. I'm sure it's something simple... Public Class optyTextBox Inherits System.Windows.Forms.TextBox Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) Const WM_PASTE As Int32 = &H302 Select Case m.Msg Case WM_PASTE ' The clipboard contents were pasted... 'Code to handle paste event. End Select End Sub End Class Shared WithEvents txtZip As optyTextBox Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load txtZip = New optyTextBox txtZip.Name = "txtZip" txtZip.Font = New System.Drawing.Font("Tahoma", 6.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) txtZip.Location = New System.Drawing.Point(142, 160) txtZip.Margin = New System.Windows.Forms.Padding(2, 3, 2, 3) txtZip.Size = New System.Drawing.Size(59, 18) txtZip.TabIndex = 28 txtZip.Visible = True ' Shouldn't this work? Me.Controls.Add(txtZip) txtZip.Show() ' I tried using this line to see if it forced the control to 'be visible but no dice... End Sub Edited January 27, 2010 by caeanis Quote
Leaders snarfblam Posted January 27, 2010 Leaders Posted January 27, 2010 This code has one major problem: Public Class optyTextBox Inherits System.Windows.Forms.TextBox Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) Const WM_PASTE As Int32 = &H302 Select Case m.Msg Case WM_PASTE ' The clipboard contents were pasted... 'Code to handle paste event. End Select End Sub [color="Red"] MyBase.Wndproc(m)[/color] End Class When you override a method like this it means that the base method wont be called. Yours will be called instead. If you need the base method to be called, you must do this explicitly in your overriding method. In the case of WndProc, when you don't call the base method, the TextBox will not recieve any messages. Quote [sIGPIC]e[/sIGPIC]
Administrators PlausiblyDamp Posted January 27, 2010 Administrators Posted January 27, 2010 Try changing the class definition to Public Class optyTextBox Inherits System.Windows.Forms.TextBox Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) Const WM_PASTE As Int32 = &H302 Select Case m.Msg Case WM_PASTE ' The clipboard contents were pasted... 'Code to handle paste event. Case Else MyBase.WndProc(m) End Select End Sub End Class If you are not interested in a particular message you need to pass it on to the default WndProc so it still gets processed. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.