Question Trackbar value changes shadowoffset of label

ud2008

Well-known member
Joined
Jul 5, 2010
Messages
148
Programming Experience
Beginner
I have a component (GLabel), which can set shadow.

I also have 2 trackbars which should change the offset of the labels shadow.

I use this code, but it doesn't work, I think I miss something:
VB.NET:
Private Sub RadTrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles RadTrackBar1.Scroll
        RadTrackBar1.Value = GLabel1.ShadowOffset = (New Point(GLabel1.ShadowOffset.X, _
                                         GLabel1.ShadowOffset.Y - 1))
    End Sub

Any idea?
 
That code:
VB.NET:
        RadTrackBar1.Value = GLabel1.ShadowOffset = (New Point(GLabel1.ShadowOffset.X, _
                                         GLabel1.ShadowOffset.Y - 1))
is creating a Point that is always different to GLabel1.ShadowOffset, comparing it to GLabel1.ShadowOffset to create a Boolean that is always False, then assigning that Boolean to the Value of the RadTrackBar, which would require implicitly converting it to an Integer. That obviously doesn't make sense. Try starting with a CLEAR statement of EXACTLY what you want to do. Most beginners try to write code when they don;t even really know what it's supposed to do, so the chances of it actually doing what it's supposed to are very slim. If you need to actually write the description down using pen and paper then do so. Once you have a clear description of what the code needs to do, then you can write code to do exactly that; no more, no less.
 
Thanks for your reply.

I'm still a beginner in vb.net, but let me try to explain what I want to do.

When sliding the track (horizontal trackbar) it should change the glabel.shadowoffset.X, the other trackbar (vertical) should change the shadowoffset.Y

I tried change the code as followed:

VB.NET:
GLabel1.ShadowOffset = (New Point(GLabel1.ShadowOffset.X, GLabel1.ShadowOffset.Y)) = RadTrackBar1.Value

But then I get the following error:

Error 1 Overload resolution failed because no accessible '=' can be called with these arguments:
'Public Shared Operator =(left As System.Drawing.Point, right As System.Drawing.Point) As Boolean': Value of type 'Integer' cannot be converted to 'System.Drawing.Point'.

Don't know exactly what it means, but my guess is that the value of the radtrackbar cannot be used (at its current state) with the shadowoffset.X

Hope someone can give me a direction to go to.

Thanks
 
Again, why do you have two '=' operators in your code? In VB, '=' is either an assignment or a comparison. You can only have one assignment in a single statement so that means that you have at least one equality comparison in that code. Do you want to compare anything for equality? I don't think so.

Start at the beginning. You need a Point to assign to the ShadowOffset. That Point will be comprised of an X value and a Y value. The X value is going to come from the track bar and the Y value will come from the existing offset. Now, build it up in stages instead of trying to do it all at once.
VB.NET:
Dim newX As Integer = RadTrackBar1.Value
Dim newY As Integer = GLabel1.ShadowOffset.Y
Dim newOffset As New Point(newX, newY)

GLabel1.ShadowOffset = newOffset
Don't try to do something in one line of code if it's confusing you. Break it down and do each part on a separate line. You can then combine those multiple lines into one if you want, once you know it works, e.g.
VB.NET:
Dim newY As Integer = GLabel1.ShadowOffset.Y
Dim newOffset As New Point(RadTrackBar1.Value, newY)

GLabel1.ShadowOffset = newOffset
VB.NET:
Dim newOffset As New Point(RadTrackBar1.Value, GLabel1.ShadowOffset.Y)

GLabel1.ShadowOffset = newOffset
VB.NET:
GLabel1.ShadowOffset = New Point(RadTrackBar1.Value, GLabel1.ShadowOffset.Y)
 
Back
Top