PePe

I have the following problem :

I created a new control using the code below.

It's used to translate the text in a label using values stored in a database

I added the control to a form

Set the text property of my control (in the property window) to testEntity.texttest

When changing to another property the text in the propery window and in the label on my form changes directly to texttest, it erases everything before the dot.

If I delete the translation code and in the get part of the property I write return MyBase.Text it also erases the part before the dot

Can somebody explain me how this is possible

Code Snippet

Imports System

Imports System.Windows.Forms

' The labeltext is evaluated and if it respons to the format ENTITYNAME.TEXTNAME then the translation in the current language is displayed

Public Class TranslatedLabel

Inherits System.Windows.Forms.Label

Public Overrides Property Text() As String

Get

Dim myText As String = MyBase.Text

If myText <> "" Then

myText = Translator.Instance.TranslateEntityText(myText)

End If
Return myText

End Get

Set(ByVal value As String)

MyBase.Text = value

End Set

End Property

End Class



Re: Visual Basic General Overrides text property of a label gives problems

cybertaz69

Could not duplicate issue... Please try this verison and reply with results....

Code Snippet

Public Class mylabel

Inherits Label

Private _text As String

Public Overrides Property Text() As String

Get

if _text <> "" then

Return "MyText is " & _text

else

Return _text

end if

End Get

Set(ByVal value As String)

_text = value

End Set

End Property

End Class






Re: Visual Basic General Overrides text property of a label gives problems

PePe

Hey,

I've replaced my code by your code

When typing something in the text property of the properties window the same text is shown on my form (design view).

It isn't displayed as MyText is ..

When again I try to type in the textbox something like entityname.text the entityname is directly deleted from the property and not seen on the form





Re: Visual Basic General Overrides text property of a label gives problems

cybertaz69

TRy rebuilding your solution... I just test the sample I sent you and it corrects the property window with "My text is ......." every time...




Re: Visual Basic General Overrides text property of a label gives problems

cybertaz69

I see the issue now...... Its a problem with the autosize event........

Change the label property to autosize false and streach the label out to show all the text.....






Re: Visual Basic General Overrides text property of a label gives problems

cybertaz69

The get was modifing the text and not calling the autosize event.... try this code...

Code Snippet

Public Class mylabel

Inherits Label

Public Overrides Property Text() As String

Get

If MyBase.Text <> "" Then

Return "MyText is " & MyBase.Text

Else

Return MyBase.Text

End If

End Get

Set(ByVal value As String)

MyBase.Text = value.Replace("MyText is ", "")

End Set

End Property

End Class






Re: Visual Basic General Overrides text property of a label gives problems

PePe

First time I rebuild the complete solution it worked like you described.

Then I made some modifications to show my translated values

Rebuild it and it didn't work anymore

Reinjected your code rebuild the solution and your code doesn't work anymore.

Can you give me your opinion on this :

Adding a property of my own to the label class where I enter the entity name and let that property update mybase.text of the labelclass with the translated value could that be the solution





Re: Visual Basic General Overrides text property of a label gives problems

PePe

Tried your remark about autosize but it didn't function I think something is realy fu... in my solution

I stil can't type the dot between some texts using the properties window (It works when at runtime I set the values) and the form that I uses to put the home made labels on doesn't do what is written in the labels.

Sorry but I get a little depressed about it





Re: Visual Basic General Overrides text property of a label gives problems

cybertaz69

I ziped up the project... try it and tell if you get the same error...

http://downloads.tampacct.com/Projects/mylabeltest.rar






Re: Visual Basic General Overrides text property of a label gives problems

PePe

Your testproject works fine with me.

What I really want to do with the label

I've got some functionality in a dll that searches for a translation giving an entity and text

Example

TranslateEntityText(TANK.ERRORCONNECTION)

Where TANK is the entity and ERRORCONNECTION the text he needs to search (entity is for grouping some texts)

So what I want is I write the Entity.text in the text property and he must give me the translated value.

I think the problem is when I type Entity.text in the text property it searches my translation and replaces the base text.





Re: Visual Basic General Overrides text property of a label gives problems

cybertaz69

Since I don't do any thing with translations I just simulated a translation......

To show the base text wasn't changed I added a label to show the base text without translation....

I also added a design mode check so the text would only be translated in run mode....

Code Snippet

Public Class mylabel

Inherits Label

Public Overrides Property Text() As String

Get

If MyBase.Text <> "" Then

If Me.DesignMode Then

Return MyBase.Text

Else

'Simulated tranlation......

Return MyBase.Text.Replace("Hellow", "Ola")

End If

Else

Return MyBase.Text

End If

End Get

Set(ByVal value As String)

MyBase.Text = value

End Set

End Property

Public Property mytext() As String

Get

Return MyBase.Text

End Get

Set(ByVal value As String)

MyBase.Text = value

End Set

End Property

End Class

Code Snippet

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.Label1.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.Mylabel1, "mytext", True))

End Sub

End Class






Re: Visual Basic General Overrides text property of a label gives problems

PePe

Thank you very much,

The above solution did work fine

I deleted the project from my solution, deleted the references, create a new project with your code (adapted with the translator) and remake all of my references and it works fine.

Regards