claudinei Posted April 23, 2009 at 10:14 PM Report #258732 Posted April 23, 2009 at 10:14 PM Boa noite, venho lhe pedir uma grande ajuda, estou para criar um novo controle herdando as propriedades do textbox, só que estou tendo um problema em uma linha que esta em vermelho conforme abaixo, pois estou quebrando a cabeça a várias semanas e não consegui a solução para o problema, veja o erro abaixo, o que devo fazer para resolver este problema. linha 1 - Imports System linha 2 - Imports System.Windows.Forms linha 3 - Imports System.Drawing linha 4 - Imports System.ComponentModel linha 5 - Public Class newtextbox linha 6 - Inherits System.Windows.Forms.TextBox linha 7 - End Class Error 1 Base class 'System.Windows.Forms.TextBox' specified for class 'newtextbox' cannot be different from the base class 'System.ComponentModel.UserControl' of one of its other partial types. C:\teste\controle\newtextbox.vb linha 6 coluna 14 controle
GOMES Posted April 24, 2009 at 07:57 AM Report #258768 Posted April 24, 2009 at 07:57 AM Bom dia Normalmente crio um extender de uma class. Mas a herança passa por algo como este exemplo Imports System Imports System.Collections.Generic Imports System.ComponentModel Imports System.Data Imports System.Drawing Imports System.Linq Imports System.Text Imports System.Windows.Forms Public Class Form1 Inherits Form Dim textBox1 As TextBox Public Sub New() InitializeComponent() End Sub Private Sub InitializeComponent() Me.textBox1 = New System.Windows.Forms.TextBox() Me.SuspendLayout() ' ' textBox1 ' Me.textBox1.AcceptsReturn = True Me.textBox1.AcceptsTab = True Me.textBox1.Dock = System.Windows.Forms.DockStyle.Fill Me.textBox1.Multiline = True Me.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical ' ' Form1 ' Me.ClientSize = New System.Drawing.Size(284, 264) Me.Controls.Add(Me.textBox1) Me.Text = "TextBox Example" Me.ResumeLayout(False) Me.PerformLayout() End Sub End Class cumpts
Hellblazer Posted April 24, 2009 at 11:41 AM Report #258798 Posted April 24, 2009 at 11:41 AM Podias enviar-me um projecto com essa classe para eu dar uma vista de olhos? There are two ways to write error-free programs; only the third one works.
GOMES Posted April 24, 2009 at 12:51 PM Report #258806 Posted April 24, 2009 at 12:51 PM Boa tarde O projecto e um ClassLibrary1 Depois tenho varias classes tipo gridview,text box e etc. Aqui vai um exemplo da textbox enviar como posso fazer isso? Imports Microsoft.VisualBasic Imports System.ComponentModel Imports System.Windows.Forms Public Class TextBoxControlDG Inherits TextBox Sub New() Me.BackColor = Color.Yellow Me.Font = New Font("Maiandra GD", 9, FontStyle.Italic) End Sub <DefaultValue(GetType(Color), "Yellow")> _ Public Overrides Property BackColor() As System.Drawing.Color Get Return MyBase.BackColor End Get Set(ByVal value As System.Drawing.Color) MyBase.BackColor = value End Set End Property <DefaultValue(GetType(Font), "Maiandra GD, 9pt, style=Italic")> _ Public Overrides Property Font() As System.Drawing.Font Get Return MyBase.Font End Get Set(ByVal value As System.Drawing.Font) MyBase.Font = value End Set End Property Protected Overrides Sub OnLeave(ByVal e As System.EventArgs) If Not IsNumeric(Me.Text) Then MessageBox.Show("You must enter a numeric value!", _ "Please try again....", MessageBoxButtons.OK, _ MessageBoxIcon.Exclamation) Me.Focus() End If End Sub Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs) If Not File.Exists(Me.Text) Then Me.ForeColor = Color.Red Else Me.ForeColor = Color.Black End If MyBase.OnTextChanged(e) End Sub Private Sub txtIntegerValidate(ByVal e As _ System.Windows.Forms.KeyPressEventArgs) If (e.KeyChar >= "!" And e.KeyChar <= "/") Or _ (e.KeyChar >= ":" And e.KeyChar <= "~") Then e.Handled = True End If End Sub Protected Overrides Sub OnKeyPress(ByVal e As _ System.Windows.Forms.KeyPressEventArgs) Select Case objType Case objType.Numeric Call txtIntegerValidate(e) Case objType.Text Call txtStringValidate(e) Case objType.Mixed Call txtMixedValidate(e) End Select End Sub End Class
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now