If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Hybrid View

Backgroundworker and Delegate (center Text)

Hi All,

I have a BackgroundWorker and using a delegate to update an UI on a different thread. Everything is working except the "lblInfo.Left = (Me.Width / 3) - (lblInfo.Width / 4)".
I need this line since it allows me to center the text on the UI as I have several Subroutines and they all have various lengths in text. If possible, Can someone help me
pass the lblInfo.Left = (Me.Width / 3) - (lblInfo.Width / 4) from the delegate so I don't get a IllegalCrossThread. ANY help will be greatly appreciated.

lblInfo.Left = (Me.Width / 3) - (lblInfo.Width / 4) ' line that done work unless I set the Control.CheckForIllegalCrossThreadCalls = False which I don't want to.
SetLabelText(lblInfo, "File is being copied and will take a while. Please Wait...")
BackgroundWorker1.ReportProgress(20)

Re: Backgroundworker and Delegate (center Text)

Hi, an alternative that would probably be better would be to calculate the position just once in the SetLabelText Sub, so using your original code remove all instances of lblInfo.Left = (Me.Width / 3) - (lblInfo.Width / 4) and just use it once in your sub routine

What I posted was not intended to be used literally. Object refers to whatever object you are centering. It could be a label, a textbox, a picture, another form or anything else that has these properties. You would use the actual name of your object in place of the word Object.