prob setting location of button on form and resetting loc to orig

R

Rich

I placed a button on a form menustrip for the purpose of causing the
horizontal scrollbar of my form to appear so that I can access controls
outside of the form's current view (the controls are further to the right of
the form than the form's default width - which may take up the entire screen
for some users). The form contains panels which will contain either
textboxes or datagridviews. The button is located on the menustrip towards
the right side of the form - at the edge of the form's default view. If I
then move this button further to the right on the menustrip - it causes the
form's horizontal scrollbar to appear. This way a user can drag the
scrollbar to view the other controls which are located further to the right
of the form. Call this button the 'anchor' button.

In the default form view - the datagridviews (I guess actually the panels
containing the datagridviews) will display their vertical scrollbars (when
there are enough records to require the vertical scrollbars). So I
positioned the anchor button to be in view of the default form's view so that
the datagridviews can have their scrollbars. When I move the anchor button
to the right (through a menu click) the vertical scrollbars of the
datagridviews go out of site - until the user scrolls to the right (some of
the users have their resolution set to 640x480 - bad eyesight). Thus, I
need to be able to reposition this anchor button to its original location to
that the datagridview vertical scrollbars remain in view. The problem is
that when I try to reposition the anchor button to its original location - it
doesn't always go back. If I reposition the button in the beginning -
without scrolling the form horizontally - and the re-reposition the button -
it will go back to its original location. But if I scroll the form and then
try to reposition the button - it won't go back to its original position -
kinda like the new/current position becomes the original position. Here is
the code I am using to perform the positioning/repositioning.

Private Sub mnuExtendScrollBar_Click(...) Handles mnuExtendScrollBar.Click
Console.WriteLine("Before: " & btnAnchor.Location.X.ToString)
If mnuExtendScrollBar.Text.Equals("Extend Bottom Scrollbar") Then
Me.btnAnchor.Location = New System.Drawing.Point(1050, 3)
mnuExtendScrollBar.Text = "De-extend Bottom Scrollbar"
Else
'--this is the original/default location of my anchor button
Me.btnAnchor.Location = New System.Drawing.Point(858, 3)
mnuExtendScrollBar.Text = "Extend Bottom Scrollbar"
End If
Console.WriteLine("After: " & btnAnchor.Location.X.ToString)
End Sub

How can I make the location values not change? make it so the button will
only move to these two locations?

Thanks,
Rich
 
R

Rich

I change my code slightly - changed Else to ElseIF:

Private Sub mnuExtendScrollBar_Click(...) Handles mnuExtendScrollBar.Click
Console.WriteLine("Before: " & btnAnchor.Location.X.ToString)
If mnuExtendScrollBar.Text.Equals("Extend Bottom Scrollbar") Then
Me.btnAnchor.Location = New System.Drawing.Point(1050, 3)
mnuExtendScrollBar.Text = "De-extend Bottom Scrollbar"
ElseIf mnuExtendScrollBar.Text.Equals("De-extend Bottom Scrollbar") Then
'--this is the original/default location of my anchor button
Me.btnAnchor.Location = New System.Drawing.Point(858, 3)
mnuExtendScrollBar.Text = "Extend Bottom Scrollbar"
End If
Console.WriteLine("After: " & btnAnchor.Location.X.ToString)
End Sub

I observed that if I scroll the form back to its original position and then
try to reposition the button - it will go back to its original position (may
take a few clicks though). I would like that button to go back as soon as I
click the menuItem without having to scroll the form back to its original
position.
 

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

Top