0

I am working on one assignment to Create a user control inheriting a text box which would allow only capital alphabets. i am still working with it. below is the code which i have worked till now.

Imports System.ComponentModel
Imports System.Windows.Controls

Partial Public Class textboxupper_uc

 Inherits TextBox

    Dim strUpperText As String

    Sub New()
        InitializeComponent()
    End Sub

    Public Property uppText As String
        Get
            Return strUpperText
        End Get
        Set(value As String)
            strUpperText = value.ToUpper
        End Set
    End Property
End Class

the line Inherits TextBox giving error as "Base class "TextBox" specified for class 'textboxupper_uc' can not be different from the base class 'user control' of one of its other partial types."

1
  • Given that this is an assignment, I guess you have to do what it says. The things is though, you can simply set the CharacterCasing property of a standard TextBox to Upper and then anything typed in will be displayed in upper-case. Commented Apr 23, 2018 at 7:14

1 Answer 1

1

You need to understand the difference between a user control and a custom control. If you want to inherit the TextBox class then that is a custom control. A user control is literally a class that inherits UserControl.

If you added a user control to your project then you have two code files containing partial classes. The designer code file contains Inherits UserControl and that's why you get that error message. Your class cannot inherit both UserControl and TextBox.

You don't actually want a user control so delete that item from the Solution Explorer. You want a custom control, you should add a class item to your project rather than a user control. In the class definition in the single code file, you can then add Inherits TextBox and you're good to go.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.