473,385 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Re-draw Control

Hi,

I have a question about drawing windowed control.

For example, i have a windowed control, let's called it C1 (as container
for example).
its width = 300 px and height = 200 px.

C1 displays some other windowed controls, however, not all are displayed
initially when C1 is painted. for example C2 can be located on point
500,300 (x,y).

therefore, C2 is not displayed initially,

I have 4 buttons which allow me to scroll from right to left or bottom
to top the "canvas" (display surface) of C1.

However, i would like to understand how i can shift this canvas based on
button click ?

I mean if i click on "Right Button" 10 times, the drawing region of C1
should be re-draw to reflect this shift. So, C1 should be repaint to
display the region : 10,0,300,200 (x,y,width,height).

I suppose that i have to use the paint event with clip, cliprectangle
and bound. Moreover, i should compare repaint window surface (clipped
region) to something...but to what ?

I would be very glad if i can get some tutorial or example on similar
topics. It will help me in my understanding.

thx,

Al.
Feb 11 '07 #1
1 2042
On Sun, 11 Feb 2007 08:11:17 -0800, --== Alain ==-- <no****@noemail.com
wrote:
[...]
I suppose that i have to use the paint event with clip, cliprectangle
and bound. Moreover, i should compare repaint window surface (clipped
region) to something...but to what ?

I would be very glad if i can get some tutorial or example on similar
topics. It will help me in my understanding.
You really only need two things:

* to keep track of the offset related to scrolling
* UI to change that offset

You already have the buttons, though typically an application would use
the built-in scroll bars. If you look up ScrollableControl, scroll bars,
etc. in the MSDN documentation you'll find a variety of examples and
references discussing the topic.

Generally speaking, in your example you do not need to worry about
clipping. Drawing should be clipped to the control already when the
control receives its paint message. So all you have to do is make sure
you offset your drawing by the correct amount when repainting the control,
and make sure that the control is repainted (invalidated) when any
scrolling occurs.

So in your example where you have a 300x200 control (call that the
parent), and a contained control at (500,300) (call that the child), you
won't see that child control unless you've scrolled the parent container
by at least 200 pixels horizontally and 100 pixels vertically.

There are a couple of different ways to handle the scrolling values, but
one of the most straightforward is to simply subract the scrolled amount
from all drawing coordinates before drawing. If you're dealing with
actual child controls, then you need to move all of the child controls by
the scrolled amount. Again, using your example, if your parent gets
scrolled by (200,100), then you subtract that from the child's nominal
position of (500,300) to get a new position of (300,200), placing it just
at the lower right corner of the parent. Obviously scrolling more will
move the child more and reveal more of it than just the one pixel.

Basically, you always make sure that the position of the child controls
reflects the current status of the scrolling UI, any parts that you paint
yourself explicitly you offset by the current status of the scrolling UI,
and any time that the scrolling state has changed, you just force a
redraw, which will cause all of the necessary repainting to occur (with
needed clipping).

As it happens, .NET has a container control that is appropriate if all
you're doing is containing other .NET controls. It will handle all the
scrolling and whatnot for you. I don't recall the exact name off the top
of my head, but I think it's something like "UserControl" or something.
If you're using Visual Studio, just look in the control toolbox (category
"Containers" I think) and you should be able to find it. It will handle
the UI for scrolling the container and everything for you.

Hope that helps...

Pete
Feb 11 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nel | last post by:
I have a question related to the "security" issues posed by Globals ON. It is good programming technique IMO to initialise variables, even if it's just $foo = 0; $bar = ""; Surely it would...
4
by: Craig Bailey | last post by:
Anyone recommend a good script editor for Mac OS X? Just finished a 4-day PHP class in front of a Windows machine, and liked the editor we used. Don't recall the name, but it gave line numbers as...
1
by: Chris | last post by:
Sorry to post so much code all at once but I'm banging my head against the wall trying to get this to work! Does anyone have any idea where I'm going wrong? Thanks in advance and sorry again...
11
by: James | last post by:
My form and results are on one page. If I use : if ($Company) { $query = "Select Company, Contact From tblworking Where ID = $Company Order By Company ASC"; }
4
by: Alan Walkington | last post by:
Folks: How can I get an /exec'ed/ process to run in the background on an XP box? I have a monitor-like process which I am starting as 'exec("something.exe");' and, of course the exec function...
1
by: John Ryan | last post by:
What PHP code would I use to check if submitted sites to my directory actually exist?? I want to use something that can return the server code to me, ie HTTP 300 OK, or whatever. Can I do this with...
10
by: James | last post by:
What is the best method for creating a Web Page that uses both PHP and HTML ? <HTML> BLA BLA BLA BLA BLA
8
by: Beowulf | last post by:
Hi Guru's, I have a query regarding using PHP to maintain a user profiles list. I want to be able to have a form where users can fill in their profile info (Name, hobbies etc) and attach an...
1
by: joost | last post by:
Hello, I'm kind of new to mySQL but more used to Sybase/PHP What is illegal about this query or can i not use combined query's in mySQL? DELETE FROM manufacturers WHERE manufacturers_id ...
3
by: presspley | last post by:
I have bought the book on advanced dreamweaver and PHP recently. I have installed MySQL and PHP server but am getting an error on the $GET statement show below. It says there is a problem with...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.