473,793 Members | 2,927 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,heig ht).

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 2074
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 ScrollableContr ol, 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 "UserContro l" 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
4324
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 be better to promote better programming than rely on PHP to compensate for lazy programming?
4
6430
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 well as some color coding, etc. Having trouble finding the same in an editor that'll run on OS X. -- Floydian Slip(tm) - "Broadcasting from the dark side of the moon"
1
4101
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 for adding so much code... <TABLE border="1" bordercolor="#000000" cellspacing="0"> <TR>
11
4012
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
18542
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 blocks until something.exe terminates. Just what I /don't/ want. (Wouldn't an & be nice here! Sigh) I need something.exe to disconnect and run in the background while I
1
3705
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 sockets??
10
4226
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
4420
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 image, which will upload the record to a mySql db so users can then either view all profiles or query.. I.e. show all males in UK, all femails over 35 etc. Now, I'm not asking for How to do this but more what would be the best way? I've looked at...
1
3640
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 NOT IN ( SELECT manufacturers_id FROM products )
3
3492
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 the variable $GET but $GET is not a variable, I thought it came from the page that calls the PHP file? if(($_GET)==""){ this gets an error
0
9670
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9518
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10430
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9033
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3719
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.