Jump to content
  • Advertisement
Sign in to follow this  
myvraccount

Controls in Scrolling Windows

This topic is 1079 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Something VERY weird is happening.  If I make a window and turn own its built-in scroll bars, then scroll around and place controls in run-time, I noticed that the x and y coordinates of the controls are relative to the window coordinates, but as it appears on the screen.

 

In other words, if I start at horizontal (or vertical) position 0, then place a control 100 pixels from the left (or top), its x (or y) coordinate is 100.  But then if I scroll 300 pixels to the right (or down) and place another control 100 pixels from the left (or top), it will also have an x (or y) coordinate of 100, even though it's actually 300 pixels right (or below) of the other one, and the coordinate should be 400!

 

This makes it impossible to judge in absolute terms, within the entire scrolling range, where exactly any control exists!  What gives???

 

And no, I can't post source code, and don't even have it with me right now.

Share this post


Link to post
Share on other sites
Advertisement
I use raw win32, no C#/MFC/winforms etc so maybe I misinterpret your problem but I think you are wrong about how a scroll bar works. Let's say you scroll 100 pixels down. The pixel closest to the title bar is now still 0, not 99, for drawing something new. A scroll bar just sends a message that your app has to interpret and act upon (move everything "up" by dY for example)
You can maintain an absolute position yourself and update it during that scroll message's processing.

Share this post


Link to post
Share on other sites

Well I have turned on a property called "AutoScroll" or something like that, so it automatically moves the controls around when I move the scroll bars.  However, I don't think it's actually changing the coordinate properties of the controls when it does so.  So when I put it left = 100, then move the scroll bar, the property on the control stays at left = 100.

 

For that reason, I assumed that the coordinate stored in the control (the left property) would correspond to the position within the scrolled window, not the visual position relative to the window on the screen.  It doesn't make any sense how I can have 2 different controls that both have left = 100, and they appear horizontally far apart, just because they were inserted onto the form when the scroll bar was in different positions.

Share this post


Link to post
Share on other sites

Which particular UI framework are you using?  WinForms, WPF, something else?  And have you looked at the relevant documentation for the position properties?  It might explicitly tell you if the property returns the position relative to the parent's virtual area (pre-scroll), relative to the parent's visible area (post-scroll), relative to the screen, et cetera.  And if it doesn't provide you the value you want, there's like another set of properties that do give you what you're looking for, or at least some methods that will convert from one frame of reference to another.  (Client to screen and screen to client are common.  And note that the client area typically refers to the visible area of the control, so any position that is relative to the client area of the parent will produce the effect that you see; it is a position relative to the root visible corner of the parent.)

 

After a bit of research, if you're using System.Windows.Forms (WinForms), this MSDN page might help:  ScrollableControl.AutoScrollPosition

Edited by Andy Gainey

Share this post


Link to post
Share on other sites

Yes System.Windows.Forms is what I'm using.  I'm sorry I didn't say that - I thought it was assumed.

 

But I think I was already using AutoScrollPosition.  Anyway, all I want to do is be able to programmatically place any control at run time, and also be able to draw things (like lines, etc.), and give all of that a left and top (or x and y) position, and have it show up where I want either on the screen or in the "virtual" scrollable space.

 

But I want it to be consistent, so that if I place 2 different things so that their horizontal positions are both at 100, they don't look half a screen apart horizontally!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!