Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27208

VS 2008 label width calculated in a module

$
0
0
Dear all,

I have found code to calculate the width of a label in a form.

Knows someone to transfer this code to the script f a module?

Nice regards,
Michell.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxx Code for form
Public Class frmMain
Dim StringSize As New SizeF
Dim StringSizeForLargerFont As New SizeF
Dim StringSizeForLargestFont As New SizeF

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lblMessage.Text = "1234567890"
lblMessage.Width = 1280
lblMessage.Font = New System.Drawing.Font("Courier New", 11)
lblMessage.Font = New System.Drawing.Font(lblMessage.Font, FontStyle.Regular)
End Sub

Private Sub frmMain_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.PageUnit = GraphicsUnit.Pixel
StringSize = e.Graphics.MeasureString(lblMessage.Text, lblMessage.Font, lblMessage.Size)
MsgBox(StringSize.Width)
End Sub
End Class


xxxxxxxxxxxxxxxxxxxxxxxxxxxxx Allready created code:
Imports System.Windows.Forms
Imports System.Drawing

Module Module1
Dim StringSize As New SizeF
Dim StringSizeForLargerFont As New SizeF
Dim StringSizeForLargestFont As New SizeF
Dim FRM As New Form

Sub Main()


Dim LB As New Label
LB.Text = "1234567890"
LB.Width = 1280
LB.Font = New System.Drawing.Font("Courier New", 11)
LB.Font = New System.Drawing.Font(LB.Font, FontStyle.Regular)

AddHandler FRM.Paint, AddressOf claculateWidth
FRM.Refresh()

End Sub

Private Sub claculateWidth(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles FRM.Paint

End Sub
End Module

Viewing all articles
Browse latest Browse all 27208

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>