My label will not word wrap and I cannot access my Text control

Two questions:

1) I have a large amount of textin one of my labels but it will not word wrap. I have found out that vb.net word wraps automatically, whereas in VB6 you had control? Does anyone have any suggestions?

2) I am trying to access the Text property on a label control from another module. This other module is running on a different thread. I have used mainFrm.welcomeLbl.Text = "Welcome" in my module code but without effect. I have even made the welcomeLbl public instead of friend. Still, nothing happens. Please help because this one is driving me insane!
[595 byte] By [markyoung1984] at [2007-11-20 10:51:04]
# 1 Re: My label will not word wrap and I cannot access my Text control
You can use the following to break the line yourself.

Command1.Caption = "Testing..." & Chr(10) & "Does this work?"
PeejAvery at 2007-11-10 3:08:24 >
# 2 Re: My label will not word wrap and I cannot access my Text control
Question 1 : http://www.dev-archive.com/forum/showthread.php?t=370571
HanneSThEGreaT at 2007-11-10 3:09:24 >
# 3 Re: My label will not word wrap and I cannot access my Text control
Command1.Caption = "Testing..." & Chr(10) & "Does this work?"
The Caption property is replcaed by the Text property for all those controls. If we were to change the above to :
Command1.Text = "Testing..." & Chr(10) & "Does this work?"
It should be fine :)

But, if we do this :
Button1.Text = "Testing..." & Environment.NewLine & "Does this work?"
It a bit more .NET appropriate :)

All this would work during run time only though.

