Re: Measurment Converstions
feet = ((metres * 100) / 2.25 / 12)
You'll need to show some code for a useful answer, but i'm not sure how you're hoping to shoehorn imperial conversions in there...
Re: Measurment Converstions
Do you have hundreds or thousands of output labels?
Re: Measurment Converstions
at minimum hundreds on the 50 odd forms.
Re: Measurment Converstions
i can do the conversion was more after the correct way its usually handled.
Re: Measurment Converstions
How about this:
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler Label1.TextChanged, AddressOf ClassHandlers.Labels_TextChanged
End Sub
End Class
Code:
Public Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler Label1.TextChanged, AddressOf ClassHandlers.Labels_TextChanged
End Sub
End Class
Code:
Public Class ClassHandlers
'you need to set this on checkbox_imperial.checkedchanged
Public Shared convert As Boolean
Public Shared Sub Labels_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
If convert Then
Dim lbl As Label = DirectCast(sender, Label)
If lbl.Text.EndsWith("lm") Then
Dim d As Decimal
If Decimal.TryParse(lbl.Text.Replace("lm", ""), d) Then
'conversion code here and output back to the same label
End If
End If
End If
End Sub
End Class
Re: Measurment Converstions
There might be a more efficient answer, but I really can't think how...
Re: Measurment Converstions
Quote:
Originally Posted by
.paul.
There might be a more efficient answer, but I really can't think how...
thx heaps for that .paul i will check it thoroughly
Re: Measurment Converstions
As far as your form will contains such huge amount of labels, it is better to create your own Label and encapsulate required conversions.
Here is a working code you can start with
VB.NET Code:
Option Strict On
Option Explicit On
Public Class MyLabel
Inherits System.Windows.Forms.Label
Public Enum Units
Centimetre
Meter
'
Inch
Foot
End Enum
Private _Unit As Units
Public Property Unit() As Units
Get
Return _Unit
End Get
Set(ByVal value As Units)
_Unit = value
Select Case value
Case Units.Meter ' it is the default, so no conversion needed
Me.Text = CStr(Me.Value) & " m"
Case Units.Centimetre
Me.Text = CStr(Me.Value * 100) & " cm"
Case Units.Foot
Me.Text = CStr(Me.Value / 0.3048) & " ft"
Case Units.Inch
Me.Text = CStr(Me.Value / 0.0254) & " in"
End Select
End Set
End Property
Public Sub New()
Me.Unit = Units.Meter ' set default unit.
End Sub
Private _Value As Decimal
Public Property Value() As Decimal
Get
Return _Value
End Get
Set(ByVal value As Decimal)
_Value = value
Me.Text = CStr(value) & " m"
End Set
End Property
End Class
Usage
VB.NET Code:
Option Strict On
Option Explicit On
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
MyLabel1.Value = 10 ' meters
RadioButton3.Checked = True ' convert to feet
End Sub
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
MyLabel1.Unit = MyLabel.Units.Meter
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged
MyLabel1.Unit = MyLabel.Units.Centimetre
End Sub
Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton3.CheckedChanged
MyLabel1.Unit = MyLabel.Units.Foot
End Sub
Private Sub RadioButton4_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton4.CheckedChanged
MyLabel1.Unit = MyLabel.Units.Inch
End Sub
End Class
Re: Measurment Converstions
Hi,
why not in diffrent Datagridviews?
regards
Chris