Make Sheet window transparent

  1. 4 years ago

    Mike C

    4 Jan 2015 (England, Midlands)

    How do you make the back of a sheet window transparent so you can draw the window yourself in the paint event of the window?

    Put this in your sheet windows open event to make the background completely transparent. Controls will still be visible.

    Sub Open()
      const Cocoa = "Cocoa"
      declare sub setOpaque lib Cocoa selector "setOpaque:" (id As integer, b As boolean)
      declare function NSClassFromString lib Cocoa (aClassName as CFStringRef) as Ptr
      declare function clearColor lib Cocoa selector "clearColor" (NSColorClass As Ptr) As Ptr
      declare sub setBackgroundColor lib Cocoa selector "setBackgroundColor:" (w As integer, c As Ptr)
      
      //allow for transparency by setting opaqueness false
      setOpaque(self.Handle, false)
      
      //set the background completely transparent
      setBackgroundColor(self.Handle, clearColor(NSClassFromString("NSColor")))
      
    End Sub

    And draw your custom background in Paint

    Sub Paint(g As Graphics, areas() As REALbasic.Rect)
      g.ForeColor = &c00FF0080
      g.FillRect(0, 0, g.Width, g.Height)
    End Sub
  2. Tim J

    4 Jan 2015 Pre-Release Testers, Xojo Pro Dehydrating in AZ

    Do you have an example of what you're trying to achieve?

  3. Michel B

    4 Jan 2015 Pre-Release Testers RubberViews.com

    @MikeCharlesworth How do you make the back of a sheet window transparent so you can draw the window yourself in the paint event of the window?

    On Mac, why not use a canvas instead ?

  4. Mike C

    4 Jan 2015 (England, Midlands)

    @Tim J Do you have an example of what you're trying to achieve?

    A custom shape window

  5. Tim J

    4 Jan 2015 Pre-Release Testers, Xojo Pro Dehydrating in AZ
    Edited 4 years ago

    If you have an MBS plugin license, @ChristianSchmitz has a great overlay capability that works for all three platforms.

    Check out this link on the MBS site: MBS Overlay Window Tutorial

    Its an older video, but it still works in Xojo.

  6. Michel B

    4 Jan 2015 Pre-Release Testers RubberViews.com
    Edited 4 years ago

    @MikeCharlesworth A custom shape window

    MacOSLib uses a custom shape splash window.

    But since a sheet window, at least on Mac, always displays within another window, a canvas can do just what you described in your OP...

  7. Will S

    4 Jan 2015 Answer Santa Cruz 

    Put this in your sheet windows open event to make the background completely transparent. Controls will still be visible.

    Sub Open()
      const Cocoa = "Cocoa"
      declare sub setOpaque lib Cocoa selector "setOpaque:" (id As integer, b As boolean)
      declare function NSClassFromString lib Cocoa (aClassName as CFStringRef) as Ptr
      declare function clearColor lib Cocoa selector "clearColor" (NSColorClass As Ptr) As Ptr
      declare sub setBackgroundColor lib Cocoa selector "setBackgroundColor:" (w As integer, c As Ptr)
      
      //allow for transparency by setting opaqueness false
      setOpaque(self.Handle, false)
      
      //set the background completely transparent
      setBackgroundColor(self.Handle, clearColor(NSClassFromString("NSColor")))
      
    End Sub

    And draw your custom background in Paint

    Sub Paint(g As Graphics, areas() As REALbasic.Rect)
      g.ForeColor = &c00FF0080
      g.FillRect(0, 0, g.Width, g.Height)
    End Sub
  8. Sam R

    4 Jan 2015 Pre-Release Testers, Xojo Pro Hengchun, Pingtung, Taiwan

    @MikeCharlesworth How do you make the back of a sheet window transparent so you can draw the window yourself in the paint event of the window?

    Erm... The sheet window is already translucent...

    Are you trying to create some kind of overlay dialog on your window content, like a progress window or something similar?

  9. Mike C

    5 Jan 2015 (England, Midlands)

    @Sam R Erm... The sheet window is already translucent...

    Are you trying to create some kind of overlay dialog on your window content, like a progress window or something similar?

    I am making a custom shaped window which I am drawing on a canvas on the window. Therefore I want the canvas and contained controls to show while the sheet window is invisible.

  10. Mike C

    5 Jan 2015 (England, Midlands)

    @Will S Put this in your sheet windows open event to make the background completely transparent. Controls will still be visible.

    Sub Open()
      const Cocoa = "Cocoa"
      declare sub setOpaque lib Cocoa selector "setOpaque:" (id As integer, b As boolean)
      declare function NSClassFromString lib Cocoa (aClassName as CFStringRef) as Ptr
      declare function clearColor lib Cocoa selector "clearColor" (NSColorClass As Ptr) As Ptr
      declare sub setBackgroundColor lib Cocoa selector "setBackgroundColor:" (w As integer, c As Ptr)
      
      //allow for transparency by setting opaqueness false
      setOpaque(self.Handle, false)
      
      //set the background completely transparent
      setBackgroundColor(self.Handle, clearColor(NSClassFromString("NSColor")))
      
    End Sub

    And draw your custom background in Paint

    Sub Paint(g As Graphics, areas() As REALbasic.Rect) g.ForeColor = &c00FF0080 g.FillRect(0, 0, g.Width, g.Height) End Sub

    Thanks Will, thats the one...

or Sign Up to reply!