dcsimg
Results 1 to 6 of 6

Thread: [RESOLVED] Tool creation/customization

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    471

    Resolved [RESOLVED] Tool creation/customization

    I am trying to create/customize the panel tool to have the capability to change the border color property. I have a very rudimentary (non-existent might be closer to the truth) understanding of the process required to do this.

    To date, I have been able to create a textbox tool that adds properties to the a textbox tool and sets the color and font for the textbox. From this I am trying to understand how to achieve what I am after.

    So for the tool that I successfully created I did the following:

    1. Project created and named

    2. Class created with same name as project.

    3. Class coded

    Code:
    Public Class NumericTextBox
      Inherits System.Windows.Forms.TextBox
      Dim wDecimal As Boolean
      Dim wNegative As Boolean
      <System.ComponentModel.Category("Behavior")> Public Property HasDecimal() As Boolean
        Get
          Return (wDecimal)
        End Get
        Set(ByVal Value As Boolean)
          wDecimal = Value
        End Set
      End Property
      <System.ComponentModel.Category("Behavior")> Public Property HasNegative() As Boolean
        Get
          Return (wNegative)
        End Get
        Set(ByVal Value As Boolean)
          wNegative = Value
        End Set
      End Property
      Public Sub New()
        Me.BackColor = Color.Yellow
        Me.ForeColor = Color.Blue
            Me.Font = New Font("Times New Roman", 11)
            Me.HasDecimal = True
        Me.HasNegative = False
      End Sub
      Private Sub NumericTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
        'check pressed key
        Select Case e.KeyChar
          Case CChar("0") To CChar("9"), ControlChars.Back
            'allow numbers or backspace
            e.Handled = False
          Case CChar(".")
            'allow decimal if HasDecimal is True
            If (HasDecimal) Then
              'check if decimal already there
              If InStr(Me.Text, ".") = 0 Then
                e.Handled = False
              Else
                e.Handled = True
              End If
            Else
              e.Handled = True
            End If
          Case CChar("-")
            'allow single negative sign in first position only if HasNegative is True
            If (HasNegative) Then
              If InStr(Me.Text, "-") = 0 And Me.SelectionStart = 0 Then
                e.Handled = False
              Else
                e.Handled = True
              End If
            Else
              e.Handled = True
            End If
          Case Else
            'no other keys allowed
            e.Handled = True
        End Select
      End Sub
    End Class
    4. From the Build tab on menu I ran the Build ToolName menu item, which created the required dll file.
    5. From the Tools tab on menu I ran the Choose Toolbox Items and selected the newly created tool.
    6. The new textbox tool was now on the toolbox and worked as expected.

    At this point I am wanting to take the Panel tool and be able to change the border color. I would prefer to use a method similar to that used by the above textbox tool, where a capability was added by adding it to the properties window. However, I am not even close to be able to duplicate that for my intended use.

    What I have tried to do is use the code below. I have used this in the past to be able to set the color of a panel border. The methodology for setting it up was different and I do not recall what the process was. However, I used the same methodology I used for the textbox tool noted above and eventually had a dll file created with no errors, and checked as a tool.

    Code:
    Public Class BorderPanel
        Inherits System.Windows.Forms.Panel
     
        Private _borderColor As Color = Color.Black
     
        Public Property BorderColor As Color
            Get
                Return _borderColor
            End Get
            Set(value As Color)
                If _borderColor <> value Then
                    _borderColor = value
                    OnBorderColorChanged(EventArgs.Empty)
                End If
            End Set
        End Property
     
        Public Event BorderColorChanged As EventHandler
     
        Protected Overridable Sub OnBorderColorChanged(e As EventArgs)
            'Repaint the control to update the colour of the border.
            Refresh()
     
            RaiseEvent BorderColorChanged(Me, e)
        End Sub
     
        Protected Overrides Sub OnPaint(e As PaintEventArgs)
            MyBase.OnPaint(e)
     
            Using p As New Pen(BorderColor)
                e.Graphics.DrawRectangle(p, 0, 0, Width - 1, Height - 1)
            End Using
        End Sub
    End Class
    It is at this point that I run into a problem. The tool BorderPanel is not displayed in the Tools Window. So where the hell is it?

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    471

    Re: Tool creation/customization

    I got rid of the dll files I created and then went through the process again. When I loaded the dll file to the Choose Toolbox Items I got the following message:

    Name:  ErrorMessage.jpg
Views: 171
Size:  35.5 KB

    So what will it take for me to make the control to be compatible with the current designer?

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,718

    Re: Tool creation/customization

    Are you adding this control to the Toolbox while you have a Windows form open in the designer? What is the .NET version that project is targeting and what version is your library project targeting?

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    471

    Re: Tool creation/customization

    I have been playing with this for quite awhile now and quite likely have added the toolbox with an open designer on more than one occasion.

    .Net Framework 4.6.1 for the project. I do not know where to obtain the version that the library project is targeting.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    471

    Re: Tool creation/customization

    It would appear that the issue is solved. It turned out that I needed to change the .Net Framework to 2.0 in the project. I think that was what JM was getting at with his questions. Additionally, there were a couple of minor coding errors that needed correction.

    Anyway, thanks.

    Some detail might be appreciated.

    1. Checked the Target frame work of the project for the textbox control previously created, tested and working. It was set to be .NET Framework 2.0

    2. The Target frame work of the Panel I wanted create was set to .NET Freamework 6.2.1. I changed this setting at the project level of the Panel and was able to create the tool and use it.
    Last edited by gwboolean; Jan 20th, 2019 at 08:05 PM.

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,718

    Re: [RESOLVED] Tool creation/customization

    Different version of the Framework may use different versions of the .NET CLR. .NET 2.0 introduced a new CLR and so did .NET 4.0. That means that .NET 2.0 to 3.5 use the same CLR and are thus compatible but you can't mix .NET 4.x with .NET 2.0 or 3.x. If you want the control to be compatible with applications target .NET 4.x then you need to compile the library containing it against .NET 4.0 at a minimum. There's nothing to stop you building two versions of the DLL: one against .NET 2.0 and one against .NET 4.0.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width