The OP is also a bit mistaken about VB.NET having an WordWrap property for labels, it doesn't, AFAIK, but it does indeed have a WordWrap property for TextBoxes. This brings me to my next point. Why not use a Textbox instead You could easily change the TextBox's BackColor to Control, then, Change the Textbox's BorderStyle property to None - voila, now it looks identical to a label, but now, you could make use of the textBox's WordWrap Property, and Multiline property ( Both set to True and AllowDrop property set to True to achieve this, make sure though that your textbox is appropriately sized as well.
HanneSThEGreaT at 2007-11-10 3:10:34 >
# 4 Re: My label will not word wrap and I cannot access my Text control
Thanks for all your comments about the word wrapping. I used the text box instead. I still have this other label that I can't set the caption/text on.

Basically the program runs and another thread is started in the background, when the main form loads, that is performing another function. Throughout the other thread running, I want to change the text of a label, so the user can see the current status of the thread. I am currently doing this with the statement mainLbl.threadStatus.Text = "some text" but this does not seem to work. I have tried the mainFrm.Refresh() statement after, but this does not work either. Is there anything wrong with that? Do I need any additional name spaces in the module file that the thread code is in?
markyoung1984 at 2007-11-10 3:11:28 >
# 5 Re: My label will not word wrap and I cannot access my Text control
markyoung1984,

Look up "threading" in the online help. Then look at the "cross-thread calls" topic under the threading topic.

Kerry Moorman
kmoorman at 2007-11-10 3:12:33 >
# 6 Re: My label will not word wrap and I cannot access my Text control
Yeah, that can get quite tricky indeed. I got this code from MSDN. This code shows how to safely set the text in a Textbox, how to do it unsafely ( which will produce an error ), and also, it shows how to use the BackgroundWorker. Just start a new project, and paste this in :
Imports System
Imports System.ComponentModel
Imports System.Threading
Imports System.Windows.Forms

Public Class Form1
Inherits Form
' This delegate enables asynchronous calls for setting
' the text property on a TextBox control.
Delegate Sub SetTextCallback(ByVal [text] As String)

' This thread is used to demonstrate both thread-safe and
' unsafe ways to call a Windows Forms control.
Private demoThread As Thread = Nothing

' This BackgroundWorker is used to demonstrate the
' preferred way of performing asynchronous operations.
Private WithEvents backgroundWorker1 As BackgroundWorker

Private textBox1 As TextBox
Private WithEvents setTextUnsafeBtn As Button
Private WithEvents setTextSafeBtn As Button
Private WithEvents setTextBackgroundWorkerBtn As Button

Public Sub New()
InitializeComponent()
End Sub

Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso (components IsNot Nothing) Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub

' This event handler creates a thread that calls a
' Windows Forms control in an unsafe way.
Private Sub setTextUnsafeBtn_Click( _
ByVal sender As Object, _
ByVal e As EventArgs) Handles setTextUnsafeBtn.Click

Me.demoThread = New Thread( _
New ThreadStart(AddressOf Me.ThreadProcUnsafe))

Me.demoThread.Start()
End Sub

' This method is executed on the worker thread and makes
' an unsafe call on the TextBox control.
Private Sub ThreadProcUnsafe()
Me.textBox1.Text = "This text was set unsafely."
End Sub

' This event handler creates a thread that calls a
' Windows Forms control in a thread-safe way.
Private Sub setTextSafeBtn_Click( _
ByVal sender As Object, _
ByVal e As EventArgs) Handles setTextSafeBtn.Click

Me.demoThread = New Thread( _
New ThreadStart(AddressOf Me.ThreadProcSafe))

Me.demoThread.Start()
End Sub

' This method is executed on the worker thread and makes
' a thread-safe call on the TextBox control.
Private Sub ThreadProcSafe()
Me.SetText("This text was set safely.")
End Sub

' This method demonstrates a pattern for making thread-safe
' calls on a Windows Forms control.
'
' If the calling thread is different from the thread that
' created the TextBox control, this method creates a
' SetTextCallback and calls itself asynchronously using the
' Invoke method.
'
' If the calling thread is the same as the thread that created
' the TextBox control, the Text property is set directly.

Private Sub SetText(ByVal [text] As String)

' InvokeRequired required compares the thread ID of the
' calling thread to the thread ID of the creating thread.
' If these threads are different, it returns true.
If Me.textBox1.InvokeRequired Then
Dim d As New SetTextCallback(AddressOf SetText)
Me.Invoke(d, New Object() {[text]})
Else
Me.textBox1.Text = [text]
End If
End Sub

' This event handler starts the form's
' BackgroundWorker by calling RunWorkerAsync.
'
' The Text property of the TextBox control is set
' when the BackgroundWorker raises the RunWorkerCompleted
' event.
Private Sub setTextBackgroundWorkerBtn_Click( _
ByVal sender As Object, _
ByVal e As EventArgs) Handles setTextBackgroundWorkerBtn.Click
Me.backgroundWorker1.RunWorkerAsync()
End Sub

' This event handler sets the Text property of the TextBox
' control. It is called on the thread that created the
' TextBox control, so the call is thread-safe.
'
' BackgroundWorker is the preferred way to perform asynchronous
' operations.
Private Sub backgroundWorker1_RunWorkerCompleted( _
ByVal sender As Object, _
ByVal e As RunWorkerCompletedEventArgs) _
Handles backgroundWorker1.RunWorkerCompleted
Me.textBox1.Text = _
"This text was set safely by BackgroundWorker."
End Sub

#Region "Windows Form Designer generated code"

Private Sub InitializeComponent()
Me.textBox1 = New System.Windows.Forms.TextBox()
Me.setTextUnsafeBtn = New System.Windows.Forms.Button()
Me.setTextSafeBtn = New System.Windows.Forms.Button()
Me.setTextBackgroundWorkerBtn = New System.Windows.Forms.Button()
Me.backgroundWorker1 = New System.ComponentModel.BackgroundWorker()
Me.SuspendLayout()
'
' textBox1
'
Me.textBox1.Location = New System.Drawing.Point(12, 12)
Me.textBox1.Name = "textBox1"
Me.textBox1.Size = New System.Drawing.Size(240, 20)
Me.textBox1.TabIndex = 0
'
' setTextUnsafeBtn
'
Me.setTextUnsafeBtn.Location = New System.Drawing.Point(15, 55)
Me.setTextUnsafeBtn.Name = "setTextUnsafeBtn"
Me.setTextUnsafeBtn.TabIndex = 1
Me.setTextUnsafeBtn.Text = "Unsafe Call"
'
' setTextSafeBtn
'
Me.setTextSafeBtn.Location = New System.Drawing.Point(96, 55)
Me.setTextSafeBtn.Name = "setTextSafeBtn"
Me.setTextSafeBtn.TabIndex = 2
Me.setTextSafeBtn.Text = "Safe Call"
'
' setTextBackgroundWorkerBtn
'
Me.setTextBackgroundWorkerBtn.Location = New System.Drawing.Point(177, 55)
Me.setTextBackgroundWorkerBtn.Name = "setTextBackgroundWorkerBtn"
Me.setTextBackgroundWorkerBtn.TabIndex = 3
Me.setTextBackgroundWorkerBtn.Text = "Safe BW Call"
'
' backgroundWorker1
'
'
' Form1
'
Me.ClientSize = New System.Drawing.Size(268, 96)
Me.Controls.Add(setTextBackgroundWorkerBtn)
Me.Controls.Add(setTextSafeBtn)
Me.Controls.Add(setTextUnsafeBtn)
Me.Controls.Add(textBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub 'InitializeComponent

#End Region

<STAThread()> _
Shared Sub Main()
Application.EnableVisualStyles()
Application.Run(New Form1())
End Sub
End Class

Are you sure you're going about this trivial task of setting another Form's Textbox's Text property, the right way Surely you're over complicating things. :)

Or is this in the lines of what you need

EDIT : Didn't see your reply Kerry, sorry. :) It seems as if you type faster than me :)
HanneSThEGreaT at 2007-11-10 3:13:32 >