Question How to create UserControl from class

nbhatti2001

New member
Joined
Jun 23, 2011
Messages
3
Programming Experience
1-3
Plz help to implement the following class. I need to create user control in toolbox. i get it from this URL DataGridView.ProcessDialogKey Method (System.Windows.Forms)
thx in advance

Public Class CustomDataGridView
Inherits DataGridView

<System.Security.Permissions.UIPermission( _
System.Security.Permissions.SecurityAction.LinkDemand, _
Window:=System.Security.Permissions.UIPermissionWindow.AllWindows)> _
Protected Overrides Function ProcessDialogKey( _
ByVal keyData As Keys) As Boolean

' Extract the key code from the key value.
Dim key As Keys = keyData And Keys.KeyCode

' Handle the ENTER key as if it were a RIGHT ARROW key.
If key = Keys.Enter Then
Return Me.ProcessRightKey(keyData)
End If

Return MyBase.ProcessDialogKey(keyData)

End Function

<System.Security.Permissions.SecurityPermission( _
System.Security.Permissions.SecurityAction.LinkDemand, Flags:= _
System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)> _
Protected Overrides Function ProcessDataGridViewKey( _
ByVal e As System.Windows.Forms.KeyEventArgs) As Boolean

' Handle the ENTER key as if it were a RIGHT ARROW key.
If e.KeyCode = Keys.Enter Then
Return Me.ProcessRightKey(e.KeyData)
End If

Return MyBase.ProcessDataGridViewKey(e)

End Function

End Class
 
First up, it's not a UserControl. A UserControl is a class that inherits UserControl.

As for the question, you're trying to turn something easy into something difficult. You simply add a new class to your project with the appropriate name, add your code to the code file when it opens and then build the project. That's all there is to it.
 
Mean I will b unable to use it like control on toolbox.
But I can create its object by code and use it on form. m I rit?

I'm not sure if this is what your talking about about? Here's a screenshot example in VS 2008. (Fundamentally the same in 2010)
scnShot_CustomControl.jpg
like jmcilhinney said:
...You simply add a new class to your project with the appropriate name, add your code to the code file when it opens and then build the project. That's all there is to it.

so.. create a vb code file, add your code to it and then Build. After building it the components should show up in your toolbox like shown. Remember to Rebuild each time you edit the code though.
 
Back
Top