Problem showing spin control contents in other control

  • Thread starter Thread starter Drily Lit Raga
  • Start date Start date
D

Drily Lit Raga

VC++ calls this a spin control, I think VB calls it an updown? Anyway
it is the control with two arrows on the right for entering numeric
values.

I have another text control that uses the spin control contents to form
a file name, i.e.

spin #1 is page # and spin #2 is total number of pages, and the text
control spells it out as

page_01_of_02

I have the code to update the text controls within the handler for the
spin controls, but it is always one behind.

I.e. here is the routine which displays the composite text string,
control name is "outputname".

Private Sub RefreshName()
OutputName.Text = "p" + PageUpDown.Text + "_of_" +
NPagesUpDown.Text
OutputName.Update()
End Sub

And all the updown control handler does is to call this.

Private Sub PageUpDown_ValueChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles PageUpDown.ValueChanged
RefreshName()
End Sub

but the result is always one off, for example if they start out as

PageUpDown.Text = 1 and NPagesUpDown = 2, I call refreshname(), I get

p1_of_2

when I click up on PageUpDown, PageUpDown.Text now = 2 but the output
is still

p1_of_2

if I then click down on PageUpDown, PageUpDown.Text now = 1 but the
output is now

p2_of_2

What am I doing wrong?
 
Looks like the text isn't updated until after the ValueChanged event has
fired. Use the Value property instead

Private Sub RefreshName()
Dim sb As New System.Text.StringBuilder
sb.Append("p")
sb.Append(PageUpDown.Value.ToString())
sb.Append("_of_")
sb.Append(NPagesUpDown.Value.ToString())
OutputName.Text = sb.ToString()
OutputName.Update()
End Sub

/claes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top