New topic: Graphics and Canvas basic question
<http://forums.realsoftware.com/viewtopic.php?t=27611> Page 1 of 1 [ 14 posts ] Previous topic | Next topic Author Message rbasic20091005153 Post subject: Graphics and Canvas basic questionPosted: Fri Apr 17, 2009 9:14 pm Joined: Sat Apr 04, 2009 5:10 pm Posts: 34 Hello. I have a Window where there's a PushButton and a Canvas. That's where I want to display a bar chart. To make the story simple, if I write Code:Canvas1.Graphics.ForeColor=RGB(200, 200, 150) Canvas1.Graphics.FillRect 20,399,50,40 inside PushButton1's Action under the same window (Window1), a rectangle will appear when one clicks on the PushButton. I actually want to draw this rectangle under a different window, say, Window2. If I simply write Code:Window2.Canvas1.Graphics.ForeColor=RGB(200, 200, 150) Window2.Canvas1.Graphics.FillRect 20,399,50,40 inside PushButton1's Action under Window1, nothing will appear on Window2's Canvas. I wonder why? What am I doing wrong? Thanks a lot. Tom Top imikedaman Post subject: Re: Graphics and Canvas basic questionPosted: Fri Apr 17, 2009 9:16 pm Joined: Fri Sep 30, 2005 6:55 pm Posts: 1402 Put your graphics drawing code in the Paint event of each Canvas. If you only want the drawing to appear when the user pushes a button, set Canvas.visible to true when they push the button. _________________ Those who can, do. Those who can't, make excuses. Top timhare Post subject: Re: Graphics and Canvas basic questionPosted: Fri Apr 17, 2009 9:21 pm Joined: Fri Jan 06, 2006 3:21 pm Posts: 5106 Location: Portland, OR USA What platform? Mac works differently than Windows as far as buffering graphics to the window. It's possible that Window2 doesn't know that you've changed it and it needs to refresh the screen. You could try Window2.RefreshNow after drawing. Be aware that anything you draw this way is temporary and will be erased if the window needs to be redrawn because it was obscured by another window or minimized and restored. Tim Top rbasic20091005153 Post subject: Re: Graphics and Canvas basic questionPosted: Fri Apr 17, 2009 9:31 pm Joined: Sat Apr 04, 2009 5:10 pm Posts: 34 >set Canvas.visible to true Ohh... I'll look into that. Thanks. Timhare, the platform is Mac. And I'll see if 'Window2.RefreshNow' makes a diffence. Thanks a lot for your prompt replies, guys. Top rbasic20091005153 Post subject: Re: Graphics and Canvas basic questionPosted: Fri Apr 17, 2009 9:38 pm Joined: Sat Apr 04, 2009 5:10 pm Posts: 34 I put Code:Canvas1.Visible = True under Window2.Canvas1's Open, and the rectangle won't appear. It's no luck for Window2.Refresh Last edited by rbasic20091005153 on Fri Apr 17, 2009 9:47 pm, edited 1 time in total. Top timhare Post subject: Re: Graphics and Canvas basic questionPosted: Fri Apr 17, 2009 9:46 pm Joined: Fri Jan 06, 2006 3:21 pm Posts: 5106 Location: Portland, OR USA Oops, that was Window2.UpdateNow. Tim Note that this will only work if Window2 is visible and unobscured when you draw. If you can't see the area you're trying to draw to, you'll never see the rectangle as it will be erased when you reveal the window. Last edited by timhare on Fri Apr 17, 2009 9:50 pm, edited 1 time in total. Top rbasic20091005153 Post subject: Re: Graphics and Canvas basic questionPosted: Fri Apr 17, 2009 9:49 pm Joined: Sat Apr 04, 2009 5:10 pm Posts: 34 Thanks, Tim. But Code:Window2.UpdateNow doesn't change the situation. And writing Code:Window2.Canvas1.Visible = True under Window1 > PushButton > Action doesn't save me. I wonder why I cannot complete such a simple task? Last edited by rbasic20091005153 on Fri Apr 17, 2009 9:54 pm, edited 1 time in total. Top timhare Post subject: Re: Graphics and Canvas basic questionPosted: Fri Apr 17, 2009 9:51 pm Joined: Fri Jan 06, 2006 3:21 pm Posts: 5106 Location: Portland, OR USA I was editing as you were posting. Is Window2 fully visible when your code executes? Top rbasic20091005153 Post subject: Re: Graphics and Canvas basic questionPosted: Fri Apr 17, 2009 9:55 pm Joined: Sat Apr 04, 2009 5:10 pm Posts: 34 Thanks, Tim. The answer is yes. Top imikedaman Post subject: Re: Graphics and Canvas basic questionPosted: Fri Apr 17, 2009 10:03 pm Joined: Fri Sep 30, 2005 6:55 pm Posts: 1402 rbasic20091005153 wrote:I put Code:Canvas1.Visible = True under Window2.Canvas1's Open, and the rectangle won't appear. It's no luck for Window2.Refresh You only followed half by advice. Put your drawing code in the Paint event of each Canvas. _________________ Those who can, do. Those who can't, make excuses. Top rbasic20091005153 Post subject: Re: Graphics and Canvas basic questionPosted: Fri Apr 17, 2009 10:10 pm Joined: Sat Apr 04, 2009 5:10 pm Posts: 34 Umm... imikedaman may be right. If I put the exactly same code under Window2 > Paint, the rectangular will appear. Top timhare Post subject: Re: Graphics and Canvas basic questionPosted: Sat Apr 18, 2009 1:08 am Joined: Fri Jan 06, 2006 3:21 pm Posts: 5106 Location: Portland, OR USA Imikedaman is exactly right. Your code works perfectly on Windows. Can't say anything about Mac, though. But I wouldn't do it that way, anyway. I always draw in the Paint event, because anything else is transient. Tim Top lordderringe Post subject: Re: Graphics and Canvas basic questionPosted: Sat Apr 18, 2009 3:36 am Joined: Wed Nov 08, 2006 11:04 am Posts: 54 This would work as well: Canvas1.Graphics.ForeColor=RGB(200, 200, 150) Canvas1.Graphics.FillRect 20,20,50,40 Window2.Show Window2.Canvas1.Graphics.ForeColor=RGB(200, 200, 150) Window2.Canvas1.Graphics.FillRect 20,20,50,40 However, I also suggest writing a separate method for Window2 which is doing the graphics for you. Top rbasic20091005153 Post subject: Re: Graphics and Canvas basic questionPosted: Sat Apr 18, 2009 3:58 am Joined: Sat Apr 04, 2009 5:10 pm Posts: 34 Window2.Show... Ohh... Okay. You guys are very helpful. Thanks a lot. Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 14 posts ] -- Over 900 classes with 18000 functions in one REALbasic plug-in. The Monkeybread Software Realbasic Plugin v8.1. <http://www.monkeybreadsoftware.de/realbasic/plugins.shtml> [email protected]